Working towards a test tool

This commit is contained in:
Karlis Goba 2018-11-01 16:21:40 +02:00
parent a4992b068e
commit 81bcc70286
4 changed files with 177 additions and 98 deletions

View file

@ -3,3 +3,12 @@ LDFLAGS = -lm
gen_ft8: gen_ft8.o encode.o pack.o text.o pack_77.o encode_91.o gen_ft8: gen_ft8.o encode.o pack.o text.o pack_77.o encode_91.o
$(CXX) $(LDFLAGS) -o $@ $^ $(CXX) $(LDFLAGS) -o $@ $^
.PHONY: run_tests
run_tests: test
@./test
test: test.o encode.o pack.o text.o pack_77.o encode_91.o unpack.o
$(CXX) $(LDFLAGS) -o $@ $^

View file

@ -10,33 +10,6 @@
#include "encode_91.h" #include "encode_91.h"
void convert_8bit_to_6bit(uint8_t *dst, const uint8_t *src, int nBits) {
// Zero-fill the destination array as we will only be setting bits later
for (int j = 0; j < (nBits + 5) / 6; ++j) {
dst[j] = 0;
}
// Set the relevant bits
uint8_t mask_src = (1 << 7);
uint8_t mask_dst = (1 << 5);
for (int i = 0, j = 0; nBits > 0; --nBits) {
if (src[i] & mask_src) {
dst[j] |= mask_dst;
}
mask_src >>= 1;
if (mask_src == 0) {
mask_src = (1 << 7);
++i;
}
mask_dst >>= 1;
if (mask_dst == 0) {
mask_dst = (1 << 5);
++j;
}
}
}
void synth_fsk(const uint8_t *symbols, int nSymbols, float f0, float spacing, float symbol_rate, float signal_rate, float *signal) { void synth_fsk(const uint8_t *symbols, int nSymbols, float f0, float spacing, float symbol_rate, float signal_rate, float *signal) {
float phase = 0; float phase = 0;
float dt = 1/signal_rate; float dt = 1/signal_rate;
@ -110,47 +83,6 @@ void save_wav(const float *signal, int num_samples, int sample_rate, const char
} }
void test1() {
//const char *test_in3 = "CQ DL7ACA JO40"; // 62, 32, 32, 49, 37, 27, 59, 2, 30, 19, 49, 16
//const char *test_in3 = "VA3UG F1HMR 73"; // 52, 54, 60, 12, 55, 54, 7, 19, 2, 23, 59, 16
const char *test_in3 = "RA3Y VE3NLS 73"; // 46, 6, 32, 22, 55, 20, 11, 32, 53, 23, 59, 16
uint8_t test_out3[9];
int rc = packmsg(test_in3, test_out3);
printf("RC = %d\n", rc);
for (int i = 0; i < 9; ++i) {
printf("%02x ", test_out3[i]);
}
printf("\n");
uint8_t test_out4[12];
convert_8bit_to_6bit(test_out4, test_out3, 72);
for (int i = 0; i < 12; ++i) {
printf("%d ", test_out4[i]);
}
printf("\n");
}
void test2() {
uint8_t test_in[11] = { 0xF1, 0x02, 0x03, 0x04, 0x05, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xFF };
uint8_t test_out[22];
encode174(test_in, test_out);
for (int j = 0; j < 22; ++j) {
printf("%02x ", test_out[j]);
}
printf("\n");
}
void test3() {
uint8_t test_in2[10] = { 0x11, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x10, 0x04, 0x01, 0x00 };
uint16_t crc1 = ft8_crc(test_in2, 76); // Calculate CRC of 76 bits only
printf("CRC: %04x\n", crc1); // should be 0x0708
}
void usage() { void usage() {
printf("Generate a 15-second WAV file encoding a given message.\n"); printf("Generate a 15-second WAV file encoding a given message.\n");
printf("Usage:\n"); printf("Usage:\n");

136
test.cpp Normal file
View file

@ -0,0 +1,136 @@
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include "text.h"
#include "pack.h"
#include "encode.h"
#include "unpack.h"
#include "pack_77.h"
#include "encode_91.h"
#define LOG_LEVEL LOG_INFO
#define LOG_INFO 0
#define LOG_WARN 1
#define LOG_ERROR 2
#define LOG_FATAL 3
#define LOG(level, ...) if (level >= LOG_LEVEL) printf(__VA_ARGS__)
void convert_8bit_to_6bit(uint8_t *dst, const uint8_t *src, int nBits) {
// Zero-fill the destination array as we will only be setting bits later
for (int j = 0; j < (nBits + 5) / 6; ++j) {
dst[j] = 0;
}
// Set the relevant bits
uint8_t mask_src = (1 << 7);
uint8_t mask_dst = (1 << 5);
for (int i = 0, j = 0; nBits > 0; --nBits) {
if (src[i] & mask_src) {
dst[j] |= mask_dst;
}
mask_src >>= 1;
if (mask_src == 0) {
mask_src = (1 << 7);
++i;
}
mask_dst >>= 1;
if (mask_dst == 0) {
mask_dst = (1 << 5);
++j;
}
}
}
class TestCase {
public:
TestCase(const std::string &name) : _name(name) {
//_all_cases.push_back(this);
}
virtual bool run(const std::string &params) = 0;
private:
std::string _name;
//static std::vector<TestCase *> _all_cases;
};
//std::vector<TestCase *> TestCase::_all_cases;
class TestCase1 : public TestCase {
public:
TestCase1() : TestCase("Test Case 1") {}
bool run(const std::string &params) override {
return true;
}
};
bool test1() {
//const char *msg = "CQ DL7ACA JO40"; // 62, 32, 32, 49, 37, 27, 59, 2, 30, 19, 49, 16
const char *msg = "VA3UG F1HMR 73"; // 52, 54, 60, 12, 55, 54, 7, 19, 2, 23, 59, 16
//const char *msg = "RA3Y VE3NLS 73"; // 46, 6, 32, 22, 55, 20, 11, 32, 53, 23, 59, 16
uint8_t a72[9];
int rc = packmsg(msg, a72);
if (rc < 0) return false;
LOG(LOG_INFO, "8-bit packed: ");
for (int i = 0; i < 9; ++i) {
LOG(LOG_INFO, "%02x ", a72[i]);
}
LOG(LOG_INFO, "\n");
uint8_t a72_6bit[12];
convert_8bit_to_6bit(a72_6bit, a72, 72);
LOG(LOG_INFO, "6-bit packed: ");
for (int i = 0; i < 12; ++i) {
LOG(LOG_INFO, "%d ", a72_6bit[i]);
}
LOG(LOG_INFO, "\n");
char msg_out_raw[14];
unpack(a72, msg_out_raw);
char msg_out[14];
fmtmsg(msg_out, msg_out_raw);
LOG(LOG_INFO, "msg_out = [%s]\n", msg_out);
return true;
}
void test2() {
uint8_t test_in[11] = { 0xF1, 0x02, 0x03, 0x04, 0x05, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xFF };
uint8_t test_out[22];
encode174(test_in, test_out);
for (int j = 0; j < 22; ++j) {
printf("%02x ", test_out[j]);
}
printf("\n");
}
void test3() {
uint8_t test_in2[10] = { 0x11, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x10, 0x04, 0x01, 0x00 };
uint16_t crc1 = ft8_crc(test_in2, 76); // Calculate CRC of 76 bits only
printf("CRC: %04x\n", crc1); // should be 0x0708
}
int main() {
test1();
return 0;
}

View file

@ -42,40 +42,42 @@ void unpackcall(uint32_t nc, char *callsign) {
// extract maidenhead locator // extract maidenhead locator
void unpackgrid(uint32_t ng, char *grid) { void unpackgrid(uint32_t ng, char *grid) {
// start of special grid locators for sig strength &c. // // start of special grid locators for sig strength &c.
NGBASE = 180*180 // NGBASE = 180*180
if ng == NGBASE+1: // if ng == NGBASE+1:
return " " // return " "
if ng >= NGBASE+1 and ng < NGBASE+31: // if ng >= NGBASE+1 and ng < NGBASE+31:
return " -%02d" % (ng - (NGBASE+1)) // sig str, -01 to -30 DB // return " -%02d" % (ng - (NGBASE+1)) // sig str, -01 to -30 DB
if ng >= NGBASE+31 and ng < NGBASE+62: // if ng >= NGBASE+31 and ng < NGBASE+62:
return "R-%02d" % (ng - (NGBASE+31)) // return "R-%02d" % (ng - (NGBASE+31))
if ng == NGBASE+62: // if ng == NGBASE+62:
return "RO " // return "RO "
if ng == NGBASE+63: // if ng == NGBASE+63:
return "RRR " // return "RRR "
if ng == NGBASE+64: // if ng == NGBASE+64:
return "73 " // return "73 "
lat = (ng % 180) - 90 // lat = (ng % 180) - 90
ng = int(ng / 180) // ng = int(ng / 180)
lng = (ng * 2) - 180 // lng = (ng * 2) - 180
g = "%c%c%c%c" % (ord('A') + int((179-lng)/20), // g = "%c%c%c%c" % (ord('A') + int((179-lng)/20),
ord('A') + int((lat+90)/10), // ord('A') + int((lat+90)/10),
ord('0') + int(((179-lng)%20)/2), // ord('0') + int(((179-lng)%20)/2),
ord('0') + (lat+90)%10) // ord('0') + (lat+90)%10)
if g[0:2] == "KA": // if g[0:2] == "KA":
// really + signal strength // // really + signal strength
sig = int(g[2:4]) - 50 // sig = int(g[2:4]) - 50
return "+%02d" % (sig) // return "+%02d" % (sig)
if g[0:2] == "LA": // if g[0:2] == "LA":
// really R+ signal strength // // really R+ signal strength
sig = int(g[2:4]) - 50 // sig = int(g[2:4]) - 50
return "R+%02d" % (sig) // return "R+%02d" % (sig)
grid[0] = 0;
} }
@ -118,7 +120,7 @@ int unpack(const uint8_t *a72, char *message) {
nc1 |= (a72[2] << 4); nc1 |= (a72[2] << 4);
nc1 |= (a72[3] >> 4); nc1 |= (a72[3] >> 4);
nc2 = (a72[3] << 24); nc2 = ((a72[3] & 0x0F) << 24);
nc2 |= (a72[4] << 16); nc2 |= (a72[4] << 16);
nc2 |= (a72[5] << 8); nc2 |= (a72[5] << 8);
nc2 |= (a72[6]); nc2 |= (a72[6]);