fix phase shift overflow, implement frame serialization

This commit is contained in:
s3lph 2023-04-25 03:08:16 +02:00
parent dafe1910db
commit 6812cfbcdb
3 changed files with 101 additions and 13 deletions

View file

@ -52,10 +52,14 @@ void sendZero(uint32_t *us, uint8_t *phaseShift) {{
while ((t = micros() - *us) < INV_BAUD) {{
OUT_PORT = pgm_read_byte(&SINUS2200[ (PS2200[*phaseShift] + t) % N_SINUS_2200 ]);
}}
(*phaseShift)++;
*phaseShift = (*phaseShift + 1) % N_SHIFTS;
*us += INV_BAUD;
}}
void setZero() {{
OUT_PORT = pgm_read_byte(&SINUS2200[0]);
}}
''')

View file

@ -27,7 +27,11 @@ void sendZero(uint32_t *us, uint8_t *phaseShift) {
while ((t = micros() - *us) < INV_BAUD) {
OUT_PORT = pgm_read_byte(&SINUS2200[ (PS2200[*phaseShift] + t) % N_SINUS_2200 ]);
}
(*phaseShift)++;
*phaseShift = (*phaseShift + 1) % N_SHIFTS;
*us += INV_BAUD;
}
void setZero() {
OUT_PORT = pgm_read_byte(&SINUS2200[0]);
}

View file

@ -1,18 +1,73 @@
#include <Arduino.h>
#include <util/crc16.h>
#include "afsk_sinus.hpp"
#define NCOMMENT 0
#define CALLSIGN "HB3YBQ"
uint8_t txdelay[32];
struct ax25 {
uint8_t sflag;
uint8_t daddr[7];
uint8_t saddr[7];
uint8_t ctrl;
uint8_t proto;
struct {
uint8_t dtid;
uint8_t type;
char time[7];
char lat[8];
uint8_t sym_table_id;
char lon[9];
uint8_t sym_code;
char comment[NCOMMENT];
} __attribute__((packed)) aprs;
uint16_t fcs;
uint8_t eflag;
} __attribute__((packed)) frame;
enum AprsSymbol : uint8_t {
NONE,
AMBULANCE,
BUS,
FIRE_TRUCK,
BICYCLE,
YACHT,
HELICOPTER,
SMALL_AIRCRAFT,
SHIP,
CAR,
MOTORCYCLE,
BALLOON,
JEEP,
RECREATIONAL_VEHICLE,
TRUCK,
VAN
};
extern void sendOne(uint32_t *us, uint8_t *phaseShift);
extern void sendZero(uint32_t *us, uint8_t *phaseShift);
extern void setZero();
uint32_t m = 0;
uint8_t phaseShift = 0;
bool nrzi = true;
void sendBell202(uint8_t byt) {
void sendBell202(uint8_t byt, bool sync) {
if (sync) {
phaseShift = 0;
m = micros();
}
for (uint8_t i = 0; i < 8; ++i) {
if ((byt >> i) & 1) {
if (!((byt >> i) & 1)) {
nrzi = !nrzi;
}
if (nrzi) {
sendOne(&m, &phaseShift);
} else {
sendZero(&m, &phaseShift);
@ -20,23 +75,48 @@ void sendBell202(uint8_t byt) {
}
}
void sendBell202buf(uint8_t *buf, size_t len) {
m = micros();
void sendBell202buf(uint8_t *buf, size_t len, bool sync) {
for (size_t i = 0; i < len; ++i) {
sendBell202(buf[i]);
sendBell202(buf[i], sync);
sync = false;
}
}
void initFrame() {
memset(txdelay, 0x7e, sizeof(txdelay));
memset(&frame, 0, sizeof(frame));
frame.sflag = 0x7e;
memcpy(&frame.daddr, "GPS\x00\x00\x00\x00", 7);
memcpy(&frame.saddr, CALLSIGN, 6);
frame.ctrl = 0x03;
frame.proto = 0xf0;
frame.aprs.dtid = 1;
memcpy(&frame.aprs.time, "151430h", 7);
memcpy(&frame.aprs.lat, "4730.00N", 8);
frame.aprs.sym_table_id = '/';
memcpy(&frame.aprs.lon, "00730.00E", 9);
frame.aprs.sym_code = BICYCLE;
frame.fcs = 0xffff;
for (size_t i = 0; i < sizeof(frame) - 3; ++i) {
frame.fcs = _crc_xmodem_update(frame.fcs, ((uint8_t*) &frame)[i]);
}
frame.eflag = 0x7e;
}
void setup() {
OUT_DDR = 0xff;
Serial.begin(115200);
setZero();
initFrame();
nrzi = true;
}
uint8_t bytes[] = {
0xff, 0x55, 0xff, 0x00, 0xff, 0x00
};
void loop() {
sendBell202buf(bytes, 6);
sendBell202buf(txdelay, sizeof(txdelay), true);
//sendBell202buf((uint8_t*) &frame, sizeof(frame) - 1, false);
//sendBell202buf((uint8_t*) &frame, sizeof(frame) - 1, false);
sendBell202buf((uint8_t*) &frame, sizeof(frame), false);
setZero();
nrzi = true;
delay(10000);
}