-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.c
executable file
·94 lines (82 loc) · 2.94 KB
/
protocol.c
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
//------------------------------------------------------------------------------
/**
* @file protocol.c
* @author charles-park ([email protected])
* @brief ODROID-M1S JIG Client App.
* @version 0.2
* @date 2023-10-23
*
* @package apt install iperf3, nmap, ethtool, usbutils, alsa-utils
*
* @copyright Copyright (c) 2022
*
*/
//------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <getopt.h>
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/* protocol control 함수 */
#include "protocol.h"
//------------------------------------------------------------------------------
//
// https://docs.google.com/spreadsheets/d/1igBObU7CnP6FRaRt-x46l5R77-8uAKEskkhthnFwtpY/edit?gid=2036366963#gid=2036366963
//
//------------------------------------------------------------------------------
int protocol_check (ptc_var_t *var)
{
/* head & tail check with protocol size */
if(var->buf[(var->p_sp + var->size -1) % var->size] != '#') return 0;
if(var->buf[(var->p_sp ) % var->size] != '@') return 0;
return 1;
}
//------------------------------------------------------------------------------
int protocol_catch (ptc_var_t *var)
{
char cmd = var->buf[(var->p_sp + 2) % var->size];
switch (cmd) {
case 'B': case 'R':
case 'A': case 'O': case 'C':
case 'E': case 'X':
return 1;
default :
printf ("unknown command %c\n", cmd);
return 0;
}
}
//------------------------------------------------------------------------------
void protocol_msg_tx (uart_t *puart, void *tx_msg)
{
if (puart == NULL) return;
uart_write (puart, tx_msg, (int)strlen(tx_msg));
printf ("%s : size = %d, data = %s\n", __func__, (int)strlen(tx_msg), (char *)tx_msg);
}
//------------------------------------------------------------------------------
int protocol_msg_rx (uart_t *puart, char *rx_msg)
{
unsigned char idata, p_cnt;
if (puart == NULL) return 0;
/* uart data processing */
if (uart_read (puart, &idata, 1)) {
ptc_event (puart, idata);
for (p_cnt = 0; p_cnt < puart->pcnt; p_cnt++) {
if (puart->p[p_cnt].var.pass) {
ptc_var_t *var = &puart->p[p_cnt].var;
int i;
puart->p[p_cnt].var.pass = 0;
puart->p[p_cnt].var.open = 1;
for (i = 0; i < (int)var->size; i++)
// uuid start position is 2
rx_msg [i] = var->buf[(var->p_sp + i) % var->size];
return 1;
}
}
}
return 0;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------