//***************************************************************************** // // Writes a message to the log. The message is preceeded by a time stamp, and // the message can not exceed 28 characters in length (unless g_pcBuffer is // increased in size). // //***************************************************************************** void LogWrite(char *pcPtr) { tTime sTime; // // Convert the current time from seconds since Jan 1, 1970 to the month, // day, year, hour, minute, and second equivalent. // ulocaltime(g_ulTime, &sTime); // // Construct the log message with the time stamp preceeding it. // UARTprintf("%s %s %2d %02d:%02d:%02d.%02d UT %d => %s\r\n", g_ppcDays[sTime.ucWday], g_ppcMonths[sTime.ucMon], sTime.ucMday, sTime.ucHour, sTime.ucMin, sTime.ucSec, g_ulTimeCount / 10, sTime.usYear, pcPtr); }
//***************************************************************************** // // Callback function from the menu widget. This function is called whenever // the menu is used to activate a child widget that is associated with the // menu. It is also called when the widget is deactivated and control is // returned to the menu widget. It can be used to trigger different actions // depending on which menus are chosen, and to track the state of the // application and control focus for the user interface. // // This function is called in the context of widget tree message processing // so care should be taken if doing any operation that affects the display // or widget tree. // //***************************************************************************** static void WidgetActivated(tWidget *psWidget, tSlideMenuItem *psMenuItem, bool bActivated) { char *pcMenuText; uint32_t ui32RTC; // // Handle the activation or deactivation of the strip chart. The strip // chart widget is activated when the user selects the START menu. // if(psWidget == &g_sStripChart.sBase) { // // If the strip chart is activated, start the logger running. // if(bActivated) { // // Get the current state of the menus // MenuGetState(&g_sConfigState); // // Save the state in battery backed memory // SetSavedState(&g_sConfigState); // // Start logger and update the logger state // AcquireStart(&g_sConfigState); g_iLoggerState = eSTATE_LOGGING; } else { // // If the strip chart is deactivated, stop the logger. // AcquireStop(); g_iLoggerState = eSTATE_IDLE; } } else if((psWidget == &g_sAINContainerCanvas.sBase) || (psWidget == &g_sAccelContainerCanvas.sBase) || (psWidget == &g_sCurrentContainerCanvas.sBase) || (psWidget == &g_sClockContainerCanvas.sBase) || (psWidget == &g_sTempContainerCanvas.sBase)) { // // Handle the activation or deactivation of any of the container // canvas that is used for showing the acquired data as a numerical // display. This happens when the VIEW menu is used. // // A viewer has been activated. // if(bActivated) { static tConfigState sLocalState; // // Get the current menu configuration state and save it in a local // storage. // MenuGetState(&sLocalState); // // Modify the state to set values that are suitable for using // with the viewer. The acquisition rate is set to 1/2 second // and all channels are selected. The storage medium is set to // "viewer" so the acquistion module will write the value of // acquired data to the appropriate viewing canvas. // sLocalState.ui8Storage = CONFIG_STORAGE_VIEWER; sLocalState.ui32Period = 0x00000040; sLocalState.ui16SelectedMask = 0x3ff; // // Start the acquisition module running. // AcquireStart(&sLocalState); g_iLoggerState = eSTATE_VIEWING; } else { // // The viewer has been deactivated so turn off the acquisition // module. // AcquireStop(); g_iLoggerState = eSTATE_IDLE; } } else if(psWidget == &g_sStatusContainerCanvas.sBase) { // // Handle the case when a status display has been activated. This can // occur when any of several menu items are selected. // // Get pointer to the text of the current menu item. // if(psMenuItem) { pcMenuText = psMenuItem->pcText; } else { return; } // // If activated from the SAVE menu, then the flash data needs to be // saved to USB stick. Enter the saving state. // if(!strcmp(pcMenuText, "SAVE")) { if(bActivated) { g_iLoggerState = eSTATE_SAVING; } else { g_iLoggerState = eSTATE_IDLE; } } else if(!strcmp(pcMenuText, "ERASE DATA?")) { // // If activated from the ERASE menu, then the flash data needs to // be erased. Enter the erasing state. // if(bActivated) { g_iLoggerState = eSTATE_ERASING; } else { g_iLoggerState = eSTATE_IDLE; } } else if(!strcmp(pcMenuText, "FLASH SPACE")) { // // If activated from the FLASH SPACE menu, then the user will be // shown a report on the amount of free space in flash. Enter the // reporting state. // if(bActivated) { g_iLoggerState = eSTATE_FREEFLASH; } else { g_iLoggerState = eSTATE_IDLE; } } } else if(psWidget == &g_sClockSetter.sBase) { // // Handle the activation of the clock setting widget. Deactivation is // handled through a separate callback. // // If the clock setter is activated, load the time structure fields. // if(bActivated) { // // Get the current time in seconds from the RTC. // ui32RTC = HibernateRTCGet(); // // Convert the RTC time to a time structure. // ulocaltime(ui32RTC, &g_sTimeClock); // // Set the callback that will be called when the clock setting // widget is deactivated. Since the clock setting widget needs // to take over the focus for button events, it uses a separate // callback when it is finsihed. // ClockSetCallbackSet((tClockSetWidget *)psWidget, ClockSetOkCallback); // // Give the clock setter widget focus for the button events // g_ui32KeyFocusWidgetHandle = (uint32_t)psWidget; g_iLoggerState = eSTATE_CLOCKSET; } } }
//***************************************************************************** // // Read the next chunck of data from the file. Return the count of data // that was read. Return 0 if no data is currently available. Return // a -1 if at the end of file. // //***************************************************************************** int fs_read(struct fs_file *file, char *buffer, int count) { int iAvailable; // // Check to see if an audio update was requested (pextension = 1). // if(file->pextension) { const struct fsdata_file *ptTree; // // Check to see if this is a file we know something about. // ptTree = file->pextension; if(strncmp((char *)ptTree->name, "/ptpclock", 9) == 0) { char *ptr, cTemp; extern volatile unsigned long g_ulSystemTimeSeconds; tTime sLocalTime; // // Check to see if the buffer size is large enough for the entire // file. If not, return EOF. // if(ptTree->len > count) { return(-1); } // // Copy the file into the buffer. // memcpy(buffer, ptTree->data, ptTree->len); // // Find the "div" marker for the PTP time. // ptr = ustrstr((const char *)buffer, "Www Mmm Dd, Yyyy Hh:Mm:Ss"); if(ptr == NULL) { return(-1); } // // Save the character after the date string. // cTemp = *(ptr + 26); // // Get the local time from the current second counter. // ulocaltime(g_ulSystemTimeSeconds, &sLocalTime); // // Print the the local time into the page buffer. // usprintf(ptr, "%3s %3s %2d, %4d %02d:%02d:%02d", g_ppcDay[sLocalTime.ucWday], g_ppcMonth[sLocalTime.ucMon], sLocalTime.ucMday, sLocalTime.usYear, sLocalTime.ucHour, sLocalTime.ucMin, sLocalTime.ucSec); *(ptr + 26) = cTemp; // // Clear the extension data and return the count. // file->pextension = NULL; return(ptTree->len); } // // Here, return EOF ... we don't now how to process this file. // else { return(-1); } } // // Check to see if more data is available. // if(file->len == file->index) { // // There is no remaining data. Return a -1 for EOF indication. // return(-1); } // // Determine how much data we can copy. The minimum of the 'count' // parameter or the available data in the file system buffer. // iAvailable = file->len - file->index; if(iAvailable > count) { iAvailable = count; } // // Copy the data. // memcpy(buffer, file->data + file->index, iAvailable); file->index += iAvailable; // // Return the count of data that we copied. // return(iAvailable); }
//***************************************************************************** // // Writes a message to the log. The message is preceeded by a time stamp, and // the message can not exceed 28 characters in length (unless g_pcBuffer is // increased in size). // //***************************************************************************** void LogWrite(char *pcPtr) { tTime sTime; // // Convert the current time from seconds since Jan 1, 1970 to the month, // day, year, hour, minute, and second equivalent. // ulocaltime(g_ulTime, &sTime); // // Construct the log message with the time stamp preceeding it. // usprintf(g_pcBuffer, "%s %s %2d %02d:%02d:%02d.%02d UT %d => %s\r\n", g_ppcDays[sTime.ucWday], g_ppcMonths[sTime.ucMon], sTime.ucMday, sTime.ucHour, sTime.ucMin, sTime.ucSec, g_ulTimeCount / 10, sTime.usYear, pcPtr); // // Get a pointer to the start of the log message. // pcPtr = g_pcBuffer; // // Disable the UART interrupt to prevent the UART interrupt handler from // executing, which would cause corruption of the logging state (possibly // losing characters in the process). // UARTIntDisable(UART1_BASE, UART_INT_TX); // // See if the software FIFO is empty. // if(g_ulReadPtr == g_ulWritePtr) { // // The software FIFO is empty, so copy as many characters from the log // message into the hardware FIFO as will fit. // while(*pcPtr && (UARTCharPutNonBlocking(UART1_BASE, *pcPtr) == true)) { pcPtr++; } } // // Copy as many characters from the log message into the software FIFO as // will fit. // while(*pcPtr && (((g_ulWritePtr + 1) & (SOFT_FIFO_SIZE - 1)) != g_ulReadPtr)) { g_pcTransmitBuffer[g_ulWritePtr] = *pcPtr++; g_ulWritePtr = (g_ulWritePtr + 1) & (SOFT_FIFO_SIZE - 1); } // // Re-enable the UART interrupt. // UARTIntEnable(UART1_BASE, UART_INT_TX); }
//***************************************************************************** // // This function is called when in VIEW mode. The acquired data is written // as text strings which will appear on the eval board display. // //***************************************************************************** static void UpdateViewerData(const tLogRecord *psRecord) { static char pcViewerBuf[24]; uint32_t ui32Idx, pui32RTC; struct tm sTime; // // Loop through the analog channels and update the text display strings. // for(ui32Idx = LOG_ITEM_USER0; ui32Idx <= LOG_ITEM_USER3; ui32Idx++) { usnprintf(pcViewerBuf, sizeof(pcViewerBuf), " CH%u: %u.%03u V ", ui32Idx - LOG_ITEM_USER0, psRecord->pi16Items[ui32Idx] / 1000, psRecord->pi16Items[ui32Idx] % 1000); MenuUpdateText(ui32Idx, pcViewerBuf); } // // Loop through the accel channels and update the text display strings. // for(ui32Idx = LOG_ITEM_ACCELX; ui32Idx <= LOG_ITEM_ACCELZ; ui32Idx++) { int16_t i16Accel = psRecord->pi16Items[ui32Idx]; i16Accel *= (i16Accel < 0) ? -1 : 1; usnprintf(pcViewerBuf, sizeof(pcViewerBuf), " %c: %c%d.%02u g ", (ui32Idx - LOG_ITEM_ACCELX) + 'X', psRecord->pi16Items[ui32Idx] < 0 ? '-' : '+', i16Accel / 100, i16Accel % 100); MenuUpdateText(ui32Idx, pcViewerBuf); } // // Update the display string for internal temperature. // usnprintf(pcViewerBuf, sizeof(pcViewerBuf), " INT: %d.%01u C ", psRecord->pi16Items[LOG_ITEM_INTTEMP] / 10, psRecord->pi16Items[LOG_ITEM_INTTEMP] % 10); MenuUpdateText(LOG_ITEM_INTTEMP, pcViewerBuf); // // Update the display string for external temperature. // usnprintf(pcViewerBuf, sizeof(pcViewerBuf), " EXT: %d.%01u C ", psRecord->pi16Items[LOG_ITEM_EXTTEMP] / 10, psRecord->pi16Items[LOG_ITEM_EXTTEMP] % 10); MenuUpdateText(LOG_ITEM_EXTTEMP, pcViewerBuf); // // Update the display string for processor current. // usnprintf(pcViewerBuf, sizeof(pcViewerBuf), " %u.%01u mA ", psRecord->pi16Items[LOG_ITEM_CURRENT] / 10, psRecord->pi16Items[LOG_ITEM_CURRENT] % 10); MenuUpdateText(LOG_ITEM_CURRENT, pcViewerBuf); // // Update the display strings for time and data. // pui32RTC = HibernateRTCGet(); ulocaltime(pui32RTC, &sTime); usnprintf(pcViewerBuf, sizeof(pcViewerBuf), "%4u/%02u/%02u", sTime.tm_year+1900, sTime.tm_mon + 1, sTime.tm_mday); MenuUpdateText(TEXT_ITEM_DATE, pcViewerBuf); usnprintf(pcViewerBuf, sizeof(pcViewerBuf), "%02u:%02u:%02u", sTime.tm_hour, sTime.tm_min, sTime.tm_sec); MenuUpdateText(TEXT_ITEM_TIME, pcViewerBuf); }