00001
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #include <string.h>
00058
00059 #include "compiler.h"
00060 #include "FreeRTOS.h"
00061
00062 #include "shell.h"
00063 #include "datalog.h"
00064 #include "cpled.h"
00065 #include "lcd.h"
00066
00067 #include "tracedump.h"
00068 #include "cptime.h"
00069
00070
00071
00073 #define ACTUATOR_MAXNB_ACTUATORS (DATALOG_ID_LCD - DATALOG_ID_LEDB1 +1)
00074
00075 #define ACTUATOR_LIST "{ledb1,ledb2,ledm1,ledm2,lcd}"
00076
00077
00078
00080 typedef struct ActuatorReg {
00081
00082 Bool (*pfGetActuatorValue)( xLogDef *pxLog );
00083
00084 eExecStatus (*pfSetActuatorValue)( eModId xModId, int ac, signed portCHAR *av[],
00085 signed portCHAR **ppcStringReply );
00086 }xActuatorReg;
00087
00088 xActuatorReg axActuatorsRegistry[ACTUATOR_MAXNB_ACTUATORS] = {
00089 { b_ledb1_get_value, e_ledb1_set_value } ,
00090 { b_ledb2_get_value, e_ledb2_set_value } ,
00091 { b_ledm1_get_value, e_ledm1_set_value } ,
00092 { b_ledm2_get_value, e_ledm2_set_value } ,
00093 { b_lcd_get_value, e_lcd_set_value }
00094 };
00095
00099 typedef struct st_scheduled_param {
00100 int ac;
00101 signed portCHAR *av[4];
00102 }Scheduled_Cmd_Params;
00103
00104 const signed portCHAR *const ACTUATOR_MSG_HELP = (signed portCHAR *)"\
00105 "CRLF"set_actuator_value actuator={ledb1,ledb2} green=value red=value [time=date]"CRLF"\
00106 set_actuator_value actuator={ledm1,ledm2} state={on,off} [time=date]"CRLF"\
00107 set_actuator_value actuator=lcd usrmsg=\"string\" [time=date]"CRLF"\
00108 get_actuator_value actuator="ACTUATOR_LIST" : display the current value of an actuator"CRLF;
00109
00111 const signed portCHAR *const ACTUATOR_ERRMSG_GETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: get_actuator_value actuator=actuatorname"CRLF;
00112
00114 const signed portCHAR *const ACTUATOR_ERRMSG_UNREFACTUATOR = (signed portCHAR *)"Error"CRLF"Unreferenced actuator name"CRLF;
00115
00117 const signed portCHAR *const ACTUATOR_ERRMSG_GETVAL_FAIL = (signed portCHAR *)"Error"CRLF"Actuator failed to deliver a value."CRLF;
00118
00120 const signed portCHAR *const ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: set_actuator_value actuator=actuatorname fields..."CRLF;
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 eExecStatus e_actuator_cmd_get_value( eModId xModId, signed short FsNavId,
00141 int ac, signed portCHAR *av[],
00142 signed portCHAR **ppcStringReply )
00143 {
00144 int i;
00145 xLogDef *pxLog;
00146
00147
00148
00149 if( ppcStringReply == NULL )
00150 return( SHELL_EXECSTATUS_KO );
00151
00152
00153
00154 if( 2 != ac )
00155 {
00156 *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_GETVAL_SYNTAXERROR;
00157 return( SHELL_EXECSTATUS_KO );
00158 }
00159
00160
00161
00162
00163 for( i=DATALOG_ID_LEDB1;
00164 i<=DATALOG_ID_LCD && strcmp( (char *)av[1], acLogSourceName[i] );
00165 i++ );
00166 i -= DATALOG_ID_LEDB1;
00167
00168 if( ACTUATOR_MAXNB_ACTUATORS == i )
00169 {
00170 *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_UNREFACTUATOR;
00171 return( SHELL_EXECSTATUS_KO );
00172 }
00173
00174
00175
00176 pxLog = pxdatalog_log_alloc_init( DATALOG_ALLOC_DYNAMIC );
00177 if( NULL == pxLog )
00178 {
00179 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC;
00180 return( SHELL_EXECSTATUS_KO );
00181 }
00182
00183
00184 pxLog->id = i+DATALOG_ID_LEDB1;
00185
00186
00187 if( FALSE == axActuatorsRegistry[i].pfGetActuatorValue( pxLog ) )
00188 {
00189 vdatalog_log_free( pxLog );
00190 *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_GETVAL_FAIL;
00191 return( SHELL_EXECSTATUS_KO );
00192 }
00193
00194
00195
00196 *ppcStringReply = (signed portCHAR *)pvPortMalloc( DATALOG_LOG_MAXSIZE );
00197 if( NULL == *ppcStringReply )
00198 {
00199 vdatalog_log_free( pxLog );
00200 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC;
00201 return( SHELL_EXECSTATUS_KO );
00202 }
00203
00204
00205 vdatalog_make_logstring( pxLog, *ppcStringReply );
00206
00207
00208 vdatalog_log_free( pxLog );
00209
00210 return( SHELL_EXECSTATUS_OK );
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 eExecStatus e_actuator_cmd_set_value( eModId xModId, signed short FsNavId,
00237 int ac, signed portCHAR *av[],
00238 signed portCHAR **ppcStringReply )
00239 {
00240 int i;
00241
00242
00243
00244 if( ppcStringReply == NULL )
00245 return( SHELL_EXECSTATUS_KO );
00246
00247
00248
00249 if( ( 4 > ac ) || ( 8 < ac ) )
00250 {
00251 *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR;
00252 return( SHELL_EXECSTATUS_KO );
00253 }
00254
00255
00256
00257
00258 for( i=DATALOG_ID_LEDB1;
00259 i<=DATALOG_ID_LCD && strcmp( (char *)av[1], acLogSourceName[i] );
00260 i++ );
00261 i -= DATALOG_ID_LEDB1;
00262
00263 if( ACTUATOR_MAXNB_ACTUATORS == i )
00264 {
00265 *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_UNREFACTUATOR;
00266 return( SHELL_EXECSTATUS_KO );
00267 }
00268
00269
00270 return( axActuatorsRegistry[i].pfSetActuatorValue( xModId, ac-2, &(av[2]), ppcStringReply ) );
00271 }
00272
00273
00280 void vExecScheduledSet( int CmdId, void *pxCmdParams )
00281 {
00282 Scheduled_Cmd_Params *pxActuatorCmdParams;
00283 int i;
00284
00285
00286
00287 pxActuatorCmdParams = (Scheduled_Cmd_Params *)pxCmdParams;
00288 switch( CmdId )
00289 {
00290 case CPTIME_SCHEDCMDID_SETLEDM1VAL:
00291 e_ledm1_set_value( SYS_MODID_NONE, pxActuatorCmdParams->ac, pxActuatorCmdParams->av, NULL );
00292 break;
00293
00294 case CPTIME_SCHEDCMDID_SETLEDM2VAL:
00295 e_ledm2_set_value( SYS_MODID_NONE, pxActuatorCmdParams->ac, pxActuatorCmdParams->av, NULL );
00296 break;
00297
00298 case CPTIME_SCHEDCMDID_SETLEDB1VAL:
00299 e_ledb1_set_value( SYS_MODID_NONE, pxActuatorCmdParams->ac, pxActuatorCmdParams->av, NULL );
00300 break;
00301
00302 case CPTIME_SCHEDCMDID_SETLEDB2VAL:
00303 e_ledb2_set_value( SYS_MODID_NONE, pxActuatorCmdParams->ac, pxActuatorCmdParams->av, NULL );
00304 break;
00305
00306 case CPTIME_SCHEDCMDID_SETLCDVAL:
00307 e_lcd_set_value( SYS_MODID_NONE, pxActuatorCmdParams->ac, pxActuatorCmdParams->av, NULL );
00308 break;
00309 }
00310
00311 for( i=0; i<pxActuatorCmdParams->ac; i++ )
00312 {
00313 vPortFree( pxActuatorCmdParams->av[i] );
00314 }
00315 vPortFree( pxActuatorCmdParams );
00316 }
00317
00318
00332 eExecStatus e_actuator_ScheduleCmdSet( eSchedCmdId CmdId,
00333 int ac, signed portCHAR *av[],
00334 signed portCHAR **ppcStringReply )
00335 {
00336 int i,j;
00337 Scheduled_Cmd_Params *pxCmdParams;
00338
00339
00340
00341 if( strcmp( (char *)av[ac-2], "time" ) )
00342 {
00343 *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR;
00344 return( SHELL_EXECSTATUS_KO );
00345 }
00346
00347
00348
00349 pxCmdParams = pvPortMalloc( sizeof(Scheduled_Cmd_Params) );
00350 if( NULL == pxCmdParams )
00351 {
00352 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC;
00353 return( SHELL_EXECSTATUS_KO );
00354 }
00355
00356
00357 pxCmdParams->ac = ac-2;
00358 for( i=0; i<pxCmdParams->ac; i++ )
00359 {
00360 pxCmdParams->av[i] = pvPortMalloc( strlen( (char *)av[i] ) +1 );
00361 if( NULL == pxCmdParams->av[i] )
00362 {
00363 for(j=0; j<i; j++)
00364 {
00365 vPortFree( pxCmdParams->av[j] );
00366 }
00367 vPortFree( pxCmdParams );
00368 *ppcStringReply = (signed portCHAR *)SHELL_ERRMSG_MEMALLOC;
00369 return( SHELL_EXECSTATUS_KO );
00370 }
00371 }
00372
00373
00374 for( i=0; i<pxCmdParams->ac; i++ )
00375 {
00376 strcpy( (char *)pxCmdParams->av[i], (char *)av[i] );
00377 }
00378
00379
00380 return( e_cptime_RecordScheduledCmd( (char *)av[ac-1],
00381 CmdId,
00382 vExecScheduledSet,
00383 pxCmdParams,
00384 ppcStringReply) );
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 eExecStatus e_actuator_help( eModId xModId, signed short FsNavId,
00405 int ac, signed portCHAR *av[],
00406 signed portCHAR **ppcStringReply )
00407 {
00408
00409 if( ppcStringReply == NULL )
00410 return( SHELL_EXECSTATUS_KO );
00411
00412
00413 *ppcStringReply = (signed portCHAR *)ACTUATOR_MSG_HELP;
00414
00415 return( SHELL_EXECSTATUS_OK_NO_FREE );
00416 }