From 8c38bb4089734632930b98efbf7a986bc7a93273 Mon Sep 17 00:00:00 2001 From: Canopus Date: Thu, 18 Jul 2024 22:00:22 +0700 Subject: [PATCH] . --- examples/LoRa_P2P/LoRa_P2P.ino | 30 +++++++------- examples/LoRa_P2P_Rx/LoRa_P2P_Rx.ino | 30 +++++++------- examples/LoRa_P2P_Tx/LoRa_P2P_Tx.ino | 30 +++++++------- examples/Lora_Modbus/function.cpp | 56 +++++++++++---------------- examples/Rak2Ra02/Rak3172/Rak3172.ino | 30 +++++++------- 5 files changed, 83 insertions(+), 93 deletions(-) diff --git a/examples/LoRa_P2P/LoRa_P2P.ino b/examples/LoRa_P2P/LoRa_P2P.ino index fe95a06..8a99f67 100644 --- a/examples/LoRa_P2P/LoRa_P2P.ino +++ b/examples/LoRa_P2P/LoRa_P2P.ino @@ -57,21 +57,21 @@ void recv_cb(rui_lora_p2p_recv_t data) void send_cb(void) { Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); } void setup() { Serial.begin(115200); - Serial.println("RAK3172_Canopus LoRaWan P2P Example"); + Serial.println("RAK3172_Canopus lora P2P Example"); Serial.println("------------------------------------------------------"); init_io(); startTime = millis(); - if (api.lorawan.nwm.get() != 0) + if (api.lora.nwm.get() != 0) { Serial.printf("Set Node device work mode %s\r\n", - api.lorawan.nwm.set(0) ? "Success" : "Fail"); + api.lora.nwm.set() ? "Success" : "Fail"); api.system.reboot(); } @@ -85,21 +85,21 @@ void setup() Serial.printf("AT Command Version: %s\r\n", api.system.cliVersion.get().c_str()); Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6), - api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail"); + api.lora.pfreq.set(myFreq) ? "Success" : "Fail"); Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf, - api.lorawan.psf.set(sf) ? "Success" : "Fail"); + api.lora.psf.set(sf) ? "Success" : "Fail"); Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw, - api.lorawan.pbw.set(bw) ? "Success" : "Fail"); + api.lora.pbw.set(bw) ? "Success" : "Fail"); Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5), - api.lorawan.pcr.set(cr) ? "Success" : "Fail"); + api.lora.pcr.set(cr) ? "Success" : "Fail"); Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble, - api.lorawan.ppl.set(preamble) ? "Success" : "Fail"); + api.lora.ppl.set(preamble) ? "Success" : "Fail"); Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower, - api.lorawan.ptp.set(txPower) ? "Success" : "Fail"); - api.lorawan.registerPRecvCallback(recv_cb); - api.lorawan.registerPSendCallback(send_cb); + api.lora.ptp.set(txPower) ? "Success" : "Fail"); + api.lora.registerPRecvCallback(recv_cb); + api.lora.registerPSendCallback(send_cb); Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); // let's kick-start things by waiting 3 seconds. } @@ -112,11 +112,11 @@ void loop() rx_done = false; while (!send_result) { - send_result = api.lorawan.psend(sizeof(payload), payload); + send_result = api.lora.psend(sizeof(payload), payload); Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail"); if (!send_result) { - Serial.printf("P2P finish Rx mode %s\r\n", api.lorawan.precv(0) ? "Success" : "Fail"); + Serial.printf("P2P finish Rx mode %s\r\n", api.lora.precv(0) ? "Success" : "Fail"); delay(1000); } } diff --git a/examples/LoRa_P2P_Rx/LoRa_P2P_Rx.ino b/examples/LoRa_P2P_Rx/LoRa_P2P_Rx.ino index 8e57842..e169e86 100644 --- a/examples/LoRa_P2P_Rx/LoRa_P2P_Rx.ino +++ b/examples/LoRa_P2P_Rx/LoRa_P2P_Rx.ino @@ -24,21 +24,21 @@ void recv_cb(rui_lora_p2p_recv_t data) void send_cb(void) { Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); } void setup() { Serial.begin(115200); - Serial.println("RAK3172_Canopus LoRaWan P2P Example"); + Serial.println("RAK3172_Canopus lora P2P Example"); Serial.println("------------------------------------------------------"); init_io(); startTime = millis(); - if (api.lorawan.nwm.get() != 0) + if (api.lora.nwm.get() != 0) { Serial.printf("Set Node device work mode %s\r\n", - api.lorawan.nwm.set(0) ? "Success" : "Fail"); + api.lora.nwm.set() ? "Success" : "Fail"); api.system.reboot(); } @@ -52,21 +52,21 @@ void setup() Serial.printf("AT Command Version: %s\r\n", api.system.cliVersion.get().c_str()); Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6), - api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail"); + api.lora.pfreq.set(myFreq) ? "Success" : "Fail"); Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf, - api.lorawan.psf.set(sf) ? "Success" : "Fail"); + api.lora.psf.set(sf) ? "Success" : "Fail"); Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw, - api.lorawan.pbw.set(bw) ? "Success" : "Fail"); + api.lora.pbw.set(bw) ? "Success" : "Fail"); Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5), - api.lorawan.pcr.set(cr) ? "Success" : "Fail"); + api.lora.pcr.set(cr) ? "Success" : "Fail"); Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble, - api.lorawan.ppl.set(preamble) ? "Success" : "Fail"); + api.lora.ppl.set(preamble) ? "Success" : "Fail"); Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower, - api.lorawan.ptp.set(txPower) ? "Success" : "Fail"); - api.lorawan.registerPRecvCallback(recv_cb); - api.lorawan.registerPSendCallback(send_cb); + api.lora.ptp.set(txPower) ? "Success" : "Fail"); + api.lora.registerPRecvCallback(recv_cb); + api.lora.registerPSendCallback(send_cb); Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); } void loop() @@ -79,11 +79,11 @@ void loop() while (!send_result) { digitalWrite(LED_SEND, HIGH); - send_result = api.lorawan.psend(sizeof(payload), payload); + send_result = api.lora.psend(sizeof(payload), payload); Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail"); if (!send_result) { - Serial.printf("P2P finish Rx mode %s\r\n", api.lorawan.precv(0) ? "Success" : "Fail"); + Serial.printf("P2P finish Rx mode %s\r\n", api.lora.precv(0) ? "Success" : "Fail"); delay(1000); } } diff --git a/examples/LoRa_P2P_Tx/LoRa_P2P_Tx.ino b/examples/LoRa_P2P_Tx/LoRa_P2P_Tx.ino index 93b6e4c..5e12966 100644 --- a/examples/LoRa_P2P_Tx/LoRa_P2P_Tx.ino +++ b/examples/LoRa_P2P_Tx/LoRa_P2P_Tx.ino @@ -46,21 +46,21 @@ void recv_cb(rui_lora_p2p_recv_t data) void send_cb(void) { Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); } void setup() { Serial.begin(115200); - Serial.println("RAK3172_Canopus LoRaWan P2P Example"); + Serial.println("RAK3172_Canopus lora P2P Example"); Serial.println("------------------------------------------------------"); init_io(); startTime = millis(); - if (api.lorawan.nwm.get() != 0) + if (api.lora.nwm.get() != 0) { Serial.printf("Set Node device work mode %s\r\n", - api.lorawan.nwm.set(0) ? "Success" : "Fail"); + api.lora.nwm.set() ? "Success" : "Fail"); api.system.reboot(); } @@ -74,21 +74,21 @@ void setup() Serial.printf("AT Command Version: %s\r\n", api.system.cliVersion.get().c_str()); Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6), - api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail"); + api.lora.pfreq.set(myFreq) ? "Success" : "Fail"); Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf, - api.lorawan.psf.set(sf) ? "Success" : "Fail"); + api.lora.psf.set(sf) ? "Success" : "Fail"); Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw, - api.lorawan.pbw.set(bw) ? "Success" : "Fail"); + api.lora.pbw.set(bw) ? "Success" : "Fail"); Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5), - api.lorawan.pcr.set(cr) ? "Success" : "Fail"); + api.lora.pcr.set(cr) ? "Success" : "Fail"); Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble, - api.lorawan.ppl.set(preamble) ? "Success" : "Fail"); + api.lora.ppl.set(preamble) ? "Success" : "Fail"); Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower, - api.lorawan.ptp.set(txPower) ? "Success" : "Fail"); - api.lorawan.registerPRecvCallback(recv_cb); - api.lorawan.registerPSendCallback(send_cb); + api.lora.ptp.set(txPower) ? "Success" : "Fail"); + api.lora.registerPRecvCallback(recv_cb); + api.lora.registerPSendCallback(send_cb); Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); } void loop() @@ -97,10 +97,10 @@ void loop() bool send_result = false; while (!send_result) { - send_result = api.lorawan.psend(sizeof(payload), payload); + send_result = api.lora.psend(sizeof(payload), payload); if (!send_result) { - api.lorawan.precv(0); + api.lora.precv(0); delay(1000); } } diff --git a/examples/Lora_Modbus/function.cpp b/examples/Lora_Modbus/function.cpp index d32a7dd..7e4e707 100644 --- a/examples/Lora_Modbus/function.cpp +++ b/examples/Lora_Modbus/function.cpp @@ -6,11 +6,9 @@ long startTime; bool rx_done = false; uint16_t sf = 12, bw = 0, cr = 0, preamble = 8, txPower = 22; -void Modbus_read(uint8_t *buf, uint16_t len) -{ +void Modbus_read(uint8_t *buf, uint16_t len) { Serial.print("\r\n[Lora]Read/Write: "); - for (int i = 0; i < len; i++) - { + for (int i = 0; i < len; i++) { Serial.print("["); Serial.print(buf[i], HEX); Serial_modbus.printf("%c", buf[i]); @@ -18,11 +16,9 @@ void Modbus_read(uint8_t *buf, uint16_t len) } } -void recv_cb(rui_lora_p2p_recv_t data) -{ +void recv_cb(rui_lora_p2p_recv_t data) { rx_done = true; - if (data.BufferSize == 0) - { + if (data.BufferSize == 0) { Serial.println("Empty buffer."); return; } @@ -35,19 +31,16 @@ void recv_cb(rui_lora_p2p_recv_t data) digitalWrite(LED_RECV, LOW); } -void send_cb(void) -{ +void send_cb(void) { Serial.printf("\r\n[Lora]Back to Rx mode %s", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); } -bool init_lora(double freq) -{ +bool init_lora(double freq) { - if (api.lorawan.nwm.get() != 0) - { + if (api.lora.nwm.get() != 0) { Serial.printf("Set Node device work mode %s\r\n", - api.lorawan.nwm.set(0) ? "Success" : "Fail"); + api.lora.nwm.set() ? "Success" : "Fail"); api.system.reboot(); } @@ -61,38 +54,35 @@ bool init_lora(double freq) Serial.printf("AT Command Version: %s\r\n", api.system.cliVersion.get().c_str()); Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (freq / 1e6), - api.lorawan.pfreq.set(freq) ? "Success" : "Fail"); + api.lora.pfreq.set(freq) ? "Success" : "Fail"); Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf, - api.lorawan.psf.set(sf) ? "Success" : "Fail"); + api.lora.psf.set(sf) ? "Success" : "Fail"); Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw, - api.lorawan.pbw.set(bw) ? "Success" : "Fail"); + api.lora.pbw.set(bw) ? "Success" : "Fail"); Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5), - api.lorawan.pcr.set(cr) ? "Success" : "Fail"); + api.lora.pcr.set(cr) ? "Success" : "Fail"); Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble, - api.lorawan.ppl.set(preamble) ? "Success" : "Fail"); + api.lora.ppl.set(preamble) ? "Success" : "Fail"); Serial.printf("Set P2P mode tx power %ddB: %s\r\n", txPower, - api.lorawan.ptp.set(txPower) ? "Success" : "Fail"); - api.lorawan.registerPRecvCallback(recv_cb); - api.lorawan.registerPSendCallback(send_cb); + api.lora.ptp.set(txPower) ? "Success" : "Fail"); + api.lora.registerPRecvCallback(recv_cb); + api.lora.registerPSendCallback(send_cb); Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(65534) ? "Success" : "Fail"); + api.lora.precv(65534) ? "Success" : "Fail"); delay(1000); return true; } -bool lora_send(int size_msg, uint8_t *msg) -{ +bool lora_send(int size_msg, uint8_t *msg) { Serial.printf("\r\n[Lora]P2P sending..."); bool send_result = false; int count = 0; - api.lorawan.precv(0); - while (!send_result) - { - send_result = api.lorawan.psend(size_msg, msg); + api.lora.precv(0); + while (!send_result) { + send_result = api.lora.psend(size_msg, msg); delay(1); count++; - if (count > 2000) - { + if (count > 2000) { Serial.printf("\r\n[Lora]P2P send Fail"); return false; } diff --git a/examples/Rak2Ra02/Rak3172/Rak3172.ino b/examples/Rak2Ra02/Rak3172/Rak3172.ino index 60daa93..adad1c7 100644 --- a/examples/Rak2Ra02/Rak3172/Rak3172.ino +++ b/examples/Rak2Ra02/Rak3172/Rak3172.ino @@ -58,22 +58,22 @@ void recv_cb(rui_lora_p2p_recv_t data) void send_cb(void) { Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(3000) ? "Success" : "Fail"); + api.lora.precv(3000) ? "Success" : "Fail"); } void setup() { init_io(); Serial.begin(115200); - Serial.println("RAK3172_Canopus LoRaWan P2P Example"); + Serial.println("RAK3172_Canopus lora P2P Example"); Serial.println("------------------------------------------------------"); delay(2000); startTime = millis(); - if (api.lorawan.nwm.get() != 0) + if (api.lora.nwm.get() != 0) { Serial.printf("Set Node device work mode %s\r\n", - api.lorawan.nwm.set(0) ? "Success" : "Fail"); + api.lora.nwm.set() ? "Success" : "Fail"); api.system.reboot(); } @@ -87,21 +87,21 @@ void setup() Serial.printf("AT Command Version: %s\r\n", api.system.cliVersion.get().c_str()); Serial.printf("Set P2P mode frequency %3.3f: %s\r\n", (myFreq / 1e6), - api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail"); + api.lora.pfreq.set(myFreq) ? "Success" : "Fail"); Serial.printf("Set P2P mode spreading factor %d: %s\r\n", sf, - api.lorawan.psf.set(sf) ? "Success" : "Fail"); + api.lora.psf.set(sf) ? "Success" : "Fail"); Serial.printf("Set P2P mode bandwidth %d: %s\r\n", bw, - api.lorawan.pbw.set(bw) ? "Success" : "Fail"); + api.lora.pbw.set(bw) ? "Success" : "Fail"); Serial.printf("Set P2P mode code rate 4/%d: %s\r\n", (cr + 5), - api.lorawan.pcr.set(cr) ? "Success" : "Fail"); + api.lora.pcr.set(cr) ? "Success" : "Fail"); Serial.printf("Set P2P mode preamble length %d: %s\r\n", preamble, - api.lorawan.ppl.set(preamble) ? "Success" : "Fail"); + api.lora.ppl.set(preamble) ? "Success" : "Fail"); Serial.printf("Set P2P mode tx power %d: %s\r\n", txPower, - api.lorawan.ptp.set(txPower) ? "Success" : "Fail"); - api.lorawan.registerPRecvCallback(recv_cb); - api.lorawan.registerPSendCallback(send_cb); + api.lora.ptp.set(txPower) ? "Success" : "Fail"); + api.lora.registerPRecvCallback(recv_cb); + api.lora.registerPSendCallback(send_cb); Serial.printf("P2P set Rx mode %s\r\n", - api.lorawan.precv(3000) ? "Success" : "Fail"); + api.lora.precv(3000) ? "Success" : "Fail"); // let's kick-start things by waiting 3 seconds. } @@ -114,11 +114,11 @@ void loop() rx_done = false; while (!send_result) { - send_result = api.lorawan.psend(sizeof(payload), payload); + send_result = api.lora.psend(sizeof(payload), payload); Serial.printf("P2P send %s\r\n", send_result ? "Success" : "Fail"); if (!send_result) { - Serial.printf("P2P finish Rx mode %s\r\n", api.lorawan.precv(0) ? "Success" : "Fail"); + Serial.printf("P2P finish Rx mode %s\r\n", api.lora.precv(0) ? "Success" : "Fail"); delay(1000); } }