-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkProtocol.cpp
41 lines (36 loc) · 1.84 KB
/
NetworkProtocol.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
#include "NetworkProtocol.hpp"
int CNetworkProtocol::SendKnowledgeBase () {
for (int i=0;i<4;i++) {
g_pNetwork->CreatePackage (Check (*(g_pKnowledgeBase->GetOdometryTicksSinceLastUpdate()+i), 1)); //Odometry Ticks (4 ints)
}
for (int i=0;i<271;i++) {
g_pNetwork->CreatePackage (Check (*(g_pKnowledgeBase->GetScannerData()+i), 2)); //Scanner data (271 ints)
}
for (int i=0;i<4;i++) {
g_pNetwork->CreatePackage (Check (*(g_pKnowledgeBase->GetCurrentMotorPower()+i), 3)); //Motor Power (4 ints)
}
g_pNetwork->CreatePackage (Check ((g_pKnowledgeBase->GetCalculatedDrivingDirection()+90)*100, 4)); //Calculated direction * 100 (1 int)
g_pNetwork->CreatePackage (Check ((g_pKnowledgeBase->GetTargetDrivingDirection()+90)*100, 5)); //Target direction * 100 (1 int)
g_pNetwork->CreatePackage (Check ((g_pKnowledgeBase->GetCurrentBatteryVoltage()*100), 6)); //operating voltage * 100 (1 int)
g_pNetwork->CreatePackage (Check (g_pKnowledgeBase->GetMainLoopTicksPerSecond()/10000, 7)); //loop ticks /10000 (1 int)
g_pNetwork->CreatePackage (Check (g_pKnowledgeBase->OdometryPosition()->fX+15000, 8)); //X + 15000 Pos (1 int)
g_pNetwork->CreatePackage (Check (g_pKnowledgeBase->OdometryPosition()->fY+15000, 9)); //Y + 15000 Pos (1 int)
g_pNetwork->CreatePackage (Check ((g_pKnowledgeBase->OdometryPosition()->fTheta+10)*1000, 10)); //(Theta +10) * 1000 (1 int)
return (g_pNetwork->Send ());
}
uint16_t CNetworkProtocol::Check (float fNumber, int nError) {
if ((fNumber < 0)||(fNumber > 65536)) {
std::cout << "Network parameter error! " << nError << std::endl;
return 0;
}else{
return static_cast <uint16_t> (fNumber);
}
}
uint16_t CNetworkProtocol::Check (int nNumber, int nError) {
if ((nNumber < 0)||(nNumber > 65536)) {
std::cout << "Network parameter error! " << nError << std::endl;
return 0;
}else{
return static_cast <uint16_t> (nNumber);
}
}