rllib  1
rlstatemachine.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002 *                                                                         *
00003 *   This library is free software; you can redistribute it and/or modify  *
00004 *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00005 *   published by the Free Software Foundation                             *
00006 *                                                                         *
00007 ***************************************************************************/
00008 #include "rlstatemachine.h"
00009 
00010 rlStatemachine::rlStatemachine(int numStates, int numProcessVariables)
00011 {
00012   state = 0;
00013   num_states = 0;
00014   var = NULL;
00015   num_states = numStates;
00016   num_process_variables = numProcessVariables;
00017   if(numProcessVariables <= 0) return;
00018   var = new rlPlcState(numProcessVariables, numProcessVariables, numProcessVariables);
00019 }
00020 
00021 rlStatemachine::~rlStatemachine()
00022 {
00023   if(var != NULL) delete var;
00024 }
00025 
00026 int rlStatemachine::setPlcStateInt(int index, int val)
00027 {
00028   if(index < 0) return 0;
00029   if(index >= num_process_variables) return 0;
00030   if(var == NULL) return 0;
00031   var->i_old[index] = var->i[index];
00032   var->i[index] = val;
00033   return val;
00034 }
00035 
00036 float rlStatemachine::setPlcStateFloat(int index, float val)
00037 {
00038   if(index < 0) return 0;
00039   if(index >= num_process_variables) return 0;
00040   if(var == NULL) return 0;
00041   var->f_old[index] = var->f[index];
00042   var->f[index] = val;
00043   return val;
00044 }
00045 
00046 double rlStatemachine::setPlcStateDouble(int index, double val)
00047 {
00048   if(index < 0) return 0;
00049   if(index >= num_process_variables) return 0;
00050   if(var == NULL) return 0;
00051   var->d_old[index] = var->d[index];
00052   var->d[index] = val;
00053   return val;
00054 }
00055 
00056 void rlStatemachine::doState()
00057 {
00058   // implement in subclass
00059 }
00060 
00061 void rlStatemachine::enterState(int newState, int whichEntry)
00062 {
00063   // implement in subclass and call rlStatemachine::enterState(newState,whichEntry);
00064   if(newState < 0) return;
00065   if(newState >= num_states) return;
00066   if(whichEntry){}
00067   state = newState;
00068 }
00069 
00070 void rlStatemachine::exitState(int whichExit)
00071 {
00072   // implement in subclass
00073   if(whichExit){}
00074 }
00075 
00076 int rlStatemachine::getPlcStateInt(int index)
00077 {
00078   if(index < 0) return 0;
00079   if(index >= num_process_variables) return 0;
00080   if(var == NULL) return 0;
00081   return var->i[index];
00082 }
00083 
00084 float rlStatemachine::getPlcStateFloat(int index)
00085 {
00086   if(index < 0) return 0;
00087   if(index >= num_process_variables) return 0;
00088   if(var == NULL) return 0;
00089   return var->f[index];
00090 }
00091 
00092 double rlStatemachine::getPlcStateDouble(int index)
00093 {
00094   if(index < 0) return 0;
00095   if(index >= num_process_variables) return 0;
00096   if(var == NULL) return 0;
00097   return var->d[index];
00098 }
00099 
00100 int rlStatemachine::getState()
00101 {
00102   return state;
00103 }
00104 
00105 rlPlcState *rlStatemachine::getVar()
00106 {
00107   return var;
00108 }
00109 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines