Atmel Software Framework

avr32/applications/evk1100-control-panel/sensors/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(), i, 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, i, 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, end, i, 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, i, 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 i, 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:379
#define NULL
Definition: lwip-1.4.0/src/include/lwip/def.h:47
bool b_temperature_get_value(xLogDef *pxLog)
Get the current temperature value.
Definition: temperature.c:288
bool b_light_init(void)
Init the light sensor channel.
Definition: light.c:113
bool b_joystick_init(void)
Init the joystick sensor.
Definition: joystick.c:138
bool b_pushb1_init(void)
Init the push button 1 sensor.
Definition: pushb.c:136
eExecStatus e_pushb3_get_config(signed portCHAR **ppcStringReply)
Get the pushbutton3 sensor config.
Definition: pushb.c:302
void v_joystick_stop(void)
Stop the joystick sensor.
Definition: joystick.c:180
eExecStatus e_pushb2_get_config(signed portCHAR **ppcStringReply)
Get the pushbutton2 sensor config.
Definition: pushb.c:287
eExecStatus e_light_get_config(signed portCHAR **ppcStringReply)
Get the light sensor config.
Definition: light.c:170
void v_pushb1_stop(void)
Stop the push button 1 sensor.
Definition: pushb.c:169
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:336
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:351
bool b_pushb3_get_value(xLogDef *pxLog)
Get a pushbutton current state.
Definition: pushb.c:395
bool b_pushb3_init(void)
Init the push button 3 sensor.
Definition: pushb.c:224
eExecStatus e_joystick_get_config(signed portCHAR **ppcStringReply)
Get the joystick sensor config.
Definition: joystick.c:200
bool b_potentiometer_init(void)
Init the potentiometer channel.
Definition: potentiometer.c:109
eExecStatus e_pushb1_get_config(signed portCHAR **ppcStringReply)
Get the pushbutton1 sensor config.
Definition: pushb.c:272
bool b_pushb1_get_value(xLogDef *pxLog)
Get a pushbutton current state.
Definition: pushb.c:363
eExecStatus e_temperature_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: temperature.c:208
eExecStatus e_potentiometer_get_config(signed portCHAR **ppcStringReply)
Get the potentiometer sensor config.
Definition: potentiometer.c:166
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:321
bool b_potentiometer_get_value(xLogDef *pxLog)
Get the current potentiometer value.
Definition: potentiometer.c:265
bool b_temperature_init(void)
Init the temperature channel.
Definition: temperature.c:127
eExecStatus e_light_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: light.c:196
bool b_joystick_get_value(xLogDef *pxLog)
Get the current joystick state.
Definition: joystick.c:259
void v_pushb3_stop(void)
Stop the push button 3 sensor.
Definition: pushb.c:257
bool b_pushb2_init(void)
Init the push button 2 sensor.
Definition: pushb.c:180
eExecStatus e_temperature_get_config(signed portCHAR **ppcStringReply)
Get the temperature sensor config.
Definition: temperature.c:184
eExecStatus e_potentiometer_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: potentiometer.c:192
bool b_light_get_value(xLogDef *pxLog)
Get the current light value.
Definition: light.c:269
eExecStatus e_joystick_set_config(signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[])
Set the sensor config.
Definition: joystick.c:220
void v_pushb2_stop(void)
Stop the push button 2 sensor.
Definition: pushb.c:213
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 SENSOR_LIST
Definition: avr32/applications/evk1100-control-panel/sensors/sensor.c:84
#define CRLF
Carriage Return + Line Feed.
Definition: print_funcs.h:252

Referenced by e_sensor_help().

xSemaphoreHandle xCFGMutex

The CFG system mutex.