#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"
Macros | |
#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. More... | |
bool | b_datalog_set_current_log_drive_toSDMMC (void) |
Set the current logs to be stored to the SDMMC card. More... | |
bool | bdatalog_start (unsigned portBASE_TYPE uxPriority) |
static | portTASK_FUNCTION (vDataLogTask, pvParameters) |
The datalog gathering task. More... | |
static | portTASK_FUNCTION (vLogToFileTask, pvParameters) |
The log-to-file task. More... | |
void | prv_vdatalog_pool_log_free (void *pxLog) |
Mark a data log structure from the pool of logs as free. More... | |
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. More... | |
static int | prv_xopen_current_logfile (void) |
Open the current log file. More... | |
xLogDef * | pxdatalog_log_alloc_init (bool bAllocType) |
Allocate and init a xLogDef structure. More... | |
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. More... | |
void | vdatalog_log_free (xLogDef *pxLog) |
Free a data log structure and its content. More... | |
void | vdatalog_make_logstring (xLogDef *pxLog, signed portCHAR *pcLogString) |
Build a log string from a xLogDef log structure. More... | |
portBASE_TYPE | x_datalog_AddLogFromISR (xLogDef *pxLog) |
Add a log in the xLogsQueue, from within an ISR. More... | |
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.
Referenced by bdatalog_start(), prv_vdatalog_pool_log_free(), and pxdatalog_log_alloc_init().
#define DATALOG_LOGFILE_MAXSIZE 20480 |
The max log file size.
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.
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.
Referenced by prv_vsave_logs().
#define DATALOG_LOGSQUEUE_SIZE 30 |
Detailed description of the module: TODO
The maximum number of data logs that the xLogsQueue can contain.
Referenced by bdatalog_start(), and x_datalog_AddLogFromISR().
#define DATALOG_STACK_SIZE configMINIMAL_STACK_SIZE |
Data log task stack size.
Referenced by bdatalog_start().
#define LOGTOFILE_STACK_SIZE configMINIMAL_STACK_SIZE |
LogToFile task stack size.
Referenced by bdatalog_start().
Set the current logs to be stored to the DataFlash.
References acLogFileName, pcStringCurrentLogDirectoryName, pcStringLogDirectoryNameA, and pdTRUE.
Set the current logs to be stored to the SDMMC card.
References acLogFileName, pcStringCurrentLogDirectoryName, pcStringLogDirectoryNameB, and pdTRUE.
bool bdatalog_start | ( | unsigned portBASE_TYPE | uxPriority | ) |
Start the data logger module.
uxPriority | The base priority of the data logger tasks. |
References DATALOG_INVALID_LOGSRC_ID, DATALOG_LOGSQUEUE_HITHRESHOLD, DATALOG_LOGSQUEUE_SIZE, DATALOG_STACK_SIZE, LOGTOFILE_STACK_SIZE, NULL, pcStringCurrentLogDirectoryName, pcStringLogDirectoryNameA, pdPASS, SYS_STATUS_DOWN, vTaskDelete(), xDataLogHndl, xDataLogStatus, xLogToFileHndl, xQueueCreate(), and xTaskCreate.
Referenced by portTASK_FUNCTION().
|
static |
The datalog gathering task.
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(), void, vTaskDelayUntil(), xDataLogStatus, and xTaskGetTickCount().
|
static |
The log-to-file task.
References acLogFileName, acPreviousLogFileName, NULL, prv_vsave_logs(), prv_xopen_current_logfile(), SYS_STATUS_RUNNING, void, vTaskSuspend(), x_supervisor_SemaphoreGive(), x_supervisor_SemaphoreTake(), and xDataLogStatus.
Mark a data log structure from the pool of logs as free.
pxLog | pointer on the data log structure to free. |
References DATALOG_INVALID_LOGSRC_ID.
Referenced by pxdatalog_log_alloc_init().
|
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. |
References acLogString, close, DATALOG_LOGSQUEUE_LOTHRESHOLD, FS_DATE_LAST_WRITE, nav_file_dateset(), pcTempoDate, pdTRUE, uxNbMsgsInLogsQueue, uxQueueMessagesWaiting(), v_cptime_GetDateInFatStringFormat(), vdatalog_log_free(), vdatalog_make_logstring(), vTaskDelayUntil(), write, xQueueReceive, and xTaskGetTickCount().
Referenced by portTASK_FUNCTION().
|
static |
Open the current log file.
References acLogFileName, acPreviousLogFileName, close, DATALOG_LOGFILE_MAXSIZE, FS_DATE_LAST_WRITE, fsaccess_file_get_size(), fsaccess_IsDirPresent(), NAKED_TRACE_COM2, nav_file_dateset(), O_APPEND, O_CREAT, O_WRONLY, open(), pcStringCurrentLogDirectoryName, pcTempoDate, sprintf(), v_cptime_GetDateInFatStringFormat(), v_SMTP_Post, and xcptime_LocalTime.
Referenced by portTASK_FUNCTION().
Allocate and init a xLogDef structure.
bAllocType | Allocation type (dynamic or static(FromISR)) |
References DATALOG_ALLOC_DYNAMIC, DATALOG_INVALID_LOGSRC_ID, DATALOG_LOGSQUEUE_HITHRESHOLD, NULL, LogDef::pcStringLog, LogDef::pfFreeLogStruct, LogDef::pfFreeStringLog, prv_vdatalog_pool_log_free(), pvPortMalloc(), LogDef::rawdate, u8FreeLogIdx, void, vPortFree(), and xcptime_LocalTime.
Referenced by e_actuator_cmd_get_value(), e_sensor_cmd_get_value(), and v_datalog_AddSensorLog().
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.
SensorId | The sensor id of the sensor to get the value from. |
References b_sensor_get_value(), DATALOG_ALLOC_DYNAMIC, DATALOG_LOGSQUEUE_HITHRESHOLD, errQUEUE_FULL, LogDef::id, NULL, pxdatalog_log_alloc_init(), uxNbMsgsInLogsQueue, uxQueueMessagesWaiting(), vdatalog_log_free(), vTaskResume(), vTaskSuspend(), xLogToFileHndl, and xQueueSend.
Referenced by portTASK_FUNCTION().
Free a data log structure and its content.
pxLog | pointer on the data log structure to free. |
References NULL, 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().
Build a log string from a xLogDef log structure.
pxLog | Pointer on a data log structure |
pcLogString | Allocated DATALOG_LOG_MAXSIZE string to fill. |
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().
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. |
References DATALOG_LOGSQUEUE_SIZE, NULL, pdFALSE, uxNbMsgsInLogsQueue, vdatalog_log_free(), and xQueueSendFromISR.
Referenced by prvjoystick_ISR_NonNakedBehaviour(), and prvpushb_ISR_NonNakedBehaviour().
Return the status of the datalog module.
References xDataLogStatus.
|
static |
The name of the current logfile, always "LOG/mmddyy_hhmm.log".
Thus, allocating 20Bytes for this string is enough.
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] |
Array of nicknames
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().
|
static |
Pre-allocated memory space to build a log.
Referenced by prv_vsave_logs().
|
static |
Referenced by portTASK_FUNCTION(), and prv_xopen_current_logfile().
|
static |
Pool of xLogDef structures(FIFO) used for log allocation from ISR.
const signed portCHAR* pcStringCurrentLogDirectoryName |
The <drive letter>:/LOG directory where the logs file are currently stored.
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.
Referenced by b_datalog_set_current_log_drive_toDF(), and bdatalog_start().
const signed portCHAR* const pcStringLogDirectoryNameB = (signed portCHAR *)"B:/LOG" |
Referenced by b_datalog_set_current_log_drive_toSDMMC().
|
static |
Temporary array to set the current date of a log file.
Referenced by config_file_set_value(), e_fscmds_shell_mkdir(), e_fscmds_touch(), prv_append(), prv_vsave_logs(), and prv_xopen_current_logfile().
|
static |
Pointer on the next free log in the circular pool of xLogDef structures.
Referenced by pxdatalog_log_alloc_init().
|
static |
The number of logs in xLogsQueue.
Referenced by prv_vsave_logs(), v_datalog_AddSensorLog(), and x_datalog_AddLogFromISR().
time_t xcptime_LocalTime |
The local time raw value.
|
static |
Data logger task handle.
Referenced by bdatalog_start().
|
static |
The data logger module status.
Referenced by bdatalog_start(), portTASK_FUNCTION(), and xDataLog_GetStatus().
xSemaphoreHandle xLOGMutex |
The datalog system mutex.
The LOG system mutex.
|
static |
The handle of the queue of data logs.
|
static |
LogToFile task handle.
Referenced by bdatalog_start(), and v_datalog_AddSensorLog().