This module acts as an interface to all sensors.
Definition in file sensor.h.
#include "compiler.h"
#include "FreeRTOS.h"
#include "shell.h"
#include "datalog.h"
Go to the source code of this file.
Defines | |
#define | SENSOR_MSG_ALARM_OFF "alarm=off"CRLF |
#define | SENSOR_MSG_ALARM_ON "alarm=on"CRLF |
#define | SENSOR_MSG_CONFIG_SET SHELL_MSG_CONFIG_SET |
Functions | |
Bool | b_sensor_get_value (xLogDef *pxLog) |
Get a current sensor value. | |
Bool | bsensor_start (void) |
eExecStatus | e_sensor_cmd_get_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply) |
The get sensor config command: get the config fields value of a sensor. Takes one parameter, that is the sensor's name. Format: get_sensor_config sensorname. | |
eExecStatus | e_sensor_cmd_get_value (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply) |
The get sensor value command: get value(s) from a sensor. Takes two parameters, one of which is optional. The first parameter is the sensor's name, the optional parameter is the number of samples requested. Format: get_sensor_value sensorname [nbsamples], when nbsamples is given, the command should give an history of nbsamples-1 logs + the last value. | |
eExecStatus | e_sensor_cmd_set_config (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply) |
The set sensor config command: set the value of a config field of a sensor. Takes three parameters. The first parameter is the sensor's name, the second parameter is the config field name, the third parameter is the value. Format: set_sensor_config sensorname field=value. | |
eExecStatus | e_sensor_help (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply) |
The sensor help command: display the sensors available shell commands. Format: help. | |
void | v_sensor_stop (void) |
Stop the sensor module resources. |
#define SENSOR_MSG_ALARM_OFF "alarm=off"CRLF |
Definition at line 63 of file sensor.h.
Referenced by e_joystick_get_config(), e_joystick_set_config(), e_light_set_config(), e_potentiometer_set_config(), e_temperature_set_config(), prv_e_pushb_get_config(), and prv_e_pushb_set_config().
#define SENSOR_MSG_ALARM_ON "alarm=on"CRLF |
Definition at line 62 of file sensor.h.
Referenced by e_joystick_get_config(), e_joystick_set_config(), e_light_set_config(), e_potentiometer_set_config(), e_temperature_set_config(), prv_e_pushb_get_config(), and prv_e_pushb_set_config().
#define SENSOR_MSG_CONFIG_SET SHELL_MSG_CONFIG_SET |
Definition at line 64 of file sensor.h.
Referenced by e_light_set_config(), e_potentiometer_set_config(), and e_temperature_set_config().
Bool b_sensor_get_value | ( | xLogDef * | pxLog | ) |
Get a current sensor value.
pxLog | a Log structure. The sensor id is in the id field of pxLog. |
Definition at line 189 of file sensor.c.
References b_joystick_get_value(), b_light_get_value(), b_potentiometer_get_value(), b_pushb1_get_value(), b_pushb2_get_value(), b_pushb3_get_value(), b_temperature_get_value(), DATALOG_ID_JS, DATALOG_ID_LIGHT, DATALOG_ID_PB1, DATALOG_ID_PB2, DATALOG_ID_PB3, DATALOG_ID_POT, DATALOG_ID_TEMP, LogDef::id, and TRACE_COM2.
Referenced by v_datalog_AddSensorLog().
00190 { 00191 switch( pxLog->id ) 00192 { 00193 case DATALOG_ID_TEMP: 00194 return( b_temperature_get_value( pxLog ) ); 00195 case DATALOG_ID_POT: 00196 return( b_potentiometer_get_value( pxLog ) ); 00197 case DATALOG_ID_LIGHT: 00198 return( b_light_get_value( pxLog ) ); 00199 case DATALOG_ID_PB1: 00200 return( b_pushb1_get_value( pxLog ) ); 00201 case DATALOG_ID_PB2: 00202 return( b_pushb2_get_value( pxLog ) ); 00203 case DATALOG_ID_PB3: 00204 return( b_pushb3_get_value( pxLog ) ); 00205 case DATALOG_ID_JS: 00206 return( b_joystick_get_value( pxLog ) ); 00207 default: 00208 TRACE_COM2( "Unknown sensor id %d", pxLog->id ); 00209 return( FALSE ); 00210 } 00211 }
Bool bsensor_start | ( | void | ) |
Start the sensor module.
Definition at line 147 of file sensor.c.
References adc, NAKED_TRACE_COM2, and SENSOR_MAXNB_SENSORS.
Referenced by portTASK_FUNCTION().
00148 { 00149 volatile avr32_adc_t * adc= (volatile avr32_adc_t *) &AVR32_ADC; 00150 int i; 00151 00152 /* configure ADC */ 00153 adc_configure( adc ); 00154 00155 for( i = 0; i < SENSOR_MAXNB_SENSORS ; i++) 00156 { 00157 if ( axSensorsRegistry[i].pfConfigureSensor() != TRUE ) 00158 { 00159 NAKED_TRACE_COM2( "Init sensor %d failed", i ); 00160 return FALSE; 00161 } 00162 } 00163 return TRUE; 00164 }
eExecStatus e_sensor_cmd_get_config | ( | eModId | xModId, | |
signed short | FsNavId, | |||
int | ac, | |||
signed portCHAR * | av[], | |||
signed portCHAR ** | ppcStringReply | |||
) |
The get sensor config command: get the config fields value of a sensor. Takes one parameter, that is the sensor's name. Format: get_sensor_config sensorname.
xModId | Input. The module that is calling this function. | |
FsNavId | Ignored. | |
ac | Input. The argument counter. For this command, should be 1. | |
av | Input. The argument vector. | |
ppcStringReply | Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string. |
Definition at line 365 of file sensor.c.
References acLogSourceName, DATALOG_ID_JS, DATALOG_ID_TEMP, SENSOR_ERRMSG_GETCFG_SYNTAXERROR, SENSOR_ERRMSG_UNREFSENSOR, SENSOR_MAXNB_SENSORS, and SHELL_EXECSTATUS_KO.
00368 { 00369 int i; 00370 00371 00372 /* 0) If the way to reply is unavailable, it's no use to continue. */ 00373 if( ppcStringReply == NULL ) 00374 return( SHELL_EXECSTATUS_KO ); 00375 00376 /* 1) Check the input. */ 00377 // i) Two arguments exactly. 00378 if( 2 != ac ) 00379 { // Syntax error. 00380 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_GETCFG_SYNTAXERROR; 00381 return( SHELL_EXECSTATUS_KO ); 00382 } 00383 // No need to check that av[0] == sensor. We actually use the "sensor=name" 00384 // format just to comply with the cgi calls rules. 00385 00386 // ii) Identify the sensor. 00387 for( i=DATALOG_ID_TEMP; 00388 i<=DATALOG_ID_JS && strcmp( (char *)av[1], acLogSourceName[i] ); 00389 i++ ); 00390 00391 if( SENSOR_MAXNB_SENSORS == i ) 00392 { 00393 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_UNREFSENSOR; 00394 return( SHELL_EXECSTATUS_KO ); 00395 } 00396 00397 // Get the reply 00398 return( axSensorsRegistry[i].pfGetSensorConfig( ppcStringReply ) ); 00399 }
eExecStatus e_sensor_cmd_get_value | ( | eModId | xModId, | |
signed short | FsNavId, | |||
int | ac, | |||
signed portCHAR * | av[], | |||
signed portCHAR ** | ppcStringReply | |||
) |
The get sensor value command: get value(s) from a sensor. Takes two parameters, one of which is optional. The first parameter is the sensor's name, the optional parameter is the number of samples requested. Format: get_sensor_value sensorname [nbsamples], when nbsamples is given, the command should give an history of nbsamples-1 logs + the last value.
xModId | Input. The module that is calling this function. | |
FsNavId | Ignored. | |
ac | Input. The argument counter. For this command, should be 1 or 2. | |
av | Input. The argument vector. | |
ppcStringReply | Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string. |
xModId | Input. The module that is calling this function. | |
FsNavId | Ignored. | |
ac | Input. The argument counter. For this command, should be 2. | |
av | Input. The argument vector. | |
ppcStringReply | Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string. |
Definition at line 230 of file sensor.c.
References acLogSourceName, DATALOG_ALLOC_DYNAMIC, DATALOG_ID_JS, DATALOG_ID_TEMP, DATALOG_LOG_MAXSIZE, LogDef::id, LogDef::pcStringLog, LogDef::pfFreeStringLog, pxdatalog_log_alloc_init(), SENSOR_ERRMSG_GETVAL_FAIL, SENSOR_ERRMSG_GETVAL_SYNTAXERROR, SENSOR_ERRMSG_UNREFSENSOR, SENSOR_MAXNB_SENSORS, SHELL_ERRMSG_MEMALLOC, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, vdatalog_log_free(), and vdatalog_make_logstring().
00233 { 00234 int i; 00235 xLogDef *pxLog; 00236 int end=0; 00237 00238 00239 /* 0) If the way to reply is unavailable, it's no use to continue. */ 00240 if( ppcStringReply == NULL ) 00241 return( SHELL_EXECSTATUS_KO ); 00242 00243 /* 1) Check the input. */ 00244 // i) Two arguments exactly. 00245 if( 2 != ac ) 00246 { // Syntax error. 00247 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_GETVAL_SYNTAXERROR; 00248 return( SHELL_EXECSTATUS_KO ); 00249 } 00250 // No need to check that av[0] == sensor. We actually use the "sensor=name" 00251 // format just to comply with the cgi calls rules. 00252 00253 // ii) Identify the sensor. 00254 for( i=DATALOG_ID_TEMP; 00255 i<=DATALOG_ID_JS && strcmp( (char *)av[1], acLogSourceName[i] ); 00256 i++ ); 00257 00258 if( ( SENSOR_MAXNB_SENSORS == i ) && strcmp( (char *)av[1], "all" ) ) 00259 { 00260 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_UNREFSENSOR; 00261 return( SHELL_EXECSTATUS_KO ); 00262 } 00263 00264 // Alloc and init a log. 00265 pxLog = pxdatalog_log_alloc_init( DATALOG_ALLOC_DYNAMIC ); 00266 if( NULL == pxLog ) 00267 { 00268 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC; 00269 return( SHELL_EXECSTATUS_KO ); 00270 } 00271 00272 /* 3) Perform the command. */ 00273 if( SENSOR_MAXNB_SENSORS != i ) 00274 { // Case: one sensor. 00275 // Init the id field of the log. 00276 pxLog->id = i; 00277 00278 // Get the value. 00279 if( FALSE == axSensorsRegistry[i].pfGetSensorValue( pxLog ) ) 00280 { 00281 vdatalog_log_free( pxLog ); 00282 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_GETVAL_FAIL; 00283 return( SHELL_EXECSTATUS_KO ); 00284 } 00285 00286 /* 4) Build the reply. */ 00287 // Alloc space for the reply. 00288 *ppcStringReply = (signed portCHAR *)pvPortMalloc( DATALOG_LOG_MAXSIZE ); 00289 if( NULL == *ppcStringReply ) 00290 { 00291 vdatalog_log_free( pxLog ); 00292 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC; 00293 return( SHELL_EXECSTATUS_KO ); 00294 } 00295 00296 // Build the string. 00297 vdatalog_make_logstring( pxLog, *ppcStringReply ); 00298 00299 // Free the log. 00300 vdatalog_log_free( pxLog ); 00301 } 00302 else 00303 { // Case: all sensors 00304 // Alloc space for the reply. 00305 *ppcStringReply = (signed portCHAR *)pvPortMalloc( SENSOR_MAXNB_SENSORS*DATALOG_LOG_MAXSIZE ); 00306 if( NULL == *ppcStringReply ) 00307 { 00308 vdatalog_log_free( pxLog ); 00309 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC; 00310 return( SHELL_EXECSTATUS_KO ); 00311 } 00312 00313 for( i=DATALOG_ID_TEMP; i<=DATALOG_ID_JS; i++ ) 00314 { 00315 // Init the id field of the log. 00316 pxLog->id = i; 00317 00318 // Get the value. 00319 if( FALSE == axSensorsRegistry[i].pfGetSensorValue( pxLog ) ) 00320 { 00321 vdatalog_log_free( pxLog ); 00322 vPortFree( *ppcStringReply ); 00323 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_GETVAL_FAIL; 00324 return( SHELL_EXECSTATUS_KO ); 00325 } 00326 00327 /* 4) Build the reply. */ 00328 00329 // Build the string. 00330 vdatalog_make_logstring( pxLog, *ppcStringReply + end ); 00331 end = strlen( (char *)*ppcStringReply ); 00332 00333 // Free the log string. 00334 if( NULL != pxLog->pfFreeStringLog) 00335 { 00336 pxLog->pfFreeStringLog( pxLog->pcStringLog ); 00337 } 00338 } // for( i=DATALOG_ID_TEMP; i<=DATALOG_ID_JS; i++ ) 00339 // Free the log. 00340 pxLog->pfFreeStringLog = NULL; // Do that because we already freed the log string. 00341 vdatalog_log_free( pxLog ); 00342 } 00343 00344 return( SHELL_EXECSTATUS_OK ); 00345 }
eExecStatus e_sensor_cmd_set_config | ( | eModId | xModId, | |
signed short | FsNavId, | |||
int | ac, | |||
signed portCHAR * | av[], | |||
signed portCHAR ** | ppcStringReply | |||
) |
The set sensor config command: set the value of a config field of a sensor. Takes three parameters. The first parameter is the sensor's name, the second parameter is the config field name, the third parameter is the value. Format: set_sensor_config sensorname field=value.
xModId | Input. The module that is calling this function. | |
FsNavId | Ignored. | |
ac | Input. The argument counter. For this command, should be 3. | |
av | Input. The argument vector. | |
ppcStringReply | Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string. |
Definition at line 421 of file sensor.c.
References acLogSourceName, DATALOG_ID_JS, DATALOG_ID_TEMP, SensorReg::pfSetSensorConfig, SENSOR_ERRMSG_SETCFG_SYNTAXERROR, SENSOR_ERRMSG_UNREFSENSOR, SENSOR_MAXNB_SENSORS, SHELL_ERRMSG_MAINTENANCEMODE, SHELL_EXECSTATUS_KO, x_supervisor_SemaphoreGive(), x_supervisor_SemaphoreTake(), and xCFGMutex.
00424 { 00425 eExecStatus xRet = SHELL_EXECSTATUS_KO; 00426 int i; 00427 00428 // Take the CFG mutex. 00429 if( pdFALSE == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) ) 00430 { 00431 if( NULL != ppcStringReply ) 00432 { 00433 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MAINTENANCEMODE; 00434 } 00435 return( SHELL_EXECSTATUS_KO ); 00436 } 00437 else if(ppcStringReply != NULL) 00438 { 00439 /* 1) Check the input. */ 00440 // i) 4 arguments exactly. 00441 if( 4 != ac ) 00442 { // Syntax error. 00443 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_SETCFG_SYNTAXERROR; 00444 x_supervisor_SemaphoreGive( xCFGMutex ); // Release the CFG mutex. 00445 return( SHELL_EXECSTATUS_KO ); 00446 } 00447 // No need to check that av[0] == sensor. We actually use the "sensor=name" 00448 // format just to comply with the cgi calls rules. 00449 00450 // ii) Identify the sensor. 00451 for( i=DATALOG_ID_TEMP; 00452 i<=DATALOG_ID_JS && strcmp( (char *)av[1], acLogSourceName[i] ); 00453 i++ ); 00454 00455 if( SENSOR_MAXNB_SENSORS == i ) 00456 { 00457 *ppcStringReply = (signed portCHAR *)SENSOR_ERRMSG_UNREFSENSOR; 00458 x_supervisor_SemaphoreGive( xCFGMutex ); // Release the CFG mutex. 00459 return( SHELL_EXECSTATUS_KO ); 00460 } 00461 00462 // Get the reply 00463 xRet = axSensorsRegistry[i].pfSetSensorConfig( ppcStringReply, (ac - 2), &av[2] ); 00464 } 00465 00466 x_supervisor_SemaphoreGive( xCFGMutex ); // Release the CFG mutex. 00467 return( xRet ); 00468 }
eExecStatus e_sensor_help | ( | eModId | xModId, | |
signed short | FsNavId, | |||
int | ac, | |||
signed portCHAR * | av[], | |||
signed portCHAR ** | ppcStringReply | |||
) |
The sensor help command: display the sensors available shell commands. Format: help.
xModId | Input. The module that is calling this function. | |
FsNavId | Ignored. | |
ac | Ignored. | |
av | Ignored. | |
ppcStringReply | Input/Output. The response string. If Input is NULL, no response string will be output. Else a malloc for the response string is performed here; the caller must free this string. |
Definition at line 487 of file sensor.c.
References SENSOR_MSG_HELP, SHELL_EXECSTATUS_KO, and SHELL_EXECSTATUS_OK_NO_FREE.
Referenced by e_Shell_help().
00490 { 00491 // 1) If the way to reply is unavailable, it's no use to continue. 00492 if( ppcStringReply == NULL ) 00493 return( SHELL_EXECSTATUS_KO ); 00494 00495 // 2) Perform the command. 00496 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_HELP; 00497 00498 return( SHELL_EXECSTATUS_OK_NO_FREE ); 00499 }
void v_sensor_stop | ( | void | ) |
Stop the sensor module resources.
Definition at line 169 of file sensor.c.
References SensorReg::pfStopSensor, and SENSOR_MAXNB_SENSORS.
Referenced by e_syscmds_reboot().
00170 { 00171 int i; 00172 for( i = 0; i < SENSOR_MAXNB_SENSORS ; i++) 00173 { 00174 if( NULL != axSensorsRegistry[i].pfStopSensor ) 00175 { 00176 axSensorsRegistry[i].pfStopSensor(); 00177 } 00178 } 00179 }