Definition in file temperature.h.
#include "compiler.h"
#include "FreeRTOS.h"
#include "datalog.h"
Go to the source code of this file.
Functions | |
Bool | b_temperature_get_value (xLogDef *pxLog) |
Get the current temperature value. | |
Bool | b_temperature_init (void) |
Init the temperature channel. | |
eExecStatus | e_temperature_get_config (signed portCHAR **ppcStringReply) |
Get the temperature sensor config. | |
eExecStatus | e_temperature_set_config (signed portCHAR **ppcStringReply, int ac, signed portCHAR *av[]) |
Set the sensor config. | |
Variables | |
unsigned int | ul_temp_lograte |
Bool b_temperature_get_value | ( | xLogDef * | pxLog | ) |
Get the current temperature value.
pxLog | a Log structure. |
Definition at line 283 of file temperature.c.
References adc, b_temp_alarm, b_temp_alarm_max, b_temp_alarm_min, l_temp_max, l_temp_min, LogDef::pcStringLog, LogDef::pfFreeStringLog, sprintf(), temperature_code, and v_SMTP_Post().
Referenced by b_sensor_get_value().
00284 { 00285 int i_current_val, value, index = 0; 00286 00287 00288 /* enable channel for sensor */ 00289 adc_enable( adc, ADC_TEMPERATURE_CHANNEL ); 00290 // start conversion 00291 adc_start( adc ); 00292 // get value for sensor 00293 value = adc_get_value( adc, ADC_TEMPERATURE_CHANNEL ); 00294 /* Disable channel for sensor */ 00295 adc_disable( adc, ADC_TEMPERATURE_CHANNEL ); 00296 00297 if(value > temperature_code[0]) 00298 { 00299 i_current_val = -20; 00300 } 00301 else 00302 { 00303 while(temperature_code[index++] > value); 00304 i_current_val = (index - 1 - 20); 00305 } 00306 00307 // Alloc memory for the log string. 00308 pxLog->pcStringLog = pvPortMalloc( 12*sizeof( char ) ); 00309 if( NULL == pxLog->pcStringLog ) 00310 { 00311 return( FALSE ); 00312 } 00313 pxLog->pfFreeStringLog = vPortFree; // Because pvPortMalloc() was used to 00314 // alloc the log string. 00315 00316 // Build the log string. 00317 if( i_current_val <= l_temp_min ) 00318 { 00319 sprintf( pxLog->pcStringLog, "%3dC | min", i_current_val ); 00320 // if alarms have to be checked and no alarm for min was pending 00321 if (( b_temp_alarm == pdTRUE ) && ( b_temp_alarm_min == pdFALSE )) 00322 { 00323 // alarm has been taken into account, 00324 // don't reenter this test before leaving min area 00325 b_temp_alarm_min = pdTRUE; 00326 // allow alarm if max is reached 00327 b_temp_alarm_max = pdFALSE; 00328 // post alarm to SMTP task 00329 v_SMTP_Post("Min Temp Alarm", NULL); 00330 } 00331 } 00332 else if( i_current_val >= l_temp_max ) 00333 { 00334 sprintf( pxLog->pcStringLog, "%3dC | max", i_current_val ); 00335 // if alarms have to be checked and no alarm for max was pending 00336 if (( b_temp_alarm == pdTRUE ) && ( b_temp_alarm_max == pdFALSE )) 00337 { 00338 // alarm has been taken into account, 00339 // don't reenter this test before leaving max area 00340 b_temp_alarm_max = pdTRUE; 00341 // allow alarm if min is reached 00342 b_temp_alarm_min = pdFALSE; 00343 // post alarm to SMTP task 00344 v_SMTP_Post("Max Temp Alarm", NULL); 00345 } 00346 } 00347 else 00348 { 00349 sprintf( pxLog->pcStringLog, "%3dC", i_current_val ); 00350 // if alarms have to be checked 00351 if ( b_temp_alarm == pdTRUE ) 00352 { 00353 // no alarm is pending 00354 b_temp_alarm_max = pdFALSE; 00355 b_temp_alarm_min = pdFALSE; 00356 } 00357 } 00358 00359 return( TRUE ); 00360 }
Bool b_temperature_init | ( | void | ) |
Init the temperature channel.
Definition at line 122 of file temperature.c.
References b_temp_alarm, config_file_get_value(), l_temp_max, l_temp_min, SENSOR_TEMP_CONFIG_FILE, ul_temp_lograte, x_supervisor_SemaphoreGive(), x_supervisor_SemaphoreTake(), and xCFGMutex.
00123 { 00124 portCHAR token[6]; 00125 portCHAR * unit; 00126 00127 // Get the xCFGMutex. 00128 if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) ) 00129 { 00130 // get the field 00131 if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "alarm" , token) >= 0) 00132 { 00133 // update value 00134 if (!strcmp(token, "on")) 00135 { 00136 b_temp_alarm = pdTRUE; 00137 } 00138 } 00139 if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "min" , token) >= 0) 00140 { 00141 unit = strpbrk(token , "C"); 00142 if (unit != NULL) 00143 { 00144 *unit = '\0'; 00145 } 00146 l_temp_min = atol(token); 00147 } 00148 if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "max" , token) >= 0) 00149 { 00150 unit = strpbrk(token , "C"); 00151 if (unit != NULL) 00152 { 00153 *unit = '\0'; 00154 } 00155 l_temp_max = atol(token); 00156 } 00157 if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "lograte" , token) >= 0) 00158 { 00159 ul_temp_lograte = atoi(token); 00160 } 00161 // Release the xCFGMutex. 00162 x_supervisor_SemaphoreGive( xCFGMutex ); 00163 } 00164 /* enable pin for sensor */ 00165 gpio_enable_module_pin( ADC_TEMPERATURE_PIN , ADC_TEMPERATURE_FUNCTION ); 00166 00167 return (TRUE); 00168 }
eExecStatus e_temperature_get_config | ( | signed portCHAR ** | ppcStringReply | ) |
Get the temperature sensor config.
ppcStringReply | Input/Output. The response string. NEVER NULL AS INPUT. A malloc for the response string is performed here; the caller must free this string. |
Definition at line 179 of file temperature.c.
References b_temp_alarm, l_temp_max, l_temp_min, SHELL_ERRMSG_MEMALLOC, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, sprintf(), TEMPERATURE_GETCONF_MAXLEN, and ul_temp_lograte.
00180 { 00181 // Alloc space for the reply. 00182 *ppcStringReply = (signed portCHAR *)pvPortMalloc( TEMPERATURE_GETCONF_MAXLEN ); 00183 if( NULL == *ppcStringReply ) 00184 { 00185 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC; 00186 return( SHELL_EXECSTATUS_KO ); 00187 } 00188 // Build the string. 00189 sprintf( (char *)*ppcStringReply, "lograte=%d\r\n""min=%dC\r\n""max=%dC\r\n""alarm=%s\r\n", 00190 ul_temp_lograte, l_temp_min, l_temp_max, ((b_temp_alarm == pdTRUE) ? "on" : "off") ); 00191 return( SHELL_EXECSTATUS_OK ); 00192 }
eExecStatus e_temperature_set_config | ( | signed portCHAR ** | ppcStringReply, | |
int | ac, | |||
signed portCHAR * | av[] | |||
) |
Set the sensor config.
ppcStringReply | Input/Output. The response string. NEVER NULL AS INPUT. | |
ac | Input. Number of args | |
av | Input. pointer to args |
Definition at line 203 of file temperature.c.
References b_temp_alarm, config_file_set_value(), l_temp_max, l_temp_min, SENSOR_MSG_ALARM_OFF, SENSOR_MSG_ALARM_ON, SENSOR_MSG_CONFIG_SET, SENSOR_TEMP_CONFIG_FILE, SHELL_ERRMSG_CONFIGERROR, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK_NO_FREE, and ul_temp_lograte.
00204 { 00205 portCHAR * token; 00206 00207 00208 if (config_file_set_value(SENSOR_TEMP_CONFIG_FILE, ac, av) != 0) 00209 { 00210 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR; 00211 // return error 00212 return( SHELL_EXECSTATUS_KO ); 00213 } 00214 00215 // alarm field 00216 if (!strcmp((char *)av[0] , "alarm")) 00217 { 00218 if (!strcmp((char *)av[1] , "on")) 00219 { 00220 b_temp_alarm = pdTRUE; 00221 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_ON; 00222 return( SHELL_EXECSTATUS_OK_NO_FREE ); 00223 } 00224 else if (!strcmp( (char *)av[1], "off")) 00225 { 00226 b_temp_alarm = pdFALSE; 00227 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_ALARM_OFF; 00228 return( SHELL_EXECSTATUS_OK_NO_FREE ); 00229 } 00230 else 00231 { 00232 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR; 00233 return( SHELL_EXECSTATUS_KO ); 00234 } 00235 } 00236 // lograte field 00237 else if (!strcmp((char *)av[0] , "lograte")) 00238 { 00239 ul_temp_lograte = atoi((char *)av[1]); 00240 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_CONFIG_SET; 00241 return( SHELL_EXECSTATUS_OK_NO_FREE ); 00242 } 00243 // min field 00244 else if (!strcmp((char *)av[0] , "min")) 00245 { 00246 token = strpbrk((char *)av[1] , "C"); 00247 if (token != NULL) 00248 { 00249 *token = '\0'; 00250 } 00251 l_temp_min = atoi((char *)av[1]); 00252 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_CONFIG_SET; 00253 return( SHELL_EXECSTATUS_OK_NO_FREE ); 00254 } 00255 // max field 00256 else if (!strcmp((char *)av[0] , "max")) 00257 { 00258 token = strpbrk((char *)av[1] , "C"); 00259 if (token != NULL) 00260 { 00261 *token = '\0'; 00262 } 00263 l_temp_max = atoi((char *)av[1]); 00264 *ppcStringReply = (signed portCHAR *)SENSOR_MSG_CONFIG_SET; 00265 return( SHELL_EXECSTATUS_OK_NO_FREE ); 00266 } 00267 // unknown field : error 00268 else 00269 00270 { 00271 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_CONFIGERROR; 00272 return( SHELL_EXECSTATUS_KO ); 00273 } 00274 }
unsigned int ul_temp_lograte |
Declaration for datalog use
Value for the log rate.
Definition at line 92 of file temperature.c.
Referenced by b_temperature_init(), e_temperature_get_config(), e_temperature_set_config(), and portTASK_FUNCTION().