actuator.c File Reference


Detailed Description

AVR32 UC3 Control Panel actuators interface module.

This module acts as an interface to all actuators.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file actuator.c.

#include <string.h>
#include "compiler.h"
#include "FreeRTOS.h"
#include "shell.h"
#include "datalog.h"
#include "cpled.h"
#include "lcd.h"
#include "tracedump.h"
#include "cptime.h"

Go to the source code of this file.

Data Structures

struct  ActuatorReg
struct  st_scheduled_param

Defines

#define ACTUATOR_LIST   "{ledb1,ledb2,ledm1,ledm2,lcd}"
#define ACTUATOR_MAXNB_ACTUATORS   (DATALOG_ID_LCD - DATALOG_ID_LEDB1 +1)

Typedefs

typedef struct st_scheduled_param Scheduled_Cmd_Params
typedef struct ActuatorReg xActuatorReg

Functions

eExecStatus e_actuator_cmd_get_value (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
eExecStatus e_actuator_cmd_set_value (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
eExecStatus e_actuator_help (eModId xModId, signed short FsNavId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
eExecStatus e_actuator_ScheduleCmdSet (eSchedCmdId CmdId, int ac, signed portCHAR *av[], signed portCHAR **ppcStringReply)
 Schedule an actuator set for later.
void vExecScheduledSet (int CmdId, void *pxCmdParams)
 Execute a scheduled command.

Variables

const signed portCHAR *const ACTUATOR_ERRMSG_GETVAL_FAIL = (signed portCHAR *)"Error"CRLF"Actuator failed to deliver a value."CRLF
const signed portCHAR *const ACTUATOR_ERRMSG_GETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: get_actuator_value actuator=actuatorname"CRLF
const signed portCHAR *const ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: set_actuator_value actuator=actuatorname fields..."CRLF
const signed portCHAR *const ACTUATOR_ERRMSG_UNREFACTUATOR = (signed portCHAR *)"Error"CRLF"Unreferenced actuator name"CRLF
const signed portCHAR *const ACTUATOR_MSG_HELP
xActuatorReg axActuatorsRegistry [ACTUATOR_MAXNB_ACTUATORS]


Define Documentation

#define ACTUATOR_LIST   "{ledb1,ledb2,ledm1,ledm2,lcd}"

Definition at line 75 of file actuator.c.

#define ACTUATOR_MAXNB_ACTUATORS   (DATALOG_ID_LCD - DATALOG_ID_LEDB1 +1)

Max number of actuators.

Definition at line 73 of file actuator.c.

Referenced by e_actuator_cmd_get_value(), and e_actuator_cmd_set_value().


Typedef Documentation

typedef struct ActuatorReg xActuatorReg


Function Documentation

eExecStatus e_actuator_cmd_get_value ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

Definition at line 140 of file actuator.c.

References acLogSourceName, ACTUATOR_ERRMSG_GETVAL_FAIL, ACTUATOR_ERRMSG_GETVAL_SYNTAXERROR, ACTUATOR_ERRMSG_UNREFACTUATOR, ACTUATOR_MAXNB_ACTUATORS, DATALOG_ALLOC_DYNAMIC, DATALOG_ID_LCD, DATALOG_ID_LEDB1, DATALOG_LOG_MAXSIZE, LogDef::id, pxdatalog_log_alloc_init(), SHELL_ERRMSG_MEMALLOC, SHELL_EXECSTATUS_KO, SHELL_EXECSTATUS_OK, vdatalog_log_free(), and vdatalog_make_logstring().

00143 {
00144    int       i;
00145    xLogDef   *pxLog;
00146 
00147 
00148    /* 0) If the way to reply is unavailable, it's no use to continue. */
00149    if( ppcStringReply == NULL )
00150       return( SHELL_EXECSTATUS_KO );
00151 
00152    /* 1) Check the input. */
00153    //  i) Two arguments exactly.
00154    if( 2 != ac )
00155    {   // Syntax error.
00156       *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_GETVAL_SYNTAXERROR;
00157       return( SHELL_EXECSTATUS_KO );
00158    }
00159    // No need to check that av[0] == actuator. We actually use the "actuator=name"
00160    // format just to comply with the cgi calls rules.
00161 
00162    //  ii) Identify the actuator.
00163    for( i=DATALOG_ID_LEDB1;
00164         i<=DATALOG_ID_LCD && strcmp( (char *)av[1], acLogSourceName[i] );
00165         i++ );
00166    i -= DATALOG_ID_LEDB1; // Scale the index to fit for the actuator only array.
00167 
00168    if( ACTUATOR_MAXNB_ACTUATORS == i )
00169    {   // Unreferenced actuator.
00170       *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_UNREFACTUATOR;
00171       return( SHELL_EXECSTATUS_KO );
00172    }
00173 
00174    /* 3) Perform the command. */
00175    // Alloc and init a log.
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    // Init the id field of the log.
00184    pxLog->id = i+DATALOG_ID_LEDB1;
00185 
00186    // Get the value.
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    /* 4) Build the reply. */
00195    // Alloc space for the reply.
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    // Build the string.
00205    vdatalog_make_logstring( pxLog, *ppcStringReply );
00206 
00207    // Free the log.
00208    vdatalog_log_free( pxLog );
00209 
00210    return( SHELL_EXECSTATUS_OK );
00211 }

eExecStatus e_actuator_cmd_set_value ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

Definition at line 236 of file actuator.c.

References acLogSourceName, ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR, ACTUATOR_ERRMSG_UNREFACTUATOR, ACTUATOR_MAXNB_ACTUATORS, DATALOG_ID_LCD, DATALOG_ID_LEDB1, and SHELL_EXECSTATUS_KO.

00239 {
00240    int i;
00241 
00242 
00243    /* 0) If the way to reply is unavailable, it's no use to continue. */
00244    if( ppcStringReply == NULL )
00245       return( SHELL_EXECSTATUS_KO );
00246 
00247    /* 1) Check the input. */
00248    //  i) Arguments: at least 4, at most 8.
00249    if( ( 4 > ac ) || ( 8 < ac ) )
00250    {   // Syntax error.
00251       *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR;
00252       return( SHELL_EXECSTATUS_KO );
00253    }
00254    // No need to check that av[0] == actuator. We actually use the "actuator=name"
00255    // format just to comply with the cgi calls rules.
00256 
00257    //  ii) Identify the actuator.
00258    for( i=DATALOG_ID_LEDB1;
00259         i<=DATALOG_ID_LCD && strcmp( (char *)av[1], acLogSourceName[i] );
00260         i++ );
00261    i -= DATALOG_ID_LEDB1; // Scale the index to fit for the actuator only array.
00262 
00263    if( ACTUATOR_MAXNB_ACTUATORS == i )
00264    {
00265       *ppcStringReply = (signed portCHAR *)ACTUATOR_ERRMSG_UNREFACTUATOR;
00266       return( SHELL_EXECSTATUS_KO );
00267    }
00268 
00269    /* 3) Perform the command. */
00270    return( axActuatorsRegistry[i].pfSetActuatorValue( xModId, ac-2, &(av[2]), ppcStringReply ) );
00271 }

eExecStatus e_actuator_help ( eModId  xModId,
signed short  FsNavId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

Definition at line 404 of file actuator.c.

References ACTUATOR_MSG_HELP, SHELL_EXECSTATUS_KO, and SHELL_EXECSTATUS_OK_NO_FREE.

Referenced by e_Shell_help().

00407 {
00408    // 1) If the way to reply is unavailable, it's no use to continue.
00409    if( ppcStringReply == NULL )
00410       return( SHELL_EXECSTATUS_KO );
00411 
00412    // 2) Perform the command.
00413    *ppcStringReply = (signed portCHAR *)ACTUATOR_MSG_HELP;
00414 
00415    return( SHELL_EXECSTATUS_OK_NO_FREE );
00416 }

eExecStatus e_actuator_ScheduleCmdSet ( eSchedCmdId  CmdId,
int  ac,
signed portCHAR *  av[],
signed portCHAR **  ppcStringReply 
)

Schedule an actuator set for later.

Parameters:
CmdId Input. The set actuator cmd identifier.
ac Input. The argument counter.
av Input. The argument vector.
ppcStringReply Input/Output. The response string. If Input is NULL, no response string will be output. If the action is successful, no response string is output. If the action failed, a response string is output.
Returns:
the status of the command execution.

Definition at line 332 of file actuator.c.

References st_scheduled_param::ac, ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR, st_scheduled_param::av, e_cptime_RecordScheduledCmd(), SHELL_ERRMSG_MEMALLOC, SHELL_EXECSTATUS_KO, and vExecScheduledSet().

Referenced by e_lcd_set_value(), e_ledb1_set_value(), e_ledb2_set_value(), e_ledm1_set_value(), and e_ledm2_set_value().

00335 {
00336    int                    i,j;
00337    Scheduled_Cmd_Params   *pxCmdParams;
00338 
00339 
00340    // Check that the before-last param is "time".
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    // Alloc and fill a param structure that contains the parameters that will
00348    // be given to the scheduled function when it will execute.
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    // Alloc the params.
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       {   // An alloc failed => free previous alloc.
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    // Copy the params.
00374    for( i=0; i<pxCmdParams->ac; i++ )
00375    {
00376       strcpy( (char *)pxCmdParams->av[i], (char *)av[i] );
00377    }
00378 
00379    // Record the cmd.
00380    return( e_cptime_RecordScheduledCmd( (char *)av[ac-1],
00381                                         CmdId,
00382                                         vExecScheduledSet,
00383                                         pxCmdParams,
00384                                         ppcStringReply) );
00385 }

void vExecScheduledSet ( int  CmdId,
void *  pxCmdParams 
)

Execute a scheduled command.

Parameters:
CmdId Input. The set cmd identifier.
pxCmdParams Input. The parameters (ac,*av[]) for the cmd.

Definition at line 280 of file actuator.c.

References st_scheduled_param::ac, st_scheduled_param::av, CPTIME_SCHEDCMDID_SETLCDVAL, CPTIME_SCHEDCMDID_SETLEDB1VAL, CPTIME_SCHEDCMDID_SETLEDB2VAL, CPTIME_SCHEDCMDID_SETLEDM1VAL, CPTIME_SCHEDCMDID_SETLEDM2VAL, e_lcd_set_value(), e_ledb1_set_value(), e_ledb2_set_value(), e_ledm1_set_value(), e_ledm2_set_value(), and SYS_MODID_NONE.

Referenced by e_actuator_ScheduleCmdSet().

00281 {
00282    Scheduled_Cmd_Params   *pxActuatorCmdParams;
00283    int                    i;
00284 
00285 
00286    // Cast pxCmdParams to the appropriate struct.
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    // Free the string params and the params struct.
00311    for( i=0; i<pxActuatorCmdParams->ac; i++ )
00312    {
00313       vPortFree( pxActuatorCmdParams->av[i] );
00314    }
00315    vPortFree( pxActuatorCmdParams );
00316 }


Variable Documentation

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

Error msg upon get_actuator_value actuator error.

Definition at line 117 of file actuator.c.

Referenced by e_actuator_cmd_get_value().

const signed portCHAR* const ACTUATOR_ERRMSG_GETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: get_actuator_value actuator=actuatorname"CRLF

Error msg upon get_actuator_value syntax error.

Definition at line 111 of file actuator.c.

Referenced by e_actuator_cmd_get_value().

const signed portCHAR* const ACTUATOR_ERRMSG_SETVAL_SYNTAXERROR = (signed portCHAR *)"Error"CRLF"Usage: set_actuator_value actuator=actuatorname fields..."CRLF

Error msg upon set_actuator_value syntax error.

Definition at line 120 of file actuator.c.

Referenced by e_actuator_cmd_set_value(), e_actuator_ScheduleCmdSet(), e_lcd_set_value(), e_ledb1_set_value(), e_ledb2_set_value(), e_ledm1_set_value(), and e_ledm2_set_value().

const signed portCHAR* const ACTUATOR_ERRMSG_UNREFACTUATOR = (signed portCHAR *)"Error"CRLF"Unreferenced actuator name"CRLF

Error msg upon unreferenced actuator error.

Definition at line 114 of file actuator.c.

Referenced by e_actuator_cmd_get_value(), and e_actuator_cmd_set_value().

const signed portCHAR* const ACTUATOR_MSG_HELP

Initial value:

 (signed portCHAR *)"\
"CRLF"set_actuator_value actuator={ledb1,ledb2} green=value red=value [time=date]"CRLF"\
set_actuator_value actuator={ledm1,ledm2} state={on,off} [time=date]"CRLF"\
set_actuator_value actuator=lcd usrmsg=\"string\" [time=date]"CRLF"\
get_actuator_value actuator="ACTUATOR_LIST" : display the current value of an actuator"CRLF

Definition at line 104 of file actuator.c.

Referenced by e_actuator_help().

xActuatorReg axActuatorsRegistry[ACTUATOR_MAXNB_ACTUATORS]


Generated on Fri Feb 19 02:22:42 2010 for AVR32 - Control Panel demonstration. by  doxygen 1.5.5