#include #include #include #include #include #include void hexdump(uint8_t *ptr, size_t len) { int i; for (i = 0; i < len; i++) usb_printf("%02x", ptr[i]); } void txdone(void) { usb_printf("txdone\r\n"); } void txtimeout(void) { usb_printf("txtimeout\r\n"); } void rxdone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { usb_printf("rxdone: size: %hu, rssi: %hd, snr: %d\r\ndata: ", size, rssi, snr); hexdump(payload, size); usb_printf("\r\n"); } void rxtimeout(void) { usb_printf("rxtimeout\r\n"); } void rxerr(void) { usb_printf("rxerr\r\n"); } RadioEvents_t revents = { .TxDone = txdone, .TxTimeout = txtimeout, .RxDone = rxdone, .RxTimeout = rxtimeout, .RxError = rxerr, }; int main(void) { uint8_t bytes[8]; strobe_rng_init(); BoardInitMcu(); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_8, GPIO_PIN_SET); #if 1 wait_for_vcp(); usb_printf("starting...\r\n"); bare_strobe_randomize(bytes, sizeof bytes); hexdump(bytes, sizeof bytes); usb_printf("\r\n"); #endif Radio.Init(&revents); usb_printf("foo\r\n"); Radio.ReadBuffer(0x00, bytes, sizeof bytes); usb_printf("regs 0x00: "); hexdump(bytes, sizeof bytes); usb_printf("\r\n"); Radio.ReadBuffer(0x40, bytes, sizeof bytes); usb_printf("regs 0x40: "); hexdump(bytes, sizeof bytes); usb_printf("\r\n"); uint32_t v; v = Radio.Random(); usb_printf("rr: %#x\r\n", v); v = Radio.Random(); usb_printf("rr: %#x\r\n", v); v = Radio.Random(); usb_printf("rr: %#x\r\n", v); usb_printf("gs: %#x\r\n", Radio.GetStatus()); usb_printf("set modem\r\n", v); Radio.SetModem(MODEM_LORA); usb_printf("check rffreq: %d\r\n", (int)Radio.CheckRfFrequency(914350 * 1000)); usb_printf("set channel\r\n", v); Radio.SetChannel(914350 * 1000); v = Radio.Random(); usb_printf("rr: %#x\r\n", v); usb_printf("rssi: %#hx\r\n", Radio.Rssi(MODEM_LORA)); /* RX/TX parameters */ const uint8_t modem = MODEM_LORA; const uint8_t bandwidth = 0 /* 128 kHz */; const uint8_t datarate = 7 /* 128 chips */; const uint8_t coderate = 1 /* 4/5 */; const uint8_t preambleLen = 4 /* symbols */; const uint8_t fixLen = 0 /* variable */; const uint8_t crcOn = 1 /* on */; const uint8_t freqHopOn = 0 /* off */; const bool iqInverted = false /* not inverted */; Radio.SetRxConfig(modem, bandwidth, datarate, coderate, 0/*afc*/, preambleLen, 5/*symTimeout*/, fixLen, 0/*payloadlen*/, crcOn, freqHopOn, 0/*hopPeriod*/, iqInverted, true/*rxcont*/); Radio.SetTxConfig(modem, 11/*power*/, 0/*fdev*/, bandwidth, datarate, coderate, preambleLen, fixLen, crcOn, freqHopOn, 0/*hopPeriod*/, iqInverted, 1000/*timeout*/); uint8_t sendmsg[] = "testing lora123"; usb_printf("sending...\r\n"); Radio.Send(sendmsg, sizeof sendmsg); DelayMs(200); Radio.Send(sendmsg, sizeof sendmsg); DelayMs(200); Radio.Send(sendmsg, sizeof sendmsg); DelayMs(200); usb_printf("rx(0)...\r\n"); Radio.Rx(0); loop: BoardLowPowerHandler(); if (Radio.IrqProcess != NULL) Radio.IrqProcess(); goto loop; }