RCOM PROJ
File transfer via serial port
statemachine.h
Go to the documentation of this file.
1 
4 #ifndef SM_HEADER
5 #define SM_HEADER
6 
7 #include "macros.h"
8 #include "logs.h"
9 #include "dcp.h"
10 
11 enum stateMachineType {Supervision, Write, Read}; // Type of State Machine
12 enum stateMachineState {Start, FLAG_RCV, A_RCV, C_RCV, BCC_OK, DONE}; // State of the State Machine
13 
18  unsigned char control; // Control Byte that is suppossed to be received
19  unsigned char address; // Address Byte that is suppossed to be received
22 };
23 
24 struct stateMachineParams state_machine; // Instance of the stateMachineParams struct
25 
34 void stateMachineSetUp(unsigned char control, unsigned char address, enum stateMachineState state, enum stateMachineType type);
43 int stateMachine(unsigned char byte, unsigned char **buf, int *size);
44 
51 int processStart(unsigned char byte);
58 int processFLAG_RCV(unsigned char byte);
65 int processA_RCV(unsigned char byte);
72 int processC_RCV(unsigned char byte);
81 int processBCC_OK(unsigned char byte, unsigned char **buffer, int *buffersize);
82 
83 #endif // PLA_HEADER
84 
TRUE
#define TRUE
Definition: macros.h:41
stateMachineParams::address
unsigned char address
Definition: statemachine.h:19
FALSE
#define FALSE
Definition: macros.h:40
A_RCV
@ A_RCV
Definition: statemachine.h:12
processStart
int processStart(unsigned char byte)
Function to process a byte in case the state is Start.
Definition: statemachine.c:47
stateMachineSetUp
void stateMachineSetUp(unsigned char control, unsigned char address, enum stateMachineState state, enum stateMachineType type)
Function to easily change the State Machine.
Definition: statemachine.c:9
BCC_OK
@ BCC_OK
Definition: statemachine.h:12
Start
@ Start
Definition: statemachine.h:12
log_caution
void log_caution(char *arr)
Outputs a message in yellow.
Definition: logs.c:13
stateMachineParams::type
enum stateMachineType type
Definition: statemachine.h:21
Write
@ Write
Definition: statemachine.h:11
macros.h
T_PROP_DELAY
#define T_PROP_DELAY
Definition: macros.h:17
Read
@ Read
Definition: statemachine.h:11
processFLAG_RCV
int processFLAG_RCV(unsigned char byte)
Function to process a byte in case the state is FLAG_RCV.
Definition: statemachine.c:65
state_machine
struct stateMachineParams state_machine
Definition: statemachine.h:24
DONE
@ DONE
Definition: statemachine.h:12
processC_RCV
int processC_RCV(unsigned char byte)
Function to process a byte in case the state is C_RCV.
Definition: statemachine.c:134
stateMachineParams::control
unsigned char control
Definition: statemachine.h:18
stateMachineParams
List of Parameters to Personalize the State Machine.
Definition: statemachine.h:17
BCC
#define BCC(a, c)
XOR entre a e c.
Definition: macros.h:37
C_I
#define C_I(r)
(0x00 0x40) Campo de Controlo - Tramas I
Definition: macros.h:35
C_RCV
@ C_RCV
Definition: statemachine.h:12
FLAG_RCV
@ FLAG_RCV
Definition: statemachine.h:12
statemachine.h
frameIndex
static int frameIndex
Definition: statemachine.c:7
logs.h
FLAG
#define FLAG
(0x7E) flag de inicio e fim
Definition: macros.h:25
dcp.h
log_error
void log_error(char *arr)
Outputs a message in red.
Definition: logs.c:7
generateErrorBCC2
void generateErrorBCC2(unsigned char *frame, int frameSize)
Generates a error on BCC2 based on PROBABILITY_BCC2.
Definition: dcp_spec.c:328
wrongC
static int wrongC
Definition: statemachine.c:7
generateErrorBCC1
void generateErrorBCC1(unsigned int *checkBuffer)
Generates a error on BCC based on PROBABILITY_BCC2.
Definition: dcp_spec.c:339
stateMachineParams::state
enum stateMachineState state
Definition: statemachine.h:20
C_REJ
#define C_REJ(r)
(0x01 OU 0x81) Campo de Controlo - REJ (reject / negative ACK))
Definition: macros.h:34
processBCC_OK
int processBCC_OK(unsigned char byte, unsigned char **buffer, int *buffersize)
Function to process a byte in case the state is BCC_OK.
Definition: statemachine.c:179
checkBuffer
static unsigned checkBuffer[2]
Definition: statemachine.c:6
Supervision
@ Supervision
Definition: statemachine.h:11
stateMachineState
stateMachineState
Definition: statemachine.h:12
PROBABILITY_BCC1
#define PROBABILITY_BCC1
Definition: macros.h:16
PROBABILITY_BCC2
#define PROBABILITY_BCC2
Definition: macros.h:15
stateMachineType
stateMachineType
Definition: statemachine.h:11
stateMachine
int stateMachine(unsigned char byte, unsigned char **buf, int *size)
The StateMachine function that processes a byte and updates it's state.
Definition: statemachine.c:16
processA_RCV
int processA_RCV(unsigned char byte)
Function to process a byte in case the state is A_RCV.
Definition: statemachine.c:77