rasProject_01 / weSweetHome  R. 240
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
state_t Struct Reference

The structure for state machines. More...

#include <weStateM.h>

Data Fields

union {
   float   controlF
 the analogue / float control value (some state types)
 
   uint32_t   controlV
 the integer control value (most state types)
 
   char   controlVS [6]
 the state change cause
 
}; 
 the control (parameter) value lead to current state
 
union {
   float   instanceF [4]
 instance's float values (4 * 4 byte)
 
}; 
 float and byte values to the state machines disposal. More...
 
union {
   enterState_t const   doEnter
 This state machine's function to enter it. More...
 
   enterStateF_t const   doEnterF
 Float control substitute or addendum to state_t.doEnter.
 
   enterStateS_t const   doEnterS
 Character control substitute or addendum to state_t.doEnter.
 
}; 
 Just one enter function (type).
 
union {
}; 
 This state machine's function to leave it. More...
 
union {
}; 
 This state machine's trigger respectively check function. More...
 
genStateText_t doGenStateText
 This state machine's function for status text generation. More...
 
uint32_t endTime
 The end time of a state or sub-state. More...
 
char infoTxt [36]
 state infotext (provided by application SW)
 
char const name [22]
 State machine name. More...
 
uint8_t offChainEnd
 Length of OFF chain. More...
 
uint8_t onChainEnd
 Length of ON chain. More...
 
onStateChange_t const onStateChange
 This state machine's callback function for state changes. More...
 
uint32_t realSecOff
 s time stamp of last exit transition
 
uint32_t realSecOn
 s time stamp of last enter transition
 
uint8_t status
 Status number. More...
 
uint8_t subStatus
 Addendum to status for more complicated state machines. More...
 
float threshBadLo
 The bad Hi limit. More...
 
float threshCritLo
 The critical Lo limit.
 
float threshOFF
 The lower or OFF threshold. More...
 
float threshON
 The higher or ON threshold. More...
 
uint8_t const typ
 State machine type. More...
 

Detailed Description

The structure for state machines.

Field Documentation

◆ name

char const name[22]

State machine name.

The names must be unique within one application and best also within a site as it usually will appear in logs as the only identifier of a state machine.

The maximum length is 20. It is recommended to have all state names the same length (e.g. 12) in an application if feasible. This gives better readability of state machine logs (see logStateText()).

◆ typ

uint8_t const typ

State machine type.

As of Revision 193 the following types are defined and recognised by genStateText() respectively logStateText(): /code 0xAD: Timer, seconds resolution, UTC stamp 0xDB: switch de-Bounce 0xFF: Float value hysteresis 0x5B: 5 band check ...badLO | critLo | OK | critHi | badHi... 0xFC: sequential Control (SFC) /endcode

◆ onChainEnd

uint8_t onChainEnd

Length of ON chain.

With SFCs this (or greater) substatus value in ON chain will lead to the stable (1:0) ON state. This value must be set at SFC construction and should not be changed hence on.
A value of, e.g., 4 would produce an on chain (0:1)->(0:2)->(0:3)=>(1:0) when not changed in a onStateChange function.

With switch de-bounce it is the up-counter level to recognise ON.

Other state machines defined so far don't use this member variable.

◆ offChainEnd

uint8_t offChainEnd

Length of OFF chain.

With SFCs this (or greater) substatus value in OFF chain will lead to the stable (0:0) OFF state. This value must be set at SFC construction and should not be changed hence on.
A value of, e.g., 3 would produce an off chain (0:1)->(1:2)=>(0:0) when not changed in a onStateChange function.

With switch de-bounce it is the down-counter start value to recognise OFF.

Other state machines defined so far don't use this member variable.

◆ doEnter

enterState_t const doEnter

This state machine's function to enter it.

The fitting function to enter this state, respectively to start its transition from OFF to ON might be recorded in and then called via this function pointer.

◆ 

union { ... } @6

This state machine's function to leave it.

The fitting function to leave this state, respectively to start its transition from ON to OFF might be recorded in and then called via this function pointer.

◆ 

union { ... } @8

This state machine's trigger respectively check function.

The fitting function to check if a change of state_t.status or state_t.subStatus is due might be recorded in and then called via this function pointer.

◆ onStateChange

onStateChange_t const onStateChange

This state machine's callback function for state changes.

The fitting function to be called on a real change of state_t.status and depending on type also on changes of state_t.subStatus must be recorded in this function pointer. In contrast to the other function pointers in this state_t structure, this pointer should not be NULL.

◆ doGenStateText

genStateText_t doGenStateText

This state machine's function for status text generation.

The default setting will be genStateText().

◆ status

uint8_t status

Status number.

State numbers together with sub state numbers (if applicable) must be unique, and best dense (0..n-1) within a concrete state machine (being in exactly one of n states). Status number 0,0 is reserved for the machine's default / reset state.

State machines with just two (big / first level) states can best be modelled having just one "singleton" state being either On or Off.

timer (AD):
1: (still) running; 0: ended

simple:
0: OFF; else: ON

SFC (FC):
0,0: OFF
0,x: chain to ON
4,x: chain to ON interrupted
1,0: ON
1,x: chain to OFF
5,x: chain to OFF interrupted;

Five band check (5B):
2: bad Hi
1: critical Hi
0: OK (and, hence, here usually ON while 2 and 6 would mean OFF)
5: critical Lo
6: bad Lo
8: unknown / reset
subStatus is used as previous state.

◆ subStatus

uint8_t subStatus

Addendum to status for more complicated state machines.

The semantic of subStatus is machine type dependent. For SFC it is 0: stable; !=0: internal transitions. For five band checker it is just previous state.

◆ endTime

uint32_t endTime

The end time of a state or sub-state.

For timers it's the end time of the ON state.

◆ threshOFF

float threshOFF

The lower or OFF threshold.

For five band check (5B) this is the bad Hi limit.

◆ threshON

float threshON

The higher or ON threshold.

For five band check (5B) this is the critical Hi limit.

◆ threshBadLo

float threshBadLo

The bad Hi limit.


◆ 

union { ... } @12

float and byte values to the state machines disposal.

Convention: start using bytes from above [12 .. 15] and floats from below [0]. instance variables


The documentation for this struct was generated from the following file: