-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from core-rocket/dev_main
メイン電装統合
- Loading branch information
Showing
6 changed files
with
514 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#define Serial_ES920 Serial1 | ||
bool need_uplink = false; | ||
String uplink_string = ""; | ||
typedef enum { | ||
SENDING, | ||
FREE | ||
} MODE; | ||
MODE mode = FREE; | ||
uint32_t send_millis = millis(); | ||
uint32_t timeout_ms = 3000; | ||
|
||
void setup() { | ||
//Serial.setFIFOSize(64); | ||
Serial.begin(115200); | ||
|
||
Serial_ES920.begin(115200); | ||
while (Serial_ES920.available()) { | ||
Serial_ES920.read(); | ||
} | ||
} | ||
|
||
void loop() { | ||
while (Serial.available()) { | ||
uplink_string = Serial.readStringUntil('\n'); | ||
uplink_string.trim(); | ||
need_uplink = true; | ||
} | ||
|
||
if ((mode == FREE) && Serial_ES920.available()) { | ||
String downlink = Serial_ES920.readStringUntil('\n'); | ||
// Serial.print("raw:"); | ||
// Serial.println(downlink); | ||
downlink.trim(); | ||
|
||
char rssi_char[] = "FFFF"; | ||
downlink.substring(0, 4).toCharArray(rssi_char, 5); | ||
int16_t rssi_long = rssi(rssi_char); | ||
|
||
String downlink_ASCII = downlink.substring(4, downlink.length()); | ||
|
||
Serial.print(rssi_long); | ||
Serial.print(","); | ||
Serial.println(downlink_ASCII); | ||
|
||
if (need_uplink) { | ||
delay(50); | ||
need_uplink = false; | ||
Serial_ES920.println(uplink_string); | ||
mode = SENDING; | ||
send_millis = millis(); | ||
Serial.print("uplink "); | ||
Serial.println(uplink_string); | ||
} | ||
} | ||
|
||
if (mode == SENDING) { | ||
if (Serial_ES920.available()) { | ||
String response = Serial_ES920.readStringUntil('\n'); | ||
response.trim(); | ||
mode = FREE; | ||
Serial.print("response from ES920LR:"); | ||
Serial.println(response); | ||
} | ||
if (millis() - send_millis > timeout_ms) { | ||
mode = FREE; | ||
Serial.print("timeout"); | ||
} | ||
} | ||
} | ||
|
||
int16_t rssi(char *_rssi_char) { | ||
char *e; | ||
return strtol(_rssi_char, &e, 16) - 65536; | ||
} | ||
|
||
// GROUND | ||
// configuration setting is below. | ||
// ------------------------------------- | ||
// Node : EndDevice | ||
// Band Width : 125kHz | ||
// Spreading Factor : 11 | ||
// Effective Bitrate : 537bps | ||
// Channel : 2 | ||
// PAN ID : 0001 | ||
// Own Node ID : 0001 | ||
// Destination ID : 0000 | ||
// Acknowledge : OFF | ||
// Retry count : 3 | ||
// Transfer Mode : Payload | ||
// Receive Node ID information : OFF | ||
// RSSI information : ON | ||
// Config/Operation : Operation | ||
// UART baudrate : 115200 | ||
// Sleep Mode : No Sleep | ||
// Sleep Time : 50 | ||
// Output Power : 13dBm | ||
// Format : ASCII | ||
// Send Time : 0 | ||
// Send Data : | ||
// AES Key : 00000000000000000000000000000000 | ||
// RF Mode : TxRx | ||
// Protocol Type : Private LoRa | ||
// Rx Boosted : ON |
Oops, something went wrong.