-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcom.c
executable file
·91 lines (75 loc) · 2.15 KB
/
com.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
/* ========================================
* Author: Jeremy Crowley
* File: com.c
*
* Purpose: This file provides the functions for UART communication
* ========================================
*/
#include "com.h"
#define ASCI_DIFF 48
#define TENS 10
void BuildSendPacket(uint8_t packet[SEND_SIZE], uint8_t seg, uint8_t pass, uint8_t rowHigh, uint8_t rowLow, uint8_t colHigh, uint8_t colLow)
{
packet[0] = 'd';
packet[1] = 'a';
packet[2] = 't';
packet[3] = 'a';
packet[4] = ' ';
packet[5] = 0x55;
packet[6] = 0xaa;
packet[7] = 'J'; //0x4A;
packet[8] = 'e'; //0x65;
packet[9] = 'r'; //0x72;
packet[10] = 'e'; //0x65;
packet[11] = 'm'; //0x6D;
packet[12] = 'y'; //0x79;
packet[13] = 0x20;
packet[14] = Hundreds(seg) + ASCI_DIFF;
packet[15] = Tens(seg, packet[9]) + ASCI_DIFF;
packet[16] = Ones(seg, packet[9], packet[10]) + ASCI_DIFF;
packet[17] = pass + ASCI_DIFF;
packet[18] = rowHigh + ASCI_DIFF;
packet[19] = rowLow + ASCI_DIFF;
packet[20] = colHigh + ASCI_DIFF;
packet[21] = colLow + ASCI_DIFF;
packet[22] = '\n';
}
void ParsePacket(uint8_t packet[SEND_SIZE - 3], int idEnd)
{
receiveData.pass = packet[idEnd+6]-ASCI_DIFF;
receiveData.row = (TENS*(packet[idEnd+7]-ASCI_DIFF)+(packet[idEnd+8]-ASCI_DIFF));
receiveData.col = (TENS*(packet[idEnd+9]-ASCI_DIFF)+(packet[idEnd+10]-ASCI_DIFF));
if(receiveData.row != 0)
{
receiveData.row -= 1;
}
if(receiveData.col != 0)
{
receiveData.col -= 1;
}
}
uint8_t Hundreds(uint8_t num)
{
return (num/100);
}
uint8_t Tens(uint8_t num, uint8_t hundreds)
{
return (num%(100*hundreds))/10;
}
uint8_t Ones(uint8_t num, uint8_t hundreds, uint8_t tens)
{
return (num%((100*hundreds) + (10*tens)));
}
bool newData(uint8_t currentSeq)
{
// make sure that the sequence num recieve is one more that the last
if(currentSeq == (receiveData.seq + 1))
{
return true;
}
else
{
return false;
}
}
/* [] END OF FILE */