-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommand.c
More file actions
88 lines (78 loc) · 1.87 KB
/
Command.c
File metadata and controls
88 lines (78 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "Command.h"
#include "Common.h"
#include "EasyCon_API.h"
/*
void ExeEmptyOp(const uint8_t* data) {return;}
void OpPong(const uint8_t* data);
void TriggerLED(const uint8_t* data);
*/
uint8_t* data_ptr;
const PROGMEM CommandEntryType CommandTable[] = {
{
.OP = CMD_READY,
.CmdDataLength = 0,
.ExeFunc = ExeEmptyOp
},
{
.OP = CMD_READY,
.CmdDataLength = 0,
.ExeFunc = OpVersion
},
{
.OP = CMD_HELLO,
.CmdDataLength = 0,
.ExeFunc = OpPong
},
{
.OP = CMD_LED,
.CmdDataLength = 0,
.ExeFunc = TriggerLED
}
};
void OpPong(const uint8_t* data) {
SerialSend(REPLY_HELLO);
}
void TriggerLED(const uint8_t* data) {
_ledflag ^= 0x8;
// there is no end , for flash one byte force
EasyCon_write_start(1);
EasyCon_write_data(LED_SETTING, (uint8_t *)&_ledflag, 1);
EasyCon_write_end(1);
EasyCon_runningLED_off();
EasyCon_serial_send(_ledflag);
}
static void CallCommandFunc(const CommandEntryType* CommandEntry) {
CmdActionFuncType ExeFunc = pgm_read_ptr(&CommandEntry->ExeFunc);
ExeFunc(data_ptr);
}
static void cmd_dispatch(uint8_t OPCODE, const uint8_t* data, uint8_t len) {
uint8_t i;
bool CommandFound = false;
for (i = 0; i < ARRAY_COUNT(CommandTable); i++) {
if (OPCODE == pgm_read_byte(&CommandTable[i].OP)) {
CommandFound = true;
data_ptr = data;
if(len == pgm_read_byte(&CommandTable[i].CmdDataLength)) {
CallCommandFunc(&CommandTable[i]);
BlinkLED();
}else {
SerialSend(RLY_ERR);
}
break;
}
}
if (! CommandFound) {
SerialSend(RLY_ERR);
return;
}
data_ptr = NULL;
}
static void cmd_senderr(CommandError_t errType, uint8_t arg1, uint8_t arg2)
{
SerialSend(REPLY_ERROR);
}
void SerialSend(uint8_t b)
{
Serial_SendByte(b);
BlinkLED();
}