uint32_t sent = 0;
struct timeval tSent;
char buf[20];
int8_t modem;
int8_t txPower = 14;
bool iqInverted = false;
bool publicNetwork = true;
uint32_t freq = 921900000;
bool packetMode = true;
uint32_t txInterval = 0;
static void scheduleNextSend();
static void sendTask(void *args) {
if (frame != NULL) {
printf("Tx in progress...\n");
return;
}
if (!frame) {
printf("Not enough memory\n");
return;
}
for (uint8_t n = 2; n < frame->
len; n++)
frame->buf[0] = (sent >> 8);
frame->buf[1] = (sent & 0xff);
SubGHzRadio.wakeup();
System.getTimeSinceBoot(&tSent);
printf("[%lu.%06lu] %lu Tx started...\n", (uint32_t) tSent.tv_sec, tSent.tv_usec, sent);
sent++;
} else {
delete frame;
frame = nullptr;
printf("Tx error\n");
scheduleNextSend();
}
}
static void scheduleNextSend() {
if (txInterval > 0) {
} else {
}
}
if (success) {
struct timeval tDuration;
printf("SUCCESS! (duration: %lu.%06lu)\n", (uint32_t) tDuration.tv_sec, tDuration.tv_usec);
} else {
printf("FAIL!\n");
}
delete frame;
frame = nullptr;
SubGHzRadio.sleep();
scheduleNextSend();
}
}
static void appStart() {
SubGHzRadio.setRadio(sf, bw, cr, true, iqInverted);
SubGHzRadio.setPublicNetwork(publicNetwork);
SubGHzRadio.setChannel(freq);
SubGHzRadio.setTxPower(txPower);
if (packetMode) {
SubGHzRadio.onTxDone = eventOnTxDone;
} else {
SubGHzRadio.transmitCW();
}
}
static void askInterval() {
printf("Set Tx interval in ms [%lu]:", txInterval);
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) > 0) {
txInterval = (uint32_t) strtoul(buf, NULL, 0);
}
printf("* Tx interval: %lu ms\n", txInterval);
appStart();
}
static void askPacketMode() {
printf("Select mode (0: CW, 1: packet) [%d]:", packetMode);
Serial2.onReceive(inputPacketMode);
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "1") == 0) {
printf("* Packet mode selected.\n");
askInterval();
} else if (strcmp(buf, "0") == 0) {
printf("* Continuous wave mode selected.\n");
packetMode = false;
appStart();
} else {
printf("* Unknown mode\n");
askPacketMode();
return;
}
}
static void askFrequency() {
printf("Enter frequency in unit of Hz [%lu]:", freq);
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) > 0) {
uint32_t f = (uint32_t) strtoul(buf, NULL, 0);
if (f == 0) {
printf("* Invalid frequency.\n");
askFrequency();
return;
}
freq = f;
}
printf("* Frequency: %lu\n", freq);
askPacketMode();
}
static void askSyncword() {
printf("Use public network [yN]:");
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) == 0) {
publicNetwork = false;
} else {
if (strcmp(buf, "y") == 0 || strcmp(buf, "Y") == 0) {
publicNetwork = true;
} else if (strcmp(buf, "n") == 0 || strcmp(buf, "N") == 0) {
publicNetwork = false;
} else {
printf("* Invalid syncword.\n");
askSyncword();
return;
}
publicNetwork = true;
}
printf("* Public network: %s\n", publicNetwork ? "true" : "false");
askFrequency();
}
static void askIQ() {
printf("Set IQ (1:normal, 2:inverted) [1]:");
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "1") == 0) {
printf("* Normal selected.\n");
iqInverted = false;
} else if (strcmp(buf, "2") == 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) [14]:");
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) != 0) {
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 (1:125kHz, 2:250kHz, 3:500kHz) [1]:");
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "1") == 0) {
printf("* 125kHz selected.\n");
} else if (strcmp(buf, "2") == 0) {
printf("* 250kHz selected.\n");
} else if (strcmp(buf, "3") == 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]:");
Serial2.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 (5, 6, 7, 8, 9, 10, 11, 12) [5]:");
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "5") == 0) {
printf("* SF5 selected.\n");
} else if (strcmp(buf, "6") == 0) {
printf("* SF6 selected.\n");
} else if (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 (%s)\n", buf);
askSF();
return;
}
askCR();
}
static void askModem() {
printf("Select modem (1: LoRa, 2:FSK) [1]:");
Serial2.inputKeyboard(buf,
sizeof(buf));
}
if (strlen(buf) == 0 || strcmp(buf, "1") == 0) {
printf("* LoRa selected.\n");
askSF();
} else if (strcmp(buf, "2") == 0) {
printf("* FSK selected.\n");
modem = 1;
appStart();
} else {
printf("* Unknown modem\n");
askModem();
}
}
void setup() {
printf("*** [RAK3172] Sub GHz Radio Tx Control Example ***\n");
SubGHzRadio.begin();
SubGHzRadio.sleep();
#if 1
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 startOneShot(uint32_t millis, bool interrupt=false)
작업함수를 millis 밀리초 이후 1회 실행합니다.
void onFired(void(*func)(void *), void *args=nullptr)
타이머 만료시 실행시킬 작업함수를 지정합니다.
void reboot()
소프트웨어 리셋을 통하여 시스템을 재시작합니다.
@ ERROR_SUCCESS
Definition nola-common.h:119
bool postTask(void(*func)(void *), void *args)
작업을 나중에 실행되도록 게시합니다.
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
@ SF6
Definition Radio.hpp:81
@ 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
@ SF5
Definition Radio.hpp:80
GPIO 인터럽트에 관한 상세정보
Definition nola-common.h:535
struct timeval timeEnteredISR
인터럽트가 발생하고 MCU가 ISR에 진입했을 때의 timestamp.
Definition nola-common.h:570