-
Notifications
You must be signed in to change notification settings - Fork 1
/
pb_package.c
executable file
·77 lines (65 loc) · 1.37 KB
/
pb_package.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
//******************************************
// This is a C Template file
//×÷Õߣº
//ÈÕÆÚ
//¹¦ÄÜ
//±¸×¢
//******************************************
#include "MQ6812.h"
#include "iApp.h"
#include "FlashFunction.h"
#include "pb_package.h"
#include "uart_data.h"
extern uchar rx_data[8];
extern uchar tx_data[8];
extern uchar dev0_id[4];
extern uchar pb_waiting_response_flag;
struct PB_MSG pb_sent_msg1, pb_sent_msg2;
struct PB_MSG pb_rec_msg1, pb_rec_msg2;
void Message_To_Buffer(struct PB_MSG m)
{
uchar i;
uchar buff_temp[8]={0};
buff_temp[1] = m.msg_dir;
buff_temp[2] = m.msg_role;
buff_temp[3] = m.msg_type;
for(i=0; i<4; i++)
{
buff_temp[i+4] =m.msg_data[i];
}
for(i=1; i<8; i++)
tx_data[i] = buff_temp[i];
}
uchar Buffer_To_Message(void)
{
uchar i, decode_result =0 ;
pb_rec_msg1.msg_dir = rx_data[1] ;
pb_rec_msg1.msg_role = rx_data[2];
pb_rec_msg1.msg_type= rx_data[3];
for(i=0; i<4; i++)
{
pb_rec_msg1.msg_data[i] = rx_data[i+4];
}
}
uchar PB_Protocol_Compare_Device_ID(uchar* id)
{
uchar dev1_id[4] = {0} ;
uchar i , res;
for (i=0; i<4; i++ )
{
dev1_id[i] = id[i+1];
}
Get_Device_ID();
if(dev1_id[0]<dev0_id[0])
{
res = 2; // slave
}
else
{
res = 1; // master
}
}
void Get_Device_ID(void)
{
FlashReadSequence(0x7e43, dev0_id, 4);
}