-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsupmessage.cpp
80 lines (65 loc) · 2.22 KB
/
supmessage.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
#include "supmessage.h"
#include <arpa/inet.h>
#include <iostream>
uint8_t SupMessage::getSlotId() const {
return this->buffer[9];
}
uint8_t SupMessage::getChemistry() const {
return this->buffer[10];
}
uint8_t SupMessage::getProgram() const {
return this->buffer[11];
}
uint8_t SupMessage::getMaxCharge() const {
return this->buffer[12];
}
uint8_t SupMessage::getDischargeRate() const {
return this->buffer[13];
}
uint16_t SupMessage::getCapacity() const {
uint16_t temp = 0;
memcpy(&temp, &this->buffer[14], 2);
return htons(temp);
}
uint8_t SupMessage::getSdCardStatus() const {
return this->buffer[16];
}
uint8_t SupMessage::getCoolMinutes() const {
return this->buffer[17];
}
uint8_t SupMessage::getSdSlotStatus() const {
return this->buffer[21];
}
uint16_t SupMessage::getCrc() const {
uint16_t temp = 0;
memcpy(&temp, &this->buffer[33], 2);
return temp;
}
void SupMessage::print() const {
std::cout << "unknown bytes: ";
for(int i=0; i<9; i++) {
printf("%02x ", (unsigned char)this->buffer[i]);
}
std::cout << std::endl;
std::cout << "slotId : " << (unsigned)getSlotId() << std::endl;
std::cout << "chemistry: " << (unsigned)getChemistry() << std::endl;
std::cout << "program : " << (unsigned)getProgram() << std::endl;
std::cout << "max charge: " << (unsigned)getMaxCharge() << std::endl;
std::cout << "discharge rate: " << (unsigned)getDischargeRate() << std::endl;
std::cout << "capacity: " << (unsigned)getCapacity() << std::endl;
std::cout << "sd card status: " << (unsigned)getSdCardStatus() << std::endl;
std::cout << "cool minutes: " << (unsigned)getCoolMinutes() << std::endl;
std::cout << "padding: ";
for(int i=18; i<21; i++) {
printf("%02x ", (unsigned char)this->buffer[i]);
}
std::cout << std::endl;
std::cout << "sd slot status: " << (unsigned)getSdSlotStatus() << std::endl;
std::cout << "unknown bytes: ";
for(int i=22; i<33; i++) {
printf("%02x ", (unsigned char)this->buffer[i]);
}
std::cout << std::endl;
std::cout << "crc: " << std::hex << this->getCrc() << std::dec << std::endl;
std::cout << std::endl;
}