#include "SX1276Wiring.hpp"
SX1276Wiring SX1276 = SX1276Wiring(
A0,
D10,
A4,
D2,
D3,
D4,
D5,
A3
);
uint32_t sent = 0;
char buf[20];
int8_t modem;
int8_t txPower;
bool iqInverted = false;
uint8_t syncword;
uint32_t freq = 917100000;
bool packetMode = true;
printf(
"[%lu us] Tx %s!\n",
micros(), (success) ?
"SUCCESS" :
"FAIL");
delete frame;
frame = NULL;
}
static void sendTask(void *args) {
if (frame != NULL) {
printf("Tx in progress...\n");
return;
}
if (!frame || !frame->
buf) {
printf("Not enough memory\n");
return;
}
for (uint8_t n = 2; n < frame->
len; n++)
frame->buf[n] = n;
frame->buf[0] = (sent >> 8);
frame->buf[1] = (sent & 0xff);
SX1276.transmit(frame);
printf(
"[%lu us] %lu Tx started...\n",
micros(), sent);
sent++;
}
}
static void appStart() {
Serial.stopInput();
Serial.onReceive(eventKeyStroke);
SX1276.begin();
if (modem == 0) {
SX1276.setRadio(sf, bw, cr, true, iqInverted);
SX1276.setSyncword(syncword);
} else {
SX1276.setRadio(50000, 50000, 83333, 25000);
}
SX1276.setChannel(freq);
SX1276.setTxPower(txPower);
if (packetMode) {
SX1276.onTxDone = eventOnTxDone;
SX1276.wakeup();
} else {
SX1276.transmitCW(true);
}
}
static void askPacketMode() {
printf("Select modme (0: packet, 1: CW) [0]:");
Serial.onReceive(inputPacketMode);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "0") == 0) {
printf("* Packet mode selected.\n");
packetMode = true;
} else if (strcmp(buf, "1") == 0) {
printf("* Continuous wave mode selected.\n");
packetMode = false;
} else {
printf("* Unknown mode\n");
askPacketMode();
return;
}
appStart();
}
static void askFrequency() {
printf("Enter frequency in unit of Hz [917100000]:");
Serial.onReceive(inputFrequency);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0) {
freq = 917100000;
} else {
freq = (uint32_t) strtoul(buf, NULL, 0);
if (freq == 0) {
printf("* Invalid frequency.\n");
askFrequency();
return;
}
}
printf("* Frequency: %lu\n", freq);
askPacketMode();
}
static void askSyncword() {
printf("Enter syncword [0x12]:");
Serial.onReceive(inputSyncword);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0) {
syncword = 0x12;
} else {
uint8_t sw = (uint8_t) strtoul(buf, NULL, 0);
if (sw == 0) {
printf("* Invalid syncword.\n");
askSyncword();
return;
}
syncword = sw;
}
printf("* Syncword: 0x%02X\n", syncword);
askFrequency();
}
static void askIQ() {
printf("Set IQ (0:normal, 1:inverted) [0]:");
Serial.onReceive(inputIQ);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "0") == 0) {
printf("* Normal selected.\n");
iqInverted = false;
} else if (strcmp(buf, "1") == 0) {
printf("* inverted selected.\n");
iqInverted = true;
} else {
printf("* Unknown IQ mode\n");
askIQ();
return;
}
askSyncword();
}
static void askTxPower() {
printf("Set Tx power (-1 ~ 20) [-1]:");
Serial.onReceive(inputTxPower);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0) {
txPower = -1;
}
txPower = (uint8_t) strtol(buf, NULL, 0);
printf("* %d dBm selected.\n", txPower);
if (txPower < -1 || txPower > 20) {
printf("* Unknown Tx power.\n");
askTxPower();
return;
}
askIQ();
}
static void askBW() {
printf("Set bandwidth (0:125kHz, 1:250kHz, 2:500kHz) [0]:");
Serial.onReceive(inputBW);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "0") == 0) {
printf("* 125kHz selected.\n");
} else if (strcmp(buf, "1") == 0) {
printf("* 250kHz selected.\n");
} else if (strcmp(buf, "2") == 0) {
printf("* 500kHz selected.\n");
} else {
printf("* Unknown SF\n");
askBW();
return;
}
askTxPower();
}
static void askCR() {
printf("Set coding rate (1:4/5, 2:4/6, 3:4/7, 4:4/8) [1]:");
Serial.onReceive(inputCR);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "1") == 0) {
printf("* (4/5) selected.\n");
} else if (strcmp(buf, "2") == 0) {
printf("* (4/6) selected.\n");
} else if (strcmp(buf, "3") == 0) {
printf("* (4/7) selected.\n");
} else if (strcmp(buf, "4") == 0) {
printf("* (4/8) selected.\n");
} else {
printf("* Unknown coding rate\n");
askCR();
return;
}
askBW();
}
static void askSF() {
printf("Set SF (7, 8, 9, 10, 11, 12) [7]:");
Serial.onReceive(inputSF);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "7") == 0) {
printf("* SF7 selected.\n");
} else if (strcmp(buf, "8") == 0) {
printf("* SF8 selected.\n");
} else if (strcmp(buf, "9") == 0) {
printf("* SF9 selected.\n");
} else if (strcmp(buf, "10") == 0) {
printf("* SF10 selected.\n");
} else if (strcmp(buf, "11") == 0) {
printf("* SF11 selected.\n");
} else if (strcmp(buf, "12") == 0) {
printf("* SF12 selected.\n");
} else {
printf("* Unknown SF\n");
askSF();
return;
}
askCR();
}
static void askModem() {
printf("Select modem (0: LoRa, 1:FSK) [0]:");
Serial.onReceive(inputModem);
Serial.inputKeyboard(buf, sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "0") == 0) {
printf("* LoRa selected.\n");
modem = 0;
askSF();
} else if (strcmp(buf, "1") == 0) {
printf("* FSK selected.\n");
modem = 1;
appStart();
} else {
printf("* Unknown modem\n");
askModem();
}
}
void setup(void) {
Serial.begin(115200);
printf("*** [ST Nucleo-F429ZI] SX1276 Low-Level Tx Control Example ***\n");
#if 1
Serial.listen();
askModem();
#else
modem = 0;
txPower = 14;
iq = true;
syncword = 0x12;
appStart();
#endif
}
무선 패킷
Definition RadioPacket.hpp:59
시리얼 포트를 제어하기 위한 클래스
Definition SerialPort.hpp:76
Timer는 일정 시간 이후에 1회 실행될 작업, 매 일정 시간마다 실행될 작업 등을 위한 기능입니다.
Definition Timer.hpp:61
bool startPeriodic(uint32_t millis, bool interrupt=false)
작업함수를 매 millis 밀리초 주기로 반복하여 실행합니다.
void onFired(void(*func)(void *), void *args=nullptr)
타이머 만료시 실행시킬 작업함수를 지정합니다.
uint32_t micros()
보드 부팅 이후부터 현재까지의 경과 시간을 마이크로초 단위로 구합니다.
void reboot()
소프트웨어 리셋을 통하여 시스템을 재시작합니다.
LoRaBW_t
LoRa Bandwidth Type.
Definition Radio.hpp:107
@ BW_250kHz
Definition Radio.hpp:110
@ BW_125kHz
Definition Radio.hpp:109
@ BW_500kHz
Definition Radio.hpp:111
LoRaCR_t
LoRa Coding Rate Type.
Definition Radio.hpp:93
@ CR_4_6
Definition Radio.hpp:96
@ CR_4_7
Definition Radio.hpp:97
@ CR_4_8
Definition Radio.hpp:98
@ CR_4_5
Definition Radio.hpp:95
LoRaSF_t
LoRa Spreading Factor Type.
Definition Radio.hpp:78
@ SF8
Definition Radio.hpp:83
@ SF12
Definition Radio.hpp:87
@ SF7
Definition Radio.hpp:82
@ SF9
Definition Radio.hpp:84
@ SF11
Definition Radio.hpp:86
@ SF10
Definition Radio.hpp:85
GPIO 인터럽트에 관한 상세정보
Definition nola-common.h:535