kopia lustrzana https://github.com/piotr022/wspaker
60 wiersze
1.7 KiB
C++
60 wiersze
1.7 KiB
C++
#include <cstdint>
|
|
|
|
#define __packed
|
|
#include "../paker.hpp"
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <iomanip> // Dla std::setw i std::setfill
|
|
|
|
using namespace std;
|
|
using namespace Protocol::Paker;
|
|
|
|
|
|
struct TRawFrame
|
|
{
|
|
int32_t s32Lat;
|
|
int32_t s32Lon;
|
|
uint16_t u16Alt;
|
|
uint8_t u8Course;
|
|
uint8_t u8SomeTelemetry;
|
|
};
|
|
|
|
CFT4PacketFactory PacketFactory;
|
|
int main()
|
|
{
|
|
TRawFrame RawFrame = {-22,-3949211, 9210, 11, 12};
|
|
auto const FtFramesCnt = PacketFactory.EncodeRaw((unsigned char*)&RawFrame, sizeof(TRawFrame)*8);
|
|
cout << "\npaker format: " << CFT4PacketFactory::TFT4Format::GetPattern() << endl;
|
|
cout << "frame permutations: " << CFT4PacketFactory::TFT4Format::GetMaxPermutations() << endl;
|
|
cout << "frame bitsize ffloor: " << CFT4PacketFactory::TFT4Format::GetBitSizeFloor() << endl;
|
|
cout << "specific base: ";;
|
|
|
|
const char* pattern = CFT4PacketFactory::TFT4Format::GetPattern();
|
|
for(int i = 0; i < strlen(pattern); i++)
|
|
{
|
|
cout << pattern[i] << "=" << CFT4PacketFactory::TFT4Format::GetBase(pattern[i]) << " ";
|
|
}
|
|
cout << endl << endl;
|
|
|
|
cout << "test raw data: ";
|
|
|
|
for(int i = 0; i < sizeof(RawFrame); ++i) {
|
|
std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(((unsigned char*)&RawFrame)[i]);
|
|
}
|
|
|
|
cout << "\n\nencoded output: \n";
|
|
for(unsigned int i = 0; i < FtFramesCnt; i++)
|
|
{
|
|
cout << "frame [" << i << "]: " << PacketFactory.GetPacket(i) << endl;
|
|
}
|
|
|
|
cout << "\ndecoded back to: ";
|
|
unsigned char C8Dupa[sizeof(RawFrame) + 4] = {0};
|
|
PacketFactory.DecodeFrames(FtFramesCnt, C8Dupa, sizeof(C8Dupa));
|
|
for(int i = 0; i < sizeof(RawFrame); ++i) {
|
|
std::cout << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(((unsigned char*)C8Dupa)[i]);
|
|
}
|
|
|
|
cout << endl;
|
|
}
|