#include #include #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, bool sync) { if (sync) { phaseShift = 0; m = micros(); } for (uint8_t i = 0; i < 8; ++i) { if (!((byt >> i) & 1)) { nrzi = !nrzi; } if (nrzi) { sendOne(&m, &phaseShift); } else { sendZero(&m, &phaseShift); } } } void sendBell202buf(uint8_t *buf, size_t len, bool sync) { for (size_t i = 0; i < len; ++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; setZero(); initFrame(); nrzi = true; } void loop() { 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); }