74 lines
1.6 KiB
C++
74 lines
1.6 KiB
C++
#include "DataToSend.h"
|
|
//---------------------------------------------------------------------------
|
|
int DataToSend::uid = 0;
|
|
//---------------------------------------------------------------------------
|
|
//Ïîñ÷èòàòü CRC è çàïèñàòü â ïîñëåäíèé áàéò
|
|
void DataToSend::calcCRC()
|
|
{
|
|
mas[len - 1] = 0x00;
|
|
for (int i = 0; i < len - 1; i++) {
|
|
mas[len - 1] = mas[len - 1] ^ mas[i];
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
//Äîáàâèòü ñòðîêîâûé òåã â ìàññèâ
|
|
int DataToSend::addStringTag(int tag, std::string data) {
|
|
if (tag < 255) {
|
|
mas[pos] = tag;
|
|
pos++;
|
|
}else {
|
|
mas[pos] = ((char*)&tag)[0];
|
|
pos++;
|
|
mas[pos] = ((char*)&tag)[1];
|
|
pos++;
|
|
}
|
|
mas[pos] = data.length();
|
|
pos++;
|
|
|
|
for (int i = 0; i < data.length(); i++) {
|
|
mas[pos] = data[i];
|
|
pos++;
|
|
}
|
|
return pos;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
int DataToSend::addUIntTag(int tag, unsigned int data) {
|
|
if (tag < 255) {
|
|
mas[pos] = tag;
|
|
pos++;
|
|
}
|
|
else {
|
|
mas[pos] = ((char*)&tag)[1];
|
|
pos++;
|
|
mas[pos] = ((char*)&tag)[0];
|
|
pos++;
|
|
}
|
|
mas[pos] = 4;
|
|
pos++;
|
|
|
|
mas[pos] = ((char*)&data)[3];
|
|
pos++;
|
|
mas[pos] = ((char*)&data)[2];
|
|
pos++;
|
|
mas[pos] = ((char*)&data)[1];
|
|
pos++;
|
|
mas[pos] = ((char*)&data)[0];
|
|
pos++;
|
|
|
|
return pos;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
int DataToSend::addChar(char ch) {
|
|
mas[pos] = ch;
|
|
pos++;
|
|
|
|
return pos;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
int DataToSend::addUChar(unsigned char ch) {
|
|
mas[pos] = ch;
|
|
pos++;
|
|
|
|
return pos;
|
|
}
|
|
//---------------------------------------------------------------------------
|