Microchip® Advanced Software Framework

sensor.c File Reference
#include <string.h>
#include "compiler.h"
#include "FreeRTOS.h"
#include "tracedump.h"
#include "supervisor.h"
#include "shell.h"
#include "sensor.h"
#include "temperature.h"
#include "potentiometer.h"
#include "light.h"
#include "pushb.h"
#include "joystick.h"
#include "adc.h"

Data Structures

struct  SensorReg
 

Macros

#define SENSOR_LIST   "{temp,pot,light,pb1,pb2,pb3,js,all}"
 
#define SENSOR_MAXNB_SENSORS   (DATALOG_ID_JS - DATALOG_ID_TEMP +1)
 

Typedefs

typedef struct SensorReg xSensorReg
 

Functions

bool b_sensor_get_value (xLogDef *pxLog)
 Get a current sensor value. More...
 
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. More...
 
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 current value from a sensor. Format: get_sensor_value sensor=sensorname. More...
 
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. More...
 
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. More...
 
void v_sensor_stop (void)
 Stop the sensor module resources. More...
 

Variables

xSensorReg axSensorsRegistry [SENSOR_MAXNB_SENSORS]
 
const signed portCHAR *const SENSOR_ERRMSG_GETCFG_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: get_sensor_config sensor=sensorname"CRLF
 
const signed portCHAR *const SENSOR_ERRMSG_GETVAL_FAIL = (signed portCHAR *)"Error"CRLF"Sensor failed to deliver a value."CRLF
 
const signed portCHAR *const SENSOR_ERRMSG_GETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: get_sensor_value sensor=sensorname"CRLF
 
const signed portCHAR *const SENSOR_ERRMSG_SETCFG_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: set_sensor_config sensor=sensorname param=value"CRLF
 
const signed portCHAR *const SENSOR_ERRMSG_UNREFSENSOR = (signed portCHAR *)"Error"CRLF"Unreferenced sensor name"CRLF
 
const signed portCHAR *const SENSOR_MSG_HELP
 
xSemaphoreHandle xCFGMutex
 

#define SENSOR_LIST   "{temp,pot,light,pb1,pb2,pb3,js,all}"
#define SENSOR_MAXNB_SENSORS   (DATALOG_ID_JS - DATALOG_ID_TEMP +1)

typedef struct SensorReg xSensorReg

A sensor register cell structure.

bool b_sensor_get_value ( xLogDef pxLog)

Get a current sensor value.

Parameters
pxLoga Log structure. The sensor id is in the id field of pxLog.
Returns
true upon success, false if error.

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().

bool bsensor_start ( void  )

Start the sensor module.

Returns
true upon success, else false.

References adc, adc_configure(), NAKED_TRACE_COM2, and SENSOR_MAXNB_SENSORS.

Referenced by portTASK_FUNCTION().

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.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acInput. The argument counter. For this command, should be 1.
avInput. The argument vector.
ppcStringReplyInput/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.
Returns
the status of the command execution.

References acLogSourceName, DATALOG_ID_JS, DATALOG_ID_TEMP, NULL, SENSOR_ERRMSG_GETCFG_SYNTAXERROR, SENSOR_ERRMSG_UNREFSENSOR, SENSOR_MAXNB_SENSORS, and SHELL_EXECSTATUS_KO.

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 current value from a sensor. Format: get_sensor_value sensor=sensorname.

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.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acInput. The argument counter. For this command, should be 2.
avInput. The argument vector.
ppcStringReplyInput/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.
Returns
the status of the command execution.

References acLogSourceName, DATALOG_ALLOC_DYNAMIC, DATALOG_ID_JS, DATALOG_ID_TEMP, DATALOG_LOG_MAXSIZE, LogDef::id, NULL, LogDef::pcStringLog, LogDef::pfFreeStringLog, pvPortMalloc(), 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(), vdatalog_make_logstring(), and vPortFree().

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.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acInput. The argument counter. For this command, should be 3.
avInput. The argument vector.
ppcStringReplyInput/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.
Returns
the status of the command execution.

References acLogSourceName, DATALOG_ID_JS, DATALOG_ID_TEMP, NULL, pdFALSE, SensorReg::pfSetSensorConfig, SENSOR_ERRMSG_SETCFG_SYNTAXERROR, SENSOR_ERRMSG_UNREFSENSOR, SENSOR_MAXNB_SENSORS, SHELL_ERRMSG_MAINTENANCEMODE, SHELL_EXECSTATUS_KO, x_supervisor_SemaphoreGive(), and x_supervisor_SemaphoreTake().

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.

Note
This function must be of the type pfShellCmd defined by the shell module.
Parameters
xModIdInput. The module that is calling this function.
FsNavIdIgnored.
acIgnored.
avIgnored.
ppcStringReplyInput/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.
Returns
the status of the command execution.

References NULL, SENSOR_MSG_HELP, SHELL_EXECSTATUS_KO, and SHELL_EXECSTATUS_OK_NO_FREE.

Referenced by e_Shell_help().

void v_sensor_stop ( void  )

Stop the sensor module resources.

References NULL, SensorReg::pfStopSensor, and SENSOR_MAXNB_SENSORS.

Referenced by e_syscmds_reboot().

xSensorReg axSensorsRegistry[SENSOR_MAXNB_SENSORS]
Initial value:
= {
}
bool b_pushb2_get_value(xLogDef *pxLog)
Get a pushbutton current state.
Definition: pushb.c:372
bool b_temperature_get_value(xLogDef *pxLog)
Get the current temperature value.
Definition: temperature.c:281
bool b_light_init(void)
Init the light sensor channel.
Definition: light.c:106
bool b_joystick_init(void)
Init the joystick sensor.
Definition: joystick.c:131
bool b_pushb1_init(void)
Init the push button 1 sensor.
Definition: pushb.c:129
eExecStatus e_pushb3_get_config(signed portCHAR **ppcStringReply)
Get the pushbutton3 sensor config.
Definition: pushb.c:295
#define NULL
Definition: def.h:47
void v_joystick_stop(void)
Stop the joystick sensor.
Definition: joystick.c:173
eExecStatus e_pushb2_get_config(signed portCHAR **ppcStringReply)
Get the pushbutton2 sensor config.
Definition: pushb.c:280
eExecStatus e_light_get_config(signed portCHAR **ppcStringReply)
Get the light sensor config.
Definition: light.c:163
void v_pushb1_stop(void)
Stop the push button 1 sensor.
Definition: pushb.c:162
eExecStatus e_pushb2_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
set push button config command: set the config fields value of a sensor. Takes one parameter...
Definition: pushb.c:329
eExecStatus e_pushb3_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
set push button config command: set the config fields value of a sensor. Takes one parameter...
Definition: pushb.c:344
bool b_pushb3_get_value(xLogDef *pxLog)
Get a pushbutton current state.
Definition: pushb.c:388
bool b_pushb3_init(void)
Init the push button 3 sensor.
Definition: pushb.c:217
eExecStatus e_joystick_get_config(signed portCHAR **ppcStringReply)
Get the joystick sensor config.
Definition: joystick.c:193
bool b_potentiometer_init(void)
Init the potentiometer channel.
Definition: potentiometer.c:102
eExecStatus e_pushb1_get_config(signed portCHAR **ppcStringReply)
Get the pushbutton1 sensor config.
Definition: pushb.c:265
bool b_pushb1_get_value(xLogDef *pxLog)
Get a pushbutton current state.
Definition: pushb.c:356
eExecStatus e_temperature_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: temperature.c:201
eExecStatus e_potentiometer_get_config(signed portCHAR **ppcStringReply)
Get the potentiometer sensor config.
Definition: potentiometer.c:159
eExecStatus e_pushb1_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
set push button config command: set the config fields value of a sensor. Takes one parameter...
Definition: pushb.c:314
bool b_potentiometer_get_value(xLogDef *pxLog)
Get the current potentiometer value.
Definition: potentiometer.c:258
bool b_temperature_init(void)
Init the temperature channel.
Definition: temperature.c:120
eExecStatus e_light_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: light.c:189
bool b_joystick_get_value(xLogDef *pxLog)
Get the current joystick state.
Definition: joystick.c:252
void v_pushb3_stop(void)
Stop the push button 3 sensor.
Definition: pushb.c:250
bool b_pushb2_init(void)
Init the push button 2 sensor.
Definition: pushb.c:173
eExecStatus e_temperature_get_config(signed portCHAR **ppcStringReply)
Get the temperature sensor config.
Definition: temperature.c:177
eExecStatus e_potentiometer_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: potentiometer.c:185
bool b_light_get_value(xLogDef *pxLog)
Get the current light value.
Definition: light.c:262
eExecStatus e_joystick_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: joystick.c:213
void v_pushb2_stop(void)
Stop the push button 2 sensor.
Definition: pushb.c:206
const signed portCHAR* const SENSOR_ERRMSG_GETCFG_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: get_sensor_config sensor=sensorname"CRLF

Error msg upon get_sensor_config syntax error.

Referenced by e_sensor_cmd_get_config().

const signed portCHAR* const SENSOR_ERRMSG_GETVAL_FAIL = (signed portCHAR *)"Error"CRLF"Sensor failed to deliver a value."CRLF

Error msg upon get_sensor_value sensor error.

Referenced by e_sensor_cmd_get_value().

const signed portCHAR* const SENSOR_ERRMSG_GETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: get_sensor_value sensor=sensorname"CRLF

Error msg upon get_sensor_value syntax error.

Referenced by e_sensor_cmd_get_value().

const signed portCHAR* const SENSOR_ERRMSG_SETCFG_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: set_sensor_config sensor=sensorname param=value"CRLF

Error msg upon get_sensor_config syntax error.

Referenced by e_sensor_cmd_set_config().

const signed portCHAR* const SENSOR_ERRMSG_UNREFSENSOR = (signed portCHAR *)"Error"CRLF"Unreferenced sensor name"CRLF

Error msg upon unreferenced sensor error.

Referenced by e_sensor_cmd_get_config(), e_sensor_cmd_get_value(), and e_sensor_cmd_set_config().

const signed portCHAR* const SENSOR_MSG_HELP
Initial value:
= (signed portCHAR *)"\
"CRLF"get_sensor_config sensor="SENSOR_LIST" : display the config of a sensor"CRLF"\
set_sensor_config sensor=temp min=val : set the min temp that triggers an alarm"CRLF"\
set_sensor_config sensor=temp max=val : set the max temp that triggers an alarm"CRLF"\
set_sensor_config sensor=pot min=val : set the min value that triggers an alarm"CRLF"\
set_sensor_config sensor=pot max=val : set the max value that triggers an alarm"CRLF"\
set_sensor_config sensor=light min=val : set the min value that triggers an alarm"CRLF"\
set_sensor_config sensor=light max=val : set the max value that triggers an alarm"CRLF"\
set_sensor_config sensor=pb{1,2,3} alarm={on,off} : en/disable an alarm upon event"CRLF"\
set_sensor_config sensor=js alarm={on,off} : en/disable an alarm upon event"CRLF"\
get_sensor_value sensor="SENSOR_LIST" : display the current value of one sensor or of all sensors"CRLF
#define CRLF
Definition: shell.h:61
#define SENSOR_LIST
Definition: sensor.c:77

Referenced by e_sensor_help().

xSemaphoreHandle xCFGMutex

The CFG system mutex.