Minor changes; more comments

This commit is contained in:
Karlis Goba 2018-11-02 09:55:54 +02:00
parent 81bcc70286
commit b9c40886ca
4 changed files with 70 additions and 76 deletions

12
debug.h Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <stdio.h>
#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__)

View file

@ -10,14 +10,18 @@
#include "encode_91.h" #include "encode_91.h"
void synth_fsk(const uint8_t *symbols, int nSymbols, float f0, float spacing, float symbol_rate, float signal_rate, float *signal) { // Convert a sequence of symbols (tones) into a sinewave of continuous phase (FSK).
// Symbol 0 gets encoded as a sine of frequency f0, the others are spaced in incresing
// fashion.
void synth_fsk(const uint8_t *symbols, int num_symbols, 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;
float dt_sym = 1/symbol_rate; float dt_sym = 1/symbol_rate;
float t = 0; float t = 0;
int j = 0; int j = 0;
int i = 0; int i = 0;
while (j < nSymbols) { while (j < num_symbols) {
float f = f0 + symbols[j] * spacing; float f = f0 + symbols[j] * spacing;
phase += 2 * M_PI * f / signal_rate; phase += 2 * M_PI * f / signal_rate;
signal[i] = sin(phase); signal[i] = sin(phase);
@ -31,7 +35,7 @@ void synth_fsk(const uint8_t *symbols, int nSymbols, float f0, float spacing, fl
} }
} }
// Save signal in floating point format (-1 .. +1) as a WAVE file using 16-bit signed integers.
void save_wav(const float *signal, int num_samples, int sample_rate, const char *path) { void save_wav(const float *signal, int num_samples, int sample_rate, const char *path) {
FILE *f = fopen(path, "wb"); FILE *f = fopen(path, "wb");
char subChunk1ID[4] = {'f', 'm', 't', ' '}; char subChunk1ID[4] = {'f', 'm', 't', ' '};

View file

@ -3,29 +3,17 @@
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
#include <string>
#include <vector>
#include "text.h" #include "text.h"
#include "pack.h" #include "pack.h"
#include "pack_77.h"
#include "encode.h" #include "encode.h"
#include "encode_91.h"
#include "unpack.h" #include "unpack.h"
#include "pack_77.h" #include "debug.h"
#include "encode_91.h"
#define LOG_LEVEL LOG_INFO #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) { 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 // Zero-fill the destination array as we will only be setting bits later
@ -53,28 +41,6 @@ void convert_8bit_to_6bit(uint8_t *dst, const uint8_t *src, int nBits) {
} }
} }
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() { bool test1() {
//const char *msg = "CQ DL7ACA JO40"; // 62, 32, 32, 49, 37, 27, 59, 2, 30, 19, 49, 16 //const char *msg = "CQ DL7ACA JO40"; // 62, 32, 32, 49, 37, 27, 59, 2, 30, 19, 49, 16
@ -116,16 +82,16 @@ void test2() {
encode174(test_in, test_out); encode174(test_in, test_out);
for (int j = 0; j < 22; ++j) { for (int j = 0; j < 22; ++j) {
printf("%02x ", test_out[j]); LOG(LOG_INFO, "%02x ", test_out[j]);
} }
printf("\n"); LOG(LOG_INFO, "\n");
} }
void test3() { void test3() {
uint8_t test_in2[10] = { 0x11, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x10, 0x04, 0x01, 0x00 }; 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 uint16_t crc1 = ft8_crc(test_in2, 76); // Calculate CRC of 76 bits only
printf("CRC: %04x\n", crc1); // should be 0x0708 LOG(LOG_INFO, "CRC: %04x\n", crc1); // should be 0x0708
} }

View file

@ -41,55 +41,66 @@ void unpackcall(uint32_t nc, char *callsign) {
// extract maidenhead locator // extract maidenhead locator
void unpackgrid(uint32_t ng, char *grid) { void unpackgrid(uint16_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 constexpr uint16_t NGBASE = 180*180;
// if ng == NGBASE+1: if (ng == NGBASE + 1) {
// return " " grid[0] = 0;
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 " strcpy(grid, "RO");
// if ng == NGBASE+63: return;
// return "RRR " }
// if ng == NGBASE+64: if (ng == NGBASE + 63) {
// return "73 " strcpy(grid, "RRR");
return;
}
if (ng == NGBASE + 64) {
strcpy(grid, "73");
return;
}
// lat = (ng % 180) - 90 int16_t lat = (int16_t)(ng % 180) - 90;
// ng = int(ng / 180) int16_t lng = ((int16_t)(ng / 180) * 2) - 180;
// lng = (ng * 2) - 180
// g = "%c%c%c%c" % (ord('A') + int((179-lng)/20), grid[0] = 'A' + ((179 - lng) / 20);
// ord('A') + int((lat+90)/10), grid[1] = 'A' + ((90 + lat) / 10);
// ord('0') + int(((179-lng)%20)/2), grid[2] = '0' + (((179 - lng) % 20) / 2);
// ord('0') + (lat+90)%10) grid[3] = '0' + ((90 + lat) % 10);
grid[4] = 0;
// if g[0:2] == "KA": if ((grid[0] == 'K') && (grid[1] == 'A')) {
// // really + signal strength // really + signal strength
// sig = int(g[2:4]) - 50 // sig = int(g[2:4]) - 50
// return "+%02d" % (sig) // return "+%02d" % (sig)
return;
// if g[0:2] == "LA": }
// // really R+ signal strength else if ((grid[0] == 'L') && (grid[1] == 'A')) {
// sig = int(g[2:4]) - 50 // really R+ signal strength
// return "R+%02d" % (sig) // sig = int(g[2:4]) - 50
// return "R+%02d" % (sig)
grid[0] = 0; return;
}
} }
void unpacktext(uint32_t nc1, uint32_t nc2, uint16_t ng, char *text) { void unpacktext(uint32_t nc1, uint32_t nc2, uint16_t ng, char *text) {
uint32_t nc3 = ng & 0x7FFF; uint32_t nc3 = (ng & 0x7FFF);
if (nc1 & 1 != 0) // Check for bit 0 and copy it to nc3
if ((nc1 & 1) != 0)
nc3 |= 0x08000; nc3 |= 0x08000;
nc1 >>= 1;
if (nc2 & 1 != 0) if ((nc2 & 1) != 0)
nc3 |= 0x10000; nc3 |= 0x10000;
nc1 >>= 1;
nc2 >>= 1; nc2 >>= 1;
for (int i = 4; i >= 0; --i) { for (int i = 4; i >= 0; --i) {
@ -169,6 +180,7 @@ int unpack(const uint8_t *a72, char *message) {
return 0; return 0;
} }
// Standard two-call exchange
char c1[7]; char c1[7];
unpackcall(nc1, c1); unpackcall(nc1, c1);