sq9p-wspaker/utils/paker_test.cpp

70 wiersze
2.1 KiB
C++
Czysty Zwykły widok Historia

2023-09-30 01:45:07 +00:00
#include <cstdint>
2023-10-02 18:21:58 +00:00
#define __packed __attribute__((packed))
2023-09-30 01:45:07 +00:00
#include "../paker.hpp"
#include <iostream>
#include <string>
2023-11-29 21:42:43 +00:00
#include <iomanip>
#include "telemetry.hpp"
2023-09-30 01:45:07 +00:00
using namespace std;
using namespace Protocol::Paker;
2023-11-29 22:11:11 +00:00
static int i32TestNr = 0;
template<class Factory, class CTestData>
void Test(Factory& PacketFactory, CTestData& RawFrame)
2023-09-30 01:45:07 +00:00
{
2023-10-07 17:12:10 +00:00
auto const FtFramesCnt = PacketFactory.EncodeRaw((unsigned char *)&RawFrame, sizeof(RawFrame) * 8);
2023-11-29 22:11:11 +00:00
cout << "\nSQ9P paker TEST NR: " << i32TestNr++ << endl;
2023-12-01 23:38:21 +00:00
cout << "paker format: " << Factory::Format::GetPattern() << endl;
cout << "frame permutations: " << Factory::Format::GetMaxPermutations() << endl;
cout << "frame bitsize floor: " << Factory::Format::GetBitSizeFloor() << endl;
2023-10-02 18:21:58 +00:00
cout << "specific base: ";
;
2023-12-01 23:38:21 +00:00
const char *pattern = Factory::Format::GetPattern();
2023-10-02 18:21:58 +00:00
for (int i = 0; i < strlen(pattern); i++)
{
2023-12-01 23:38:21 +00:00
cout << pattern[i] << "=" << Factory::Format::GetBase(pattern[i]) << " ";
2023-10-02 18:21:58 +00:00
}
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]);
}
2023-12-01 23:38:21 +00:00
cout << std::dec << endl;
2023-09-30 01:45:07 +00:00
}
2023-11-29 22:11:11 +00:00
int main()
{
TPositionFrame RawFrame;
for(int i = 0; i < sizeof(RawFrame); i++)
((unsigned char*)&RawFrame)[i] = i*4 + 31;
CWsprPacketFactory WsprPacketFactory;
CFT4PacketFactory Ft4PacketFactory;
2023-12-01 23:38:21 +00:00
CJt9PacketFactory Jt9PacketFactory;
2023-11-29 22:11:11 +00:00
Test(WsprPacketFactory, RawFrame);
2023-12-01 23:38:21 +00:00
Test(Ft4PacketFactory, RawFrame);
Test(Jt9PacketFactory, RawFrame);
2023-11-29 22:11:11 +00:00
}