first Draft of UART for external LoRa-Module

This commit is contained in:
2023-05-25 14:00:06 +02:00
parent cd1379f90c
commit f727bb3247
5 changed files with 98 additions and 10 deletions

View File

@@ -1,13 +1,19 @@
#include "lora_net.h"
#ifdef FEATURE_ENABLE_LORA
LoRa_E220 e220ttl(GPIO_LORA_TX, GPIO_LORA_RX, GPIO_LORA_AUX, 3, 4); // Arduino RX <-- e220 TX, Arduino TX --> e220 RX AUX M0 M1
void printParameters(struct Configuration configuration);
void printModuleInformation(struct ModuleInformation moduleInformation);
#elif defined(FEATURE_ENABLE_UARTLORA)
SoftwareSerial SerialLoRa(GPIO_LORA_RX, GPIO_LORA_TX); // RX, TX
void Parse_LoRa_UartCommand(char input[], int size);
#endif
bool InitLoRa(void (*MPinHelper)(int, int))
{
bool returnval;
bool returnval = false;
#ifdef FEATURE_ENABLE_LORA
e220ttl.setMPins = MPinHelper;
returnval = e220ttl.begin();
@@ -60,11 +66,15 @@ bool InitLoRa(void (*MPinHelper)(int, int))
{
MaintainDTC(DTC_NO_LORA_FOUND, DTC_WARN, true);
}
#elif defined(FEATURE_ENABLE_UARTLORA)
// LORA UART Stuff here
#endif
return returnval;
}
void LoRa_Process()
{
#ifdef FEATURE_ENABLE_LORA
if (e220ttl.available() > 1)
{
ResponseContainer rc = e220ttl.receiveMessageRSSI();
@@ -82,10 +92,50 @@ void LoRa_Process()
Serial.println(rc.rssi, DEC);
}
}
#elif defined(FEATURE_ENABLE_UARTLORA)
char packageInput[16];
bool packageRecieved = false;
unsigned int bufferPtr = 0;
if (SerialLoRa.available() && packageRecieved == false)
{
while (bufferPtr < sizeof(packageInput))
{
packageInput[bufferPtr] = SerialLoRa.read();
if (packageInput[bufferPtr] == '\n')
{
packageInput[bufferPtr] = 0; // terminate String
packageRecieved = true;
Debug_pushMessage("Got LoRa UART: %s\n", packageInput);
break;
}
else if ((packageInput[bufferPtr] >= 0x30) || (packageInput[bufferPtr] <= 0x5A)) // only accept Numbers, UpperCase-Letters and some special chars
{
if (bufferPtr < sizeof(packageInput) - 1)
{
bufferPtr++;
}
else
{
packageInput[bufferPtr] = 0; // terminate String, bc Buffer is full (package to long)
packageRecieved = true; // send it anyway to the parser
Debug_pushMessage("Got LoRa UART: %s\n", packageInput);
break;
}
}
}
}
if (packageRecieved)
Parse_LoRa_UartCommand(packageInput, bufferPtr);
#endif
}
void sendStatus_LoRa()
{
#ifdef FEATURE_ENABLE_LORA
struct
{
MessageType_t type = "STATUS";
@@ -101,8 +151,13 @@ void sendStatus_LoRa()
ResponseStatus rs = e220ttl.sendFixedMessage(0xFF, 0xFF, 23, (byte *)&sendStatus, sizeof(sendStatus));
Serial.println(rs.getResponseDescription());
#elif defined(FEATURE_ENABLE_UARTLORA)
// LORA UART SEND STUFF HERE
#endif
}
#ifdef FEATURE_ENABLE_LORA
void printParameters(struct Configuration configuration)
{
Serial.println("----------------------------------------");
@@ -168,4 +223,27 @@ void printParameters(struct Configuration configuration)
Serial.println(configuration.TRANSMISSION_MODE.getFixedTransmissionDescription());
Serial.println("----------------------------------------");
}
}
#endif
#ifdef FEATURE_ENABLE_UARTLORA
void Parse_LoRa_UartCommand(char input[], int size)
{
char delimiter[] = ";";
char *ptr;
char command[8];
char value[8];
ptr = strtok(input, delimiter);
while (ptr != NULL)
{
strncpy(command, ptr, sizeof(command));
ptr = strtok(NULL, delimiter);
strncpy(value, ptr, sizeof(value));
}
Debug_pushMessage("Parsed LoRa UART Command: %s Value: %s\n", command, value);
}
#endif