Skip to content

Commit

Permalink
split of sub-1GHz radio driver is complete
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed May 7, 2024
1 parent 91d5f6b commit ce210af
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 193 deletions.
1 change: 1 addition & 0 deletions software/firmware/source/SoftRF/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ PLAT_CPPS := $(PLATFORM_PATH)/ESP8266.cpp \
DRV_CPPS := $(DRIVER_PATH)/RF.cpp \
$(DRIVER_PATH)/radio/nordic.cpp \
$(DRIVER_PATH)/radio/almic.cpp \
$(DRIVER_PATH)/radio/uatm.cpp \
$(DRIVER_PATH)/radio/easylink.cpp \
$(DRIVER_PATH)/radio/ogn.cpp \
$(DRIVER_PATH)/radio/nicerf.cpp \
Expand Down
191 changes: 1 addition & 190 deletions software/firmware/source/SoftRF/src/driver/RF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
#include "RF.h"
#include "EEPROM.h"
//#include "Battery.h"
#include "../ui/Web.h"
//#include "../ui/Web.h"
#if !defined(EXCLUDE_MAVLINK)
#include "../protocol/data/MAVLink.h"
#endif /* EXCLUDE_MAVLINK */
#include <fec.h>

byte RxBuffer[MAX_PKT_SIZE] __attribute__((aligned(sizeof(uint32_t))));

Expand Down Expand Up @@ -61,26 +60,6 @@ static uint8_t RF_timing = RF_TIMING_INTERVAL;

extern const gnss_chip_ops_t *gnss_chip;

static bool uatm_probe(void);
static void uatm_setup(void);
static void uatm_channel(int8_t);
static bool uatm_receive(void);
static bool uatm_transmit(void);
static void uatm_shutdown(void);

#if !defined(EXCLUDE_UATM)
const rfchip_ops_t uatm_ops = {
RF_IC_UATM,
"UATM",
uatm_probe,
uatm_setup,
uatm_channel,
uatm_receive,
uatm_transmit,
uatm_shutdown
};
#endif /* EXCLUDE_UATM */

String Bin2Hex(byte *buffer, size_t size)
{
String str = "";
Expand Down Expand Up @@ -432,171 +411,3 @@ uint8_t RF_Payload_Size(uint8_t protocol)
default: return 0;
}
}

#if !defined(EXCLUDE_UATM)
/*
* UATM-specific code
*
*
*/

#include <uat.h>

#define UAT_RINGBUF_SIZE (sizeof(Stratux_frame_t) * 2)

static unsigned char uat_ringbuf[UAT_RINGBUF_SIZE];
static unsigned int uatbuf_head = 0;
Stratux_frame_t uatradio_frame;

const char UAT_ident[] PROGMEM = SOFTRF_IDENT;

static bool uatm_probe()
{
bool success = false;
unsigned long startTime;
unsigned int uatbuf_tail;
u1_t keylen = strlen_P(UAT_ident);
u1_t i=0;

/* Do not probe on itself and ESP8266 */
if (SoC->id == SOC_CC13X0 ||
SoC->id == SOC_CC13X2 ||
SoC->id == SOC_ESP8266) {
return success;
}

SoC->UATSerial_begin(UAT_RECEIVER_BR);

SoC->UATModule_restart();

startTime = millis();

// Timeout if no valid response in 1 second
while (millis() - startTime < 1000) {

if (UATSerial.available() > 0) {
unsigned char c = UATSerial.read();
#if DEBUG
Serial.println(c, HEX);
#endif
uat_ringbuf[uatbuf_head % UAT_RINGBUF_SIZE] = c;

uatbuf_tail = uatbuf_head - keylen;
uatbuf_head++;

for (i=0; i < keylen; i++) {
if (pgm_read_byte(&UAT_ident[i]) != uat_ringbuf[(uatbuf_tail + i) % UAT_RINGBUF_SIZE]) {
break;
}
}

if (i >= keylen) {
success = true;
break;
}
}
}

/* cleanup UAT data buffer */
uatbuf_head = 0;
memset(uat_ringbuf, 0, sizeof(uat_ringbuf));

/* Current ESP32 Core has a bug with Serial2.end()+Serial2.begin() cycle */
if (SoC->id != SOC_ESP32) {
UATSerial.end();
}

return success;
}

static void uatm_channel(int8_t channel)
{
/* Nothing to do */
}

static void uatm_setup()
{
/* Current ESP32 Core has a bug with Serial2.end()+Serial2.begin() cycle */
if (SoC->id != SOC_ESP32) {
SoC->UATSerial_begin(UAT_RECEIVER_BR);
}

init_fec();

/* Enforce radio settings to follow UAT978 protocol's RF specs */
settings->rf_protocol = RF_PROTOCOL_ADSB_UAT;

RF_FreqPlan.setPlan(settings->band, settings->rf_protocol);

protocol_encode = &uat978_encode;
protocol_decode = &uat978_decode;
}

static bool uatm_receive()
{
bool success = false;
unsigned int uatbuf_tail;
int rs_errors;

while (UATSerial.available()) {
unsigned char c = UATSerial.read();

uat_ringbuf[uatbuf_head % UAT_RINGBUF_SIZE] = c;

uatbuf_tail = uatbuf_head - sizeof(Stratux_frame_t);
uatbuf_head++;

if (uat_ringbuf[ uatbuf_tail % UAT_RINGBUF_SIZE] == STRATUX_UATRADIO_MAGIC_1 &&
uat_ringbuf[(uatbuf_tail + 1) % UAT_RINGBUF_SIZE] == STRATUX_UATRADIO_MAGIC_2 &&
uat_ringbuf[(uatbuf_tail + 2) % UAT_RINGBUF_SIZE] == STRATUX_UATRADIO_MAGIC_3 &&
uat_ringbuf[(uatbuf_tail + 3) % UAT_RINGBUF_SIZE] == STRATUX_UATRADIO_MAGIC_4) {

unsigned char *pre_fec_buf = (unsigned char *) &uatradio_frame;
for (u1_t i=0; i < sizeof(Stratux_frame_t); i++) {
pre_fec_buf[i] = uat_ringbuf[(uatbuf_tail + i) % UAT_RINGBUF_SIZE];
}

int frame_type = correct_adsb_frame(uatradio_frame.data, &rs_errors);

if (frame_type == -1) {
continue;
}

u1_t size = 0;

if (frame_type == 1) {
size = SHORT_FRAME_DATA_BYTES;
} else if (frame_type == 2) {
size = LONG_FRAME_DATA_BYTES;
}

if (size > sizeof(RxBuffer)) {
size = sizeof(RxBuffer);
}

if (size > 0) {
memcpy(RxBuffer, uatradio_frame.data, size);

RF_last_rssi = uatradio_frame.rssi;
rx_packets_counter++;
success = true;

break;
}
}
}

return success;
}

static bool uatm_transmit()
{
/* Nothing to do */
return false;
}

static void uatm_shutdown()
{
/* Nothing to do */
}
#endif /* EXCLUDE_UATM */
4 changes: 3 additions & 1 deletion software/firmware/source/SoftRF/src/driver/RF.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ extern const rfchip_ops_t sx1262_ops;
#endif /* USE_BASICMAC */
#endif /*EXCLUDE_SX12XX */

/* PLACEHOLDER */
#if !defined(EXCLUDE_UATM)
extern const rfchip_ops_t uatm_ops;
#endif /* EXCLUDE_UATM */

#if !defined(EXCLUDE_CC13XX)
extern const rfchip_ops_t cc13xx_ops;
Expand Down

0 comments on commit ce210af

Please sign in to comment.