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
89
90
91
92
93
94
95
96
| #define Max_Pins 32
#define Uart_Buffer_Size 8
#define Mmc_Card_Buffer_Size 2048
typedef struct {
unsigned char pin_states[Max_Pins];
unsigned char hours[Max_Pins];
unsigned char minutes[Max_Pins];
unsigned char seconds[Max_Pins];
unsigned int milli_seconds[Max_Pins];
long milli_seconds_delay_counter[Max_Pins];
long milli_seconds_delay_count[Max_Pins];
unsigned task_completed[Max_Pins];
char pin_state[Max_Pins];
unsigned char fileName[3][20];
char messages[10][64];
char txt[3][32];
char buf[96];
char buffer[64];
char usart_receive_state_counter;
unsigned char usart_buffer[Uart_Buffer_Size];
unsigned int usart_buffer_index;
unsigned char extracted_data[80][26];
unsigned char str_direction[80][7];
unsigned char str_port[80][2];
unsigned char str_pin[80][2];
unsigned char str_pin_state[80][2];
unsigned char str_hours[80][3];
unsigned char str_minutes[80][3];
unsigned char str_seconds[80][3];
unsigned char str_milli_seconds[80][4];
}PORT_CONTROL_TYPE;
PORT_CONTROL_TYPE my_port_control;
char instr[] = "OUTPUT,A,1,0,02,01,00,00\rOUTPUT,A,1,0,02,01,00,00\rOUTPUT,A,1,0,02,01,00,00\r";
void splitstr_a(unsigned char *_inbuf, unsigned char _outbuf[][26], char *_delim) {
unsigned char *token = 0;
int idx = 0;
unsigned char _tmpbuf[128];
strcpy(_tmpbuf, _inbuf);
token = strtok(_tmpbuf, _delim);
while(token != 0) {
sprintf(_outbuf[idx], "%s", token);
token = strtok(0, _delim);
#ifdef DEBUG
UART1_Write_Text(_outbuf[idx]);
UART1_Write(CR);
#endif
idx++;
}
}
void splitstr_b(unsigned char _inbuf[][26], PORT_CONTROL_TYPE *pct , char *_delim) {
char *token = 0;
int idx = 0;
unsigned char _tmpbuf[80][26];
while(_inbuf[idx][0]) {
strcpy(_tmpbuf[idx], _inbuf[idx]);
idx++;
}
idx = 0;
token = strtok(_tmpbuf[idx], _delim);
while((token != 0) && (_tmpbuf[idx][0])) {
sprintf(pct->str_direction[idx], "%s", token);
token = strtok(0, _delim);
sprintf(pct->str_port[idx], "%s", token);
token = strtok(0, _delim);
sprintf(pct->str_pin[idx], "%s", token);
token = strtok(0, _delim);
sprintf(pct->str_pin_state[idx], "%s", token);
token = strtok(0, _delim);
sprintf(pct->str_hours[idx], "%s", token);
token = strtok(0, _delim);
sprintf(pct->str_minutes[idx], "%s", token);
token = strtok(0, _delim);
sprintf(pct->str_seconds[idx], "%s", token);
token = strtok(0, _delim);
sprintf(pct->str_milli_seconds[idx], "%s", token);
idx++;
token = strtok(_tmpbuf[idx], _delim);
}
}
//usage
splitstr_a(&instr, &my_port_control.extracted_data[0], "\r");
splitstr_b(&my_port_control.extracted_data[0], &my_port_control, ","); |