2023-04-22 20:17:56 +02:00
|
|
|
|
|
|
|
#include <Arduino.h>
|
2023-04-25 03:08:16 +02:00
|
|
|
#include <util/crc16.h>
|
2023-04-22 20:17:56 +02:00
|
|
|
|
|
|
|
#include "afsk_sinus.hpp"
|
|
|
|
|
2023-04-25 03:08:16 +02:00
|
|
|
#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
|
|
|
|
};
|
|
|
|
|
2023-04-22 20:17:56 +02:00
|
|
|
|
|
|
|
extern void sendOne(uint32_t *us, uint8_t *phaseShift);
|
|
|
|
extern void sendZero(uint32_t *us, uint8_t *phaseShift);
|
2023-04-25 03:08:16 +02:00
|
|
|
extern void setZero();
|
2023-04-22 20:17:56 +02:00
|
|
|
|
|
|
|
uint32_t m = 0;
|
|
|
|
uint8_t phaseShift = 0;
|
2023-04-25 03:08:16 +02:00
|
|
|
bool nrzi = true;
|
2023-04-22 20:17:56 +02:00
|
|
|
|
2023-04-25 03:08:16 +02:00
|
|
|
void sendBell202(uint8_t byt, bool sync) {
|
|
|
|
if (sync) {
|
|
|
|
phaseShift = 0;
|
|
|
|
m = micros();
|
|
|
|
}
|
2023-04-22 20:17:56 +02:00
|
|
|
for (uint8_t i = 0; i < 8; ++i) {
|
2023-04-25 03:08:16 +02:00
|
|
|
if (!((byt >> i) & 1)) {
|
|
|
|
nrzi = !nrzi;
|
|
|
|
}
|
|
|
|
if (nrzi) {
|
2023-04-22 20:17:56 +02:00
|
|
|
sendOne(&m, &phaseShift);
|
|
|
|
} else {
|
|
|
|
sendZero(&m, &phaseShift);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-25 03:08:16 +02:00
|
|
|
void sendBell202buf(uint8_t *buf, size_t len, bool sync) {
|
2023-04-22 20:17:56 +02:00
|
|
|
for (size_t i = 0; i < len; ++i) {
|
2023-04-25 03:08:16 +02:00
|
|
|
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]);
|
2023-04-22 20:17:56 +02:00
|
|
|
}
|
2023-04-25 03:08:16 +02:00
|
|
|
frame.eflag = 0x7e;
|
2023-04-22 20:17:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
OUT_DDR = 0xff;
|
2023-04-25 03:08:16 +02:00
|
|
|
setZero();
|
|
|
|
initFrame();
|
|
|
|
nrzi = true;
|
2023-04-22 20:17:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2023-04-25 03:08:16 +02:00
|
|
|
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);
|
2023-04-22 20:17:56 +02:00
|
|
|
}
|