This module is in charge of :
* gathering the logs of data coming from the sensors and the actuators of the Control Panel, * filling the log files.
Definition in file datalog.c.
#include <string.h>
#include "gpio.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "datalog.h"
#include "tracedump.h"
#include "fsaccess.h"
#include "sensor.h"
#include "temperature.h"
#include "light.h"
#include "potentiometer.h"
#include "cptime.h"
#include "BasicSMTP.h"
Go to the source code of this file.
Defines | |
#define | DATALOG_INVALID_LOGSRC_ID (0xFFFFFFFF) |
#define | DATALOG_LOGFILE_MAXSIZE 20480 |
#define | DATALOG_LOGSQUEUE_HITHRESHOLD (DATALOG_LOGSQUEUE_SIZE*70/100) |
#define | DATALOG_LOGSQUEUE_LOTHRESHOLD (DATALOG_LOGSQUEUE_SIZE*30/100) |
#define | DATALOG_LOGSQUEUE_SIZE 30 |
#define | DATALOG_STACK_SIZE configMINIMAL_STACK_SIZE |
#define | LOGTOFILE_STACK_SIZE configMINIMAL_STACK_SIZE |
Functions | |
Bool | b_datalog_set_current_log_drive_toDF (void) |
Set the current logs to be stored to the DataFlash. | |
Bool | b_datalog_set_current_log_drive_toSDMMC (void) |
Set the current logs to be stored to the SDMMC card. | |
Bool | bdatalog_start (unsigned portBASE_TYPE uxPriority) |
static | portTASK_FUNCTION (vLogToFileTask, pvParameters) |
The log-to-file task. | |
static | portTASK_FUNCTION (vDataLogTask, pvParameters) |
The datalog gathering task. | |
void | prv_vdatalog_pool_log_free (void *pxLog) |
Mark a data log structure from the pool of logs as free. | |
static void | prv_vsave_logs (int fd_current_logfile) |
If the log file descriptor is valid, pop the oldest logs from the logs queue into the current log file until the low threshold of the logs queue is reached; then close the current log file. If the log file descriptor is invalid, simply pop the oldest logs from the logs queue until the low threshold of the logs queue is reached. | |
static int | prv_xopen_current_logfile (void) |
Open the current log file. | |
xLogDef * | pxdatalog_log_alloc_init (Bool bAllocType) |
Allocate and init a xLogDef structure. | |
int | sprintf (char *out, const char *format,...) |
void | v_datalog_AddSensorLog (eLogSourceId SensorId) |
Get the current value of a sensor and log it in the xLogsQueue. | |
void | vdatalog_log_free (xLogDef *pxLog) |
Free a data log structure and its content. | |
void | vdatalog_make_logstring (xLogDef *pxLog, signed portCHAR *pcLogString) |
Build a log string from a xLogDef log structure. | |
portBASE_TYPE | x_datalog_AddLogFromISR (xLogDef *pxLog) |
Add a log in the xLogsQueue, from within an ISR. | |
eStatus | xDataLog_GetStatus (void) |
Variables | |
static char | acLogFileName [25] |
char * | acLogSourceName [12] |
static char | acLogString [DATALOG_LOG_MAXSIZE] |
static char | acPreviousLogFileName [25] |
static xLogDef | axLogsPool [DATALOG_LOGSQUEUE_HITHRESHOLD] |
const signed portCHAR * | pcStringCurrentLogDirectoryName |
const signed portCHAR *const | pcStringLogDirectoryNameA = (signed portCHAR *)"A:/LOG" |
const signed portCHAR *const | pcStringLogDirectoryNameB = (signed portCHAR *)"B:/LOG" |
static char | pcTempoDate [17] |
static U8 | u8FreeLogIdx = 0 |
static unsigned portBASE_TYPE | uxNbMsgsInLogsQueue = 0 |
time_t | xcptime_LocalTime |
static xTaskHandle | xDataLogHndl = NULL |
static eStatus | xDataLogStatus = SYS_STATUS_STARTUP |
xSemaphoreHandle | xLOGMutex |
static xQueueHandle | xLogsQueue = 0 |
static xTaskHandle | xLogToFileHndl = NULL |
#define DATALOG_INVALID_LOGSRC_ID (0xFFFFFFFF) |
Invalid log id.
Definition at line 106 of file datalog.c.
Referenced by bdatalog_start(), prv_vdatalog_pool_log_free(), and pxdatalog_log_alloc_init().
#define DATALOG_LOGFILE_MAXSIZE 20480 |
The max log file size.
Definition at line 97 of file datalog.c.
Referenced by prv_xopen_current_logfile().
#define DATALOG_LOGSQUEUE_HITHRESHOLD (DATALOG_LOGSQUEUE_SIZE*70/100) |
The nb of items in the xLogsQueue hi-threshold upon which we should dump the logs to file = 70% of the max nb of items the queue can hold.
Definition at line 90 of file datalog.c.
Referenced by bdatalog_start(), pxdatalog_log_alloc_init(), and v_datalog_AddSensorLog().
#define DATALOG_LOGSQUEUE_LOTHRESHOLD (DATALOG_LOGSQUEUE_SIZE*30/100) |
The nb of items in the xLogsQueue lo-threshold upon which we should stop dumping the logs to file = 30% of the max nb of items the queue can hold.
Definition at line 94 of file datalog.c.
Referenced by prv_vsave_logs().
#define DATALOG_LOGSQUEUE_SIZE 30 |
Detailled description of the module: TODO
The maximum number of data logs that the xLogsQueue can contain.
Definition at line 83 of file datalog.c.
Referenced by bdatalog_start(), and x_datalog_AddLogFromISR().
#define DATALOG_STACK_SIZE configMINIMAL_STACK_SIZE |
#define LOGTOFILE_STACK_SIZE configMINIMAL_STACK_SIZE |
LogToFile task stack size.
Definition at line 103 of file datalog.c.
Referenced by bdatalog_start().
Bool b_datalog_set_current_log_drive_toDF | ( | void | ) |
Set the current logs to be stored to the DataFlash.
Definition at line 724 of file datalog.c.
References acLogFileName, pcStringCurrentLogDirectoryName, and pcStringLogDirectoryNameA.
00725 { 00726 // If the current logs were being stored on the SDMMC memory, force a new 00727 // file creation (by resetting the file name). 00728 if(*acLogFileName == 'B') 00729 { 00730 *acLogFileName = '\0'; 00731 } 00732 pcStringCurrentLogDirectoryName = pcStringLogDirectoryNameA; 00733 return(pdTRUE); 00734 }
Bool b_datalog_set_current_log_drive_toSDMMC | ( | void | ) |
Set the current logs to be stored to the SDMMC card.
Definition at line 742 of file datalog.c.
References acLogFileName, pcStringCurrentLogDirectoryName, and pcStringLogDirectoryNameB.
00743 { 00744 // If the current logs were being stored on the DF memory, force a new 00745 // file creation (by resetting the file name). 00746 if(*acLogFileName == 'A') 00747 { 00748 *acLogFileName = '\0'; 00749 } 00750 pcStringCurrentLogDirectoryName = pcStringLogDirectoryNameB; 00751 return(pdTRUE); 00752 }
Bool bdatalog_start | ( | unsigned portBASE_TYPE | uxPriority | ) |
Start the data logger module.
uxPriority | The base priority of the data logger tasks. |
Definition at line 191 of file datalog.c.
References DATALOG_INVALID_LOGSRC_ID, DATALOG_LOGSQUEUE_HITHRESHOLD, DATALOG_LOGSQUEUE_SIZE, DATALOG_STACK_SIZE, LOGTOFILE_STACK_SIZE, pcStringCurrentLogDirectoryName, pcStringLogDirectoryNameA, SYS_STATUS_DOWN, xDataLogHndl, xDataLogStatus, xLogsQueue, and xLogToFileHndl.
Referenced by portTASK_FUNCTION().
00192 { 00193 int i; 00194 00195 /* By default, set the current log directory to be in the DataFlash. */ 00196 pcStringCurrentLogDirectoryName = pcStringLogDirectoryNameA; 00197 00198 /* Init the xLogDef pool: set each log as free. */ 00199 for( i=0; i<DATALOG_LOGSQUEUE_HITHRESHOLD; i++) 00200 axLogsPool[i].id = DATALOG_INVALID_LOGSRC_ID; 00201 00202 /* Spawn the data log task. */ 00203 if( pdPASS != xTaskCreate( vDataLogTask, 00204 ( const signed portCHAR * )"DLOG", 00205 DATALOG_STACK_SIZE, NULL, uxPriority, 00206 &xDataLogHndl ) ) 00207 { 00208 xDataLogStatus = SYS_STATUS_DOWN; 00209 return FALSE; 00210 } 00211 00212 /* Spawn the LogToFile task. */ 00213 if( pdPASS != xTaskCreate( vLogToFileTask, 00214 ( const signed portCHAR * )"LOGF", 00215 LOGTOFILE_STACK_SIZE, NULL, uxPriority +1, 00216 &xLogToFileHndl ) ) 00217 { 00218 vTaskDelete( xDataLogHndl ); 00219 xDataLogStatus = SYS_STATUS_DOWN; 00220 return FALSE; 00221 } 00222 00223 // Create the xLogsQueue capable of containing DATALOG_LOGSQUEUE_SIZE ptrs 00224 // to xLogDef structures. 00225 xLogsQueue = xQueueCreate( DATALOG_LOGSQUEUE_SIZE, sizeof( xLogDef * ) ); 00226 if( 0 == xLogsQueue ) 00227 { // Queue was not created and must not be used. 00228 vTaskDelete( xDataLogHndl ); 00229 vTaskDelete( xLogToFileHndl ); 00230 return FALSE; 00231 } 00232 00233 return( TRUE ); 00234 }
static portTASK_FUNCTION | ( | vLogToFileTask | , | |
pvParameters | ||||
) | [static] |
The log-to-file task.
Definition at line 408 of file datalog.c.
References acLogFileName, acPreviousLogFileName, prv_vsave_logs(), prv_xopen_current_logfile(), SYS_STATUS_RUNNING, x_supervisor_SemaphoreGive(), x_supervisor_SemaphoreTake(), xDataLogStatus, and xLOGMutex.
00409 { 00410 int fd_current_logfile; 00411 00412 00413 /* Just to stop compiler warnings. */ 00414 ( void ) pvParameters; 00415 00416 xDataLogStatus = SYS_STATUS_RUNNING; 00417 00418 /* Init the current log file name. */ 00419 *acLogFileName = '\0'; 00420 *acPreviousLogFileName = '\0'; 00421 00422 for(;;) 00423 { 00424 /* 1) Suspend ourselves. */ 00425 vTaskSuspend( NULL ); // TO KEEP 00426 // NOTE: the task should be resumed when it is necessary to log the data 00427 // to the current log file, i.e.: 00428 // (*) if the xLogQueue is 75% full, 00429 // OR 00430 // (*) if the vDataLog_FlushLogs() has been called. 00431 00432 // Take the data logger system mutex. 00433 if( FALSE == x_supervisor_SemaphoreTake( xLOGMutex, 0 ) ) // 0 == Do not wait for the mutex. 00434 { 00435 // Pop the oldest logs from the logs queue so that the Control Panel 00436 // can still do logs acquisition. 00437 prv_vsave_logs( -1 ); 00438 continue; 00439 } 00440 00441 /* 2) Log the data into the current log file. */ 00442 // 2a) Open the current log file. 00443 fd_current_logfile = prv_xopen_current_logfile(); 00444 /* if( -1 == fd_current_logfile ) 00445 { // Should never happen (cf prv_xopen_current_logfile() final implem.) 00446 continue; 00447 } */ 00448 // Although the open should not fail, if it happens(!!!), prv_vsave_logs() 00449 // will correctly handle the (-1) value by just poping the oldest logs from 00450 // the logs queue. 00451 00452 // 2b) Move each item of the queue to the log file then close the file. 00453 prv_vsave_logs(fd_current_logfile); 00454 00455 // Release the data logger system mutex. 00456 x_supervisor_SemaphoreGive( xLOGMutex ); 00457 } 00458 }
static portTASK_FUNCTION | ( | vDataLogTask | , | |
pvParameters | ||||
) | [static] |
The datalog gathering task.
Definition at line 253 of file datalog.c.
References DATALOG_ID_LIGHT, DATALOG_ID_POT, DATALOG_ID_TEMP, SYS_STATUS_RUNNING, ul_light_lograte, ul_pot_lograte, ul_temp_lograte, v_datalog_AddSensorLog(), and xDataLogStatus.
00254 { 00255 portTickType xLastFocusTime; 00256 U8 u8TempWalkThrough = 0; 00257 U8 u8PotWalkThrough = 0; 00258 U8 u8LightWalkThrough = 0; 00259 00260 00261 /* Just to stop compiler warnings. */ 00262 ( void ) pvParameters; 00263 00264 xDataLogStatus = SYS_STATUS_RUNNING; 00265 00266 /* We need to initialise xLastFocusTime prior to the first call to vTaskDelayUntil(). */ 00267 xLastFocusTime = xTaskGetTickCount(); 00268 00269 for(;;) 00270 { 00271 // TODO: 00272 // 1. check all sensors sampling rate and order them in an array. 00273 // The array holds a delay for each sensor(so, it's an array of struct). 00274 // This step is out of the loop; it's an init. 00275 // 2. DelayUntil() of the shortest sampling rate(in array[0]). 00276 // 3. Perform the appropriate sensor get value. 00277 // 4. Update the delay left for all sensors (update the array according to 00278 // the previous delay and the sensors sampling rate (they may have changed 00279 // in the meantime)). 00280 // 5. Go to step 2. 00281 00282 /*############# TEMPORARY ##########################*/ 00283 vTaskDelayUntil( &xLastFocusTime, ( portTickType ) 1000 / portTICK_RATE_MS ); 00284 00285 // Log the temperature every ul_temp_lograte. 00286 u8TempWalkThrough++; 00287 if( ul_temp_lograte <= u8TempWalkThrough ) 00288 { 00289 u8TempWalkThrough = 0; 00290 /* Get and log in the xLogsQueue the current temperature sensor value. */ 00291 v_datalog_AddSensorLog( DATALOG_ID_TEMP ); 00292 } 00293 00294 // Log the potentiometer every ul_pot_lograte. 00295 u8PotWalkThrough++; 00296 if( ul_pot_lograte <= u8PotWalkThrough ) 00297 { 00298 u8PotWalkThrough = 0; 00299 /* Get and log in the xLogsQueue the current potentiometer sensor value. */ 00300 v_datalog_AddSensorLog( DATALOG_ID_POT ); 00301 } 00302 00303 // Log the potentiometer every ul_light_lograte. 00304 u8LightWalkThrough++; 00305 if( ul_light_lograte <= u8LightWalkThrough ) 00306 { 00307 u8LightWalkThrough = 0; 00308 /* Get and log in the xLogsQueue the current light sensor value. */ 00309 v_datalog_AddSensorLog( DATALOG_ID_LIGHT ); 00310 } 00311 /*##################################################*/ 00312 } 00313 }
void prv_vdatalog_pool_log_free | ( | void * | pxLog | ) |
Mark a data log structure from the pool of logs as free.
pxLog | pointer on the data log structure to free. |
Definition at line 533 of file datalog.c.
References DATALOG_INVALID_LOGSRC_ID.
Referenced by pxdatalog_log_alloc_init().
00534 { 00535 ((xLogDef *)pxLog)->id = DATALOG_INVALID_LOGSRC_ID; 00536 }
static void prv_vsave_logs | ( | int | fd_current_logfile | ) | [static] |
If the log file descriptor is valid, pop the oldest logs from the logs queue into the current log file until the low threshold of the logs queue is reached; then close the current log file. If the log file descriptor is invalid, simply pop the oldest logs from the logs queue until the low threshold of the logs queue is reached.
fd_current_logfile | The file descriptor of the current log file. |
Definition at line 666 of file datalog.c.
References acLogString, DATALOG_LOGSQUEUE_LOTHRESHOLD, pcTempoDate, uxNbMsgsInLogsQueue, v_cptime_GetDateInFatStringFormat(), vdatalog_log_free(), vdatalog_make_logstring(), and xLogsQueue.
Referenced by portTASK_FUNCTION().
00667 { 00668 xLogDef *pxLog; 00669 int iLogStringLen; 00670 portTickType xLastFocusTime; 00671 00672 00673 // We need to initialise xLastFocusTime prior to the first call to vTaskDelayUntil(). 00674 xLastFocusTime = xTaskGetTickCount(); 00675 00676 // NOTE: do not fully flush the xLogsQueue at once because it will take too 00677 // much time? 00678 // Issue vTaskDelayUntil({10,100}) upon each log pop? 00679 while( DATALOG_LOGSQUEUE_LOTHRESHOLD < ( uxNbMsgsInLogsQueue = uxQueueMessagesWaiting( xLogsQueue ) ) ) 00680 { 00681 // Get the oldest log from the queue. 00682 // NOTE: we are sure there is an item to get => no block time. 00683 if( pdTRUE == xQueueReceive( xLogsQueue, &pxLog, ( portTickType ) 0 ) ) 00684 { 00685 if( -1 == fd_current_logfile ) 00686 { // Special case: simply pop the logs. 00687 vdatalog_log_free( pxLog ); // Free the log. 00688 } 00689 else 00690 { 00691 /* 1) Build the log string to write in the file. */ 00692 vdatalog_make_logstring( pxLog, (signed portCHAR *)acLogString ); 00693 00694 /* 2) Free the log structure. */ 00695 vdatalog_log_free( pxLog ); // Free the log. 00696 00697 /* 3) Write the log to the file. */ 00698 iLogStringLen = strlen( acLogString ); 00699 if( iLogStringLen != write( fd_current_logfile, acLogString, iLogStringLen ) ) 00700 break; 00701 // NOTE: if the write failed, we'd rather stop the current write session 00702 // and start on solid ground later. 00703 } 00704 } 00705 // Give processor time to the other tasks. 00706 vTaskDelayUntil( &xLastFocusTime, ( portTickType )TASK_DELAY_MS(20) ); 00707 } 00708 if( -1 != fd_current_logfile ) 00709 { 00710 // Get the current time in the "YYYYMMDDHHMMSSMS" string format. 00711 v_cptime_GetDateInFatStringFormat( pcTempoDate ); 00712 // Set the file date. 00713 nav_file_dateset( (FS_STRING)pcTempoDate, FS_DATE_LAST_WRITE ); 00714 close( fd_current_logfile ); // Close the log file. 00715 } 00716 }
static int prv_xopen_current_logfile | ( | void | ) | [static] |
Open the current log file.
Definition at line 572 of file datalog.c.
References acLogFileName, acPreviousLogFileName, DATALOG_LOGFILE_MAXSIZE, NAKED_TRACE_COM2, pcStringCurrentLogDirectoryName, pcTempoDate, sprintf(), v_cptime_GetDateInFatStringFormat(), v_SMTP_Post(), and xcptime_LocalTime.
Referenced by portTASK_FUNCTION().
00573 { 00574 int fd_current_logfile; 00575 struct tm *pxDate; 00576 00577 00578 // TRACE_COM2( "open logfile begin==%d", xcptime_LocalTime ); 00579 00580 while( 1 ) 00581 { 00582 fd_current_logfile = -1; // Init to default value. 00583 00584 /* Open the log file. */ 00585 if( '\0' != *acLogFileName ) 00586 { // If we have an active current log file, simply open it in append mode. 00587 fd_current_logfile = open( acLogFileName, O_APPEND ); 00588 00589 // Check if the max file size has been reached. 00590 if( -1 != fd_current_logfile ) 00591 { 00592 if( DATALOG_LOGFILE_MAXSIZE <= fsaccess_file_get_size( fd_current_logfile ) ) 00593 { // The current log file has reached the max size. 00594 // Get the current time in the "YYYYMMDDHHMMSSMS" string format. 00595 v_cptime_GetDateInFatStringFormat( pcTempoDate ); 00596 // Set the file date. 00597 nav_file_dateset( (FS_STRING)pcTempoDate, FS_DATE_LAST_WRITE ); 00598 close( fd_current_logfile ); // Close the file. 00599 *acLogFileName = '\0'; // Reset the current log file name. 00600 continue; // Do another loop to create/open a new file. 00601 } 00602 } 00603 else 00604 { // The file has been removed. 00605 *acLogFileName = '\0'; // Reset the current log file name. 00606 continue; // Do another loop to create/open a new file. 00607 } 00608 } 00609 else 00610 { // Create a new log file. 00611 // Get the broken-down representation of the current date. 00612 pxDate = gmtime( &xcptime_LocalTime ); 00613 00614 // Build the filename: mmddyy_hhmm.log 00615 // WARNING: pxDate->tm_year == nunmber of years since 1900. 00616 // For years >= 2000, we'll display the last 2 digits only. 00617 if( pxDate->tm_year >= 100 ) 00618 pxDate->tm_year -= 100; 00619 00620 sprintf( acLogFileName, "%s/%.2d%.2d%.2d_%.2d%.2d.log", 00621 pcStringCurrentLogDirectoryName, pxDate->tm_mon +1, pxDate->tm_mday, 00622 pxDate->tm_year, pxDate->tm_hour, pxDate->tm_min ); 00623 00624 NAKED_TRACE_COM2( "Creating log file %s", acLogFileName ); 00625 00626 // Create the log file only if the /LOG directory exists. 00627 if( TRUE == fsaccess_IsDirPresent( (const char *)pcStringCurrentLogDirectoryName ) ) 00628 { // The LOG/ directory exists. 00629 // Create and open the file. 00630 // if the file already exists, then the file size is reset. 00631 fd_current_logfile = open( acLogFileName, (O_CREAT|O_WRONLY) ); 00632 // previous file is closed, send a mail 00633 if ( *acPreviousLogFileName != '\0' ) 00634 { 00635 // post alarm to SMTP task 00636 v_SMTP_Post(acPreviousLogFileName, acPreviousLogFileName); 00637 } 00638 strncpy(acPreviousLogFileName, acLogFileName, strlen(acLogFileName)); 00639 } 00640 } 00641 if( -1 == fd_current_logfile ) 00642 { // The open failed. We're not in maintenance mode. 00643 // Just remove the oldest log file: TODO 00644 NAKED_TRACE_COM2( "Failed opening the current log file %s", acLogFileName ); 00645 /*########### TEMPORARY #############*/ 00646 break; 00647 /*###################################*/ 00648 } 00649 else break; 00650 } 00651 00652 return( fd_current_logfile ); 00653 }
xLogDef* pxdatalog_log_alloc_init | ( | Bool | bAllocType | ) |
Allocate and init a xLogDef structure.
bAllocType | Allocation type (dynamic or static(FromISR)) |
Definition at line 468 of file datalog.c.
References DATALOG_ALLOC_DYNAMIC, DATALOG_INVALID_LOGSRC_ID, DATALOG_LOGSQUEUE_HITHRESHOLD, LogDef::pcStringLog, LogDef::pfFreeLogStruct, LogDef::pfFreeStringLog, prv_vdatalog_pool_log_free(), LogDef::rawdate, u8FreeLogIdx, and xcptime_LocalTime.
Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), and v_datalog_AddSensorLog().
00469 { 00470 xLogDef *pxLog; 00471 void (*pfFreeLogStruct)(void *); 00472 00473 00474 // Alloc a log structure. 00475 if( DATALOG_ALLOC_DYNAMIC == bAllocType ) 00476 { // Dynamic alloc. 00477 pxLog = ( xLogDef * )pvPortMalloc( sizeof( xLogDef ) ); 00478 pfFreeLogStruct = vPortFree; // Because pvPortMalloc() was used to alloc 00479 // the log structure. 00480 } 00481 else 00482 { // Static alloc. 00483 // TODO : add mutex if events are not on the same int level. 00484 if( DATALOG_INVALID_LOGSRC_ID != axLogsPool[u8FreeLogIdx].id ) 00485 { // Unavailable log. 00486 return( NULL ); 00487 } 00488 else 00489 { 00490 pxLog = &(axLogsPool[u8FreeLogIdx++]); 00491 u8FreeLogIdx = (u8FreeLogIdx == DATALOG_LOGSQUEUE_HITHRESHOLD) ? 0 : u8FreeLogIdx; 00492 pfFreeLogStruct = prv_vdatalog_pool_log_free; 00493 } 00494 } 00495 00496 // Init the fields that can possibly be filled now. 00497 if( NULL != pxLog ) 00498 { 00499 pxLog->rawdate = xcptime_LocalTime; 00500 pxLog->pfFreeLogStruct = pfFreeLogStruct; 00501 pxLog->pcStringLog = NULL; 00502 pxLog->pfFreeStringLog = NULL; 00503 } 00504 00505 return( pxLog ); 00506 }
int sprintf | ( | char * | out, | |
const char * | format, | |||
... | ||||
) |
Definition at line 293 of file printf-stdarg.c.
00294 { 00295 va_list args; 00296 00297 va_start( args, format ); 00298 return print( &out, format, args ); 00299 }
void v_datalog_AddSensorLog | ( | eLogSourceId | SensorId | ) |
Get the current value of a sensor and log it in the xLogsQueue.
SensorId | The sensor id of the sensor to get the value from. |
Definition at line 321 of file datalog.c.
References b_sensor_get_value(), DATALOG_ALLOC_DYNAMIC, DATALOG_LOGSQUEUE_HITHRESHOLD, LogDef::id, pxdatalog_log_alloc_init(), uxNbMsgsInLogsQueue, vdatalog_log_free(), xLogsQueue, and xLogToFileHndl.
Referenced by portTASK_FUNCTION().
00322 { 00323 xLogDef *pxLog; 00324 00325 00326 // Check if it is time to empty the xLogsQueue. 00327 uxNbMsgsInLogsQueue = uxQueueMessagesWaiting( xLogsQueue ); 00328 if( DATALOG_LOGSQUEUE_HITHRESHOLD <= uxNbMsgsInLogsQueue ) 00329 { 00330 // Resume the log-to-file task. 00331 vTaskSuspend( xLogToFileHndl ); 00332 vTaskResume( xLogToFileHndl ); 00333 // WARNING: What would happen if we try to resume a task that is not suspended? 00334 // Is the FreeRTOS Kernel implementation safe on this one? To be sure, we issue 00335 // a suspend before a resume. 00336 } 00337 00338 // Alloc a log structure. 00339 pxLog = pxdatalog_log_alloc_init( DATALOG_ALLOC_DYNAMIC ); 00340 00341 if( NULL != pxLog ) 00342 { 00343 // Init the id field of the log. 00344 pxLog->id = SensorId; 00345 00346 // Get the value from the sensor. 00347 if( FALSE == b_sensor_get_value( pxLog ) ) 00348 { // The get value operation failed. 00349 vdatalog_log_free( pxLog ); // Free the log. 00350 return; 00351 } 00352 00353 // Add the log to the xLogsQueue. 00354 if( errQUEUE_FULL == xQueueSend( xLogsQueue, (void *)&pxLog, 0 ) ) 00355 { // The xLogsQueue is full. This may happen if the logtofile task failed 00356 // or if it is too slow. 00357 vdatalog_log_free( pxLog ); 00358 // Resume the log-to-file task. 00359 vTaskSuspend( xLogToFileHndl ); 00360 vTaskResume( xLogToFileHndl ); 00361 // WARNING: What would happen if we try to resume a task that is not suspended? 00362 // Is the FreeRTOS Kernel implementation safe on this one? To be sure, we issue 00363 // a suspend before a resume. 00364 } 00365 } 00366 }
void vdatalog_log_free | ( | xLogDef * | pxLog | ) |
Free a data log structure and its content.
pxLog | pointer on the data log structure to free. |
Definition at line 515 of file datalog.c.
References LogDef::pcStringLog, LogDef::pfFreeLogStruct, and LogDef::pfFreeStringLog.
Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), prv_vsave_logs(), v_datalog_AddSensorLog(), and x_datalog_AddLogFromISR().
00516 { 00517 // Free the log string. 00518 if( NULL != pxLog->pfFreeStringLog) 00519 { 00520 pxLog->pfFreeStringLog( pxLog->pcStringLog ); 00521 } 00522 // Free the structure. 00523 pxLog->pfFreeLogStruct( pxLog ); 00524 }
void vdatalog_make_logstring | ( | xLogDef * | pxLog, | |
signed portCHAR * | pcLogString | |||
) |
Build a log string from a xLogDef log structure.
pxLog | Pointer on a data log structure | |
pcLogString | Allocated DATALOG_LOG_MAXSIZE string to fill. |
Definition at line 546 of file datalog.c.
References acLogSourceName, LogDef::id, LogDef::pcStringLog, LogDef::rawdate, and sprintf().
Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), and prv_vsave_logs().
00547 { 00548 struct tm *pxLogDate; 00549 00550 00551 // Get the broken-down representation of the log date. 00552 pxLogDate = gmtime( &(pxLog->rawdate) ); 00553 00554 // Build the log string. 00555 // WARNING: pxLogDate->tm_year == nunmber of years since 1900. 00556 // For years >= 2000, we'll display the last 2 digits only. 00557 if( pxLogDate->tm_year >= 100 ) 00558 pxLogDate->tm_year -= 100; 00559 sprintf( (char *)pcLogString, "%s | %.2d/%.2d/%.2d %.2d:%.2d:%.2d | %s\r\n", 00560 acLogSourceName[pxLog->id], pxLogDate->tm_mon +1, 00561 pxLogDate->tm_mday, pxLogDate->tm_year, pxLogDate->tm_hour, 00562 pxLogDate->tm_min, pxLogDate->tm_sec, pxLog->pcStringLog ); 00563 }
portBASE_TYPE x_datalog_AddLogFromISR | ( | xLogDef * | pxLog | ) |
Add a log in the xLogsQueue, from within an ISR.
pxLog | The log to add to the xLogsQueue. |
Definition at line 377 of file datalog.c.
References DATALOG_LOGSQUEUE_SIZE, uxNbMsgsInLogsQueue, vdatalog_log_free(), and xLogsQueue.
Referenced by prvjoystick_ISR_NonNakedBehaviour(), and prvpushb_ISR_NonNakedBehaviour().
00378 { 00379 portBASE_TYPE xYieldRequired = pdFALSE; 00380 00381 00382 if( ( NULL != pxLog ) && ( DATALOG_LOGSQUEUE_SIZE != uxNbMsgsInLogsQueue ) ) 00383 { 00384 // NOTE: xQueueSendFromISR() doesn't say if it could add the log or not. 00385 // For this reason, we will first test if the queue is full. Note that 00386 // we cannot call uxQueueMessagesWaiting() from an ISR, so we'll play it 00387 // safe by looking at the latest call to uxQueueMessagesWaiting(). 00388 // There is some hand-tuning here involved: the vLogToFileTask() must 00389 // work often enough so that the xLogsQueue never gets full. 00390 if( DATALOG_LOGSQUEUE_SIZE == uxNbMsgsInLogsQueue ) 00391 { // Safety 00392 vdatalog_log_free( pxLog ); 00393 } 00394 else 00395 { // Add the log to the xLogsQueue. 00396 portENTER_CRITICAL(); 00397 xQueueSendFromISR( xLogsQueue, (void *)&pxLog, &xYieldRequired ); 00398 portEXIT_CRITICAL(); 00399 } 00400 } 00401 return( xYieldRequired ); 00402 }
eStatus xDataLog_GetStatus | ( | void | ) |
Return the status of the datalog module.
Definition at line 242 of file datalog.c.
References xDataLogStatus.
00243 { 00244 return( xDataLogStatus ); 00245 }
char acLogFileName[25] [static] |
The name of the current logfile, always "LOG/mmddyy_hhmm.log".
Thus, allocating 20Bytes for this string is enough.
Definition at line 140 of file datalog.c.
Referenced by b_datalog_set_current_log_drive_toDF(), b_datalog_set_current_log_drive_toSDMMC(), portTASK_FUNCTION(), and prv_xopen_current_logfile().
char* acLogSourceName[12] |
Initial value:
{ "temp", "pot", "light", "pb1", "pb2", "pb3", "js", "ledb1", "ledb2", "ledm1", "ledm2", "lcd" }
Definition at line 144 of file datalog.c.
Referenced by e_actuator_cmd_get_value(), e_actuator_cmd_set_value(), e_sensor_cmd_get_config(), e_sensor_cmd_get_value(), e_sensor_cmd_set_config(), and vdatalog_make_logstring().
char acLogString[DATALOG_LOG_MAXSIZE] [static] |
Pre-allocated memory space to build a log.
Definition at line 148 of file datalog.c.
Referenced by prv_vsave_logs().
char acPreviousLogFileName[25] [static] |
Definition at line 141 of file datalog.c.
Referenced by portTASK_FUNCTION(), and prv_xopen_current_logfile().
xLogDef axLogsPool[DATALOG_LOGSQUEUE_HITHRESHOLD] [static] |
const signed portCHAR* pcStringCurrentLogDirectoryName |
The <drive letter>:/LOG directory where the logs file are currently stored.
Definition at line 120 of file datalog.c.
Referenced by b_datalog_set_current_log_drive_toDF(), b_datalog_set_current_log_drive_toSDMMC(), bdatalog_start(), and prv_xopen_current_logfile().
const signed portCHAR* const pcStringLogDirectoryNameA = (signed portCHAR *)"A:/LOG" |
"\<drive letter>:/LOG" strings.
Definition at line 116 of file datalog.c.
Referenced by b_datalog_set_current_log_drive_toDF(), and bdatalog_start().
const signed portCHAR* const pcStringLogDirectoryNameB = (signed portCHAR *)"B:/LOG" |
char pcTempoDate[17] [static] |
Temporary array to set the current date of a log file.
Definition at line 157 of file datalog.c.
Referenced by b_mmi_mkdir_aLOG(), b_mmi_mkdir_bLOG(), config_file_set_value(), e_fscmds_shell_mkdir(), e_fscmds_touch(), prv_append(), prv_vsave_logs(), and prv_xopen_current_logfile().
U8 u8FreeLogIdx = 0 [static] |
Pointer on the next free log in the circular pool of xLogDef structures.
Definition at line 154 of file datalog.c.
Referenced by pxdatalog_log_alloc_init().
unsigned portBASE_TYPE uxNbMsgsInLogsQueue = 0 [static] |
The number of logs in xLogsQueue.
Definition at line 135 of file datalog.c.
Referenced by prv_vsave_logs(), v_datalog_AddSensorLog(), and x_datalog_AddLogFromISR().
time_t xcptime_LocalTime |
xTaskHandle xDataLogHndl = NULL [static] |
eStatus xDataLogStatus = SYS_STATUS_STARTUP [static] |
The data logger module status.
Definition at line 129 of file datalog.c.
Referenced by bdatalog_start(), portTASK_FUNCTION(), and xDataLog_GetStatus().
xSemaphoreHandle xLOGMutex |
The datalog system mutex.
The LOG system mutex.
Definition at line 197 of file supervisor.c.
Referenced by e_supervisor_switch_to_maintenance_mode(), portTASK_FUNCTION(), and prv_v_common_leave_UsbDevice_mode().
xQueueHandle xLogsQueue = 0 [static] |
The handle of the queue of data logs.
Definition at line 132 of file datalog.c.
Referenced by bdatalog_start(), prv_vsave_logs(), v_datalog_AddSensorLog(), and x_datalog_AddLogFromISR().
xTaskHandle xLogToFileHndl = NULL [static] |
LogToFile task handle.
Definition at line 126 of file datalog.c.
Referenced by bdatalog_start(), and v_datalog_AddSensorLog().