-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuan-handle.cpp
97 lines (88 loc) · 1.82 KB
/
uan-handle.cpp
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
97
#include <iostream>
#include <fstream>
#include <list>
#include <string.h>
#include "uan-variable.h"
#include "uan-class.h"
#include "uan-app.h"
#include "uan-mac.h"
using namespace std;
void ToMAC(InitPkt init)
{
MAC_DataSend(init);
}
void ToMAC(StatePkt state)
{
MAC_DataSend(state);
}
void HandleRou(char input[])
{
switch (input[0])
{
case 1: //初始化报文
{
InitPkt initpkt; // 为了代码可读性,先复原报文,再建立路由
initpkt.seqNum = input[1];
initpkt.srcID = input[2];
initpkt.Depth = uint16((input[3] << 8) + input[4]);
if(m_Depth < initpkt.Depth){
ChildIDBuff.push_back(initpkt.srcID);
}
else{
ParentIDBuff.push_back(initpkt.srcID);
}
}break;
case 2: //状态报文
{
StatePkt statePkt;
statePkt.seqNum = input[1];
statePkt.srcID = input[2];
statePkt.bandwidth = input[3];
statePkt.connect = input[4];
statePkt.Depth = uint16(input[5] << 8 & input[6]);
if(m_Depth < statePkt.Depth){
ChildIDBuff.push_back(statePkt.srcID);
}
else{
ParentIDBuff.push_back(statePkt.srcID);
State S;
S.id = statePkt.srcID;
S.bandwidth = statePkt.bandwidth;
S.connect = statePkt.connect;
QstateVector.push_back(S);
}
}break;
default:
break;
}
}
void SetFlie()
{
fstream outfile;
outfile.open("MACResult.txt", ios::in | ios::out | ios::app);
outfile.width(6);
outfile.flags(ios::right);
outfile << "flag";
outfile.width(6);
outfile.flags(ios::right);
outfile << "Time";
outfile.width(6);
outfile.flags(ios::right);
outfile<< "Seq ";
outfile.width(6);
outfile.flags(ios::right);
outfile<< "Result" << endl;
outfile.close();
}
void InitSys()
{
SetFlie();
InitPkt pkt;
pkt.seqNum = stateSeqNum;
pkt.srcID = m_ID;
pkt.Depth = m_Depth;
ToMAC(pkt);
stateSeqNum ++;
// ScheduleState();
// ScheduleData();
}