wiki:Docs/Prog/Manual/ApplicationLibraries/lib825

Version 7 (modified by Don Wilson, 14 years ago) ( diff )

--

Standard 825 Library with Application class (lib825)

The standard library (lib825) is a collection of Cardinal utilities that simplifies the process of writing code for the WikiStart Cardinal 825. The library is distributed free of charge and available here to download.

This library contains all of the same functions as the newer lib825ev library http://tech.825spectrum.com/trac/wiki/Docs/Prog/Manual/ApplicationLibraries/lib825ev#Standard825LibrarywithEVENTfeatureslib825ev except it is the required library to use for applications based on the Application class. The Application class is an alternative to the event based programming model preferred for the lib825ev library.

For details about the Application class refer to the library source code and Doxygen comments included in the source code.

Utility Functions

Some simple routines may be used in the apps to convert between the hexadecimal strings and the various structures.

Error: Failed to load processor Lineno
No macro or processor named 'Lineno' found

These routines are packaged in [doxygen:hexutil_8cpp-source.html hexutil.cpp]

For example, an app may access time/date from the mainboard with the following:

char* mnbd_dev "/dev/mnbd";
int g_fileMnBd = 0;

int OpenMnBd(void)
{
  /* O_NONBLOCK allows open even with no carrier detect */
  g_fileMnBd = open(mnbd_dev, O_RDWR | O_NOCTTY | O_NONBLOCK);
  if(g_fileMnBd == -1)
  {
    printf("Error opening %s\n", mnbd_dev);
    return -1;
  }
  return 0;
}

void CloseMnBd(0)
{
  close(g_fileMnBd);
  return;
}

int z;
char readbuf![50];
char rcvbuf![50];
int rcvbufpos = 0;
int nread;

OpenMnBd();

write(g_fileMnBd, "S\r", 2); // Request date/time from mainboard

// In main loop of application:
for(;;)
{
  nread = read(g_fileMnBd, &readbuf, sizeof(readbuf) );

  if(nread > 0)
  {
    for(z = 0; z < nread; z++)
    {
      if(readbuf[z] == '\r')
    {

    rcvbuf[rcvbufpos] = '\0';

    // When time/date is received from mainboard set the Linux clock
    if(rcvbuf![0] == 'S')
    {
      struct mnbd_datetime_struct dt;
      convert_hex_to_binary(rcvbuf + 2, (unsigned char *)&dt);
      printf("Date/time from mainboard %d/%d/%d %d:%d:%d\r\n", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
  
      // Set regular C tm struct to appropriate time values
      struct tm time;
      time.tm_year = dt.year - 1900;
      time.tm_mon = dt.month - 1;
      time.tm_mday = dt.day;
      time.tm_hour = dt.hour;
      time.tm_min = dt.minute;
      time.tm_sec = dt.second;

      time_t tt = mktime(&time);

      stime(&tt);
    }

    rcvbufpos = 0;
  }
  else if(readbuf[z] >= 0x20 && readbuf[z] < 0x7F)
  {
    rcvbuf[rcvbufpos++] = readbuf[z];
  }
}

Top

Note: See TracWiki for help on using the wiki.