Add autoswitch on RX (need correct control packet)
parent
adf79c852f
commit
fa75807196
|
@ -1,10 +1,10 @@
|
|||
|
||||
#ifndef BUILD_NUMBER
|
||||
#define BUILD_NUMBER "205"
|
||||
#endif
|
||||
#ifndef VERSION
|
||||
#define VERSION "v0.3.2.205-0b37f35 - 2021-09-12 22:52:51.018351"
|
||||
#endif
|
||||
#ifndef VERSION_SHORT
|
||||
#define VERSION_SHORT "v0.3.2.205-0b37f35"
|
||||
#endif
|
||||
|
||||
#ifndef BUILD_NUMBER
|
||||
#define BUILD_NUMBER "20"
|
||||
#endif
|
||||
#ifndef VERSION
|
||||
#define VERSION "v0.3.2.20-adf79c8 - 2021-09-13 11:57:57.529546"
|
||||
#endif
|
||||
#ifndef VERSION_SHORT
|
||||
#define VERSION_SHORT "v0.3.2.20-adf79c8"
|
||||
#endif
|
||||
|
|
|
@ -29,11 +29,14 @@ String decapsulateKISS_pkt(const String &frame);
|
|||
*/
|
||||
|
||||
|
||||
String encode_kiss_pkt(const String &tnc2FormattedFrame)
|
||||
String encode_kiss_pkt(const String &tnc2FormattedFrame, bool &pktFrame)
|
||||
{
|
||||
String TNC2Frame = "";
|
||||
pktFrame = tnc2FormattedFrame.charAt(2) == R_PKT;
|
||||
if (pktFrame) {
|
||||
String ax25Frame = encapsulateKISS_pkt(tnc2FormattedFrame, CMD_DATA);
|
||||
TNC2Frame += ax25Frame;
|
||||
}
|
||||
return TNC2Frame;
|
||||
}
|
||||
|
||||
|
@ -97,7 +100,7 @@ String decode_kiss_pkt(const String &inputKISSTNCFrame, bool &dataFrame, bool &p
|
|||
if (validateKISSFrame_pkt(inputKISSTNCFrame)) {
|
||||
dataFrame = inputKISSTNCFrame.charAt(1) == CMD_DATA;
|
||||
// Auto switch to packet mode if find cmd data.
|
||||
if (inputKISSTNCFrame.charAt(2) == U_PKT) { pktFrame = true;}
|
||||
if (inputKISSTNCFrame.charAt(2) == T_PKT) { pktFrame = true;}
|
||||
else { pktFrame = false; }
|
||||
//END
|
||||
if (dataFrame && pktFrame){
|
||||
|
|
|
@ -1,33 +1,12 @@
|
|||
#include <Arduino.h>
|
||||
#include "KISS.h"
|
||||
|
||||
#define APRS_CONTROL_FIELD 0xf0
|
||||
#define APRS_INFORMATION_FIELD 0xf0
|
||||
|
||||
#define HAS_BEEN_DIGIPITED_MASK 0b10000000
|
||||
#define IS_LAST_ADDRESS_POSITION_MASK 0b1
|
||||
//Data control frames, ported from Direwolf
|
||||
//U-Frames
|
||||
#define U_SABME 0x6f
|
||||
#define U_SABM 0x3f //ok
|
||||
#define U_DISC 0x53 //ok
|
||||
#define U_DM 0x1f //need test
|
||||
#define U_UA 0x73 //ok
|
||||
#define U_FRMR 0x97 //need test
|
||||
#define U_UI 0x13 //need test
|
||||
#define U_XID 0xbf //need test
|
||||
#define U_TEST 0xf3 //need test
|
||||
#define U_PKT 0xaa
|
||||
//S-Frames
|
||||
#define S_RR 0x11 //need test
|
||||
#define S_RNR 0x15 //need test
|
||||
#define S_REJ 0x19 //need test
|
||||
#define S_SREJ 0x1d //need test
|
||||
//I-Frame
|
||||
#define I_I 0xcf //need test
|
||||
#define T_PKT 0xaa
|
||||
#define R_PKT 0x01
|
||||
//END
|
||||
//PACKET MODE
|
||||
String encode_kiss_pkt(const String& tnc2FormattedFrame);
|
||||
String encode_kiss_pkt(const String& tnc2FormattedFrame, bool &pktFrame);
|
||||
String decode_kiss_pkt(const String &inputKISSTNCFrame, bool &dataFrame, bool &pktFrame);
|
||||
|
||||
String encapsulateKISS_pkt(const String &ax25Frame, uint8_t TNCCmd);
|
|
@ -66,26 +66,19 @@ String encode_kiss(const String &tnc2FormattedFrame) {
|
|||
return kissFrame;
|
||||
}
|
||||
|
||||
String encapsulateKISS(const String &ax25Frame, uint8_t TNCCmd)
|
||||
{
|
||||
String encapsulateKISS(const String &ax25Frame, uint8_t TNCCmd) {
|
||||
String kissFrame = "";
|
||||
kissFrame += (char) FEND; // start of frame
|
||||
kissFrame += (char) (0x0f & TNCCmd); // TNC0, cmd
|
||||
for (int i = 0; i < ax25Frame.length(); ++i)
|
||||
{
|
||||
for (int i = 0; i < ax25Frame.length(); ++i) {
|
||||
char currentChar = ax25Frame.charAt(i);
|
||||
if (currentChar == (char) FEND)
|
||||
{
|
||||
if (currentChar == (char) FEND) {
|
||||
kissFrame += (char) FESC;
|
||||
kissFrame += (char) TFEND;
|
||||
}
|
||||
else if (currentChar == (char) FESC)
|
||||
{
|
||||
} else if (currentChar == (char) FESC) {
|
||||
kissFrame += (char) FESC;
|
||||
kissFrame += (char) TFESC;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
kissFrame += currentChar;
|
||||
}
|
||||
}
|
||||
|
@ -94,30 +87,23 @@ String encapsulateKISS(const String &ax25Frame, uint8_t TNCCmd)
|
|||
}
|
||||
|
||||
|
||||
String decapsulateKISS(const String &frame)
|
||||
{
|
||||
String decapsulateKISS(const String &frame) {
|
||||
String ax25Frame = "";
|
||||
for (int i = 2; i < frame.length() - 1; ++i)
|
||||
{
|
||||
for (int i = 2; i < frame.length() - 1; ++i) {
|
||||
char currentChar = frame.charAt(i);
|
||||
if (currentChar == (char) FESC)
|
||||
{
|
||||
if (currentChar == (char) FESC) {
|
||||
char nextChar = frame.charAt(i + 1);
|
||||
if (nextChar == (char) TFEND)
|
||||
{
|
||||
if (nextChar == (char) TFEND) {
|
||||
ax25Frame += (char) FEND;
|
||||
}
|
||||
else if (nextChar == (char) TFESC)
|
||||
{
|
||||
} else if (nextChar == (char) TFESC) {
|
||||
ax25Frame += (char) FESC;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
ax25Frame += currentChar;
|
||||
}
|
||||
}
|
||||
|
||||
return ax25Frame;
|
||||
}
|
||||
|
||||
|
@ -220,11 +206,10 @@ String decode_address_ax25(const String &ax25Address, bool &isLast, bool isRelay
|
|||
}
|
||||
|
||||
bool validateTNC2Frame(const String &tnc2FormattedFrame) {
|
||||
return (tnc2FormattedFrame.indexOf(':') != -1) &&
|
||||
(tnc2FormattedFrame.indexOf('>') != -1);
|
||||
return (tnc2FormattedFrame.indexOf(':') != -1) && (tnc2FormattedFrame.indexOf('>') != -1);
|
||||
}
|
||||
|
||||
bool validateKISSFrame(const String &kissFormattedFrame) {
|
||||
return kissFormattedFrame.charAt(0) == (char) FEND &&
|
||||
kissFormattedFrame.charAt(kissFormattedFrame.length() - 1) == (char) FEND;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
#include <Arduino.h>
|
||||
#include "KISS.h"
|
||||
|
||||
#define APRS_CONTROL_FIELD 0xf0
|
||||
#define APRS_CONTROL_FIELD 0x03
|
||||
#define APRS_INFORMATION_FIELD 0xf0
|
||||
|
||||
#define HAS_BEEN_DIGIPITED_MASK 0b10000000
|
||||
|
|
|
@ -98,11 +98,33 @@ void handleKISSData(char character, int bufferIndex) {
|
|||
handleKISSData(character, 1);
|
||||
}
|
||||
}, nullptr, clients, MAX_WIFI_CLIENTS);
|
||||
|
||||
#endif
|
||||
|
||||
if (xQueueReceive(tncReceivedQueue, &loraReceivedFrameString, (1 / portTICK_PERIOD_MS)) == pdPASS) {
|
||||
const String &kissEncoded = encode_kiss_pkt(*loraReceivedFrameString);
|
||||
bool isPacketFrame = false;
|
||||
if (isPacketFrame) {
|
||||
const String &kissEncoded_pkt = encode_kiss_pkt(*loraReceivedFrameString, isPacketFrame);
|
||||
//Serial.print(kissEncoded_pkt);
|
||||
Serial.print("PACKET MODE");
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (SerialBT.hasClient()){
|
||||
SerialBT.print(kissEncoded_pkt);
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_WIFI
|
||||
iterateWifiClients([](WiFiClient *client, int clientIdx, const String *data){
|
||||
if (client->connected()){
|
||||
client->print(*data);
|
||||
client->flush();
|
||||
}
|
||||
}, &kissEncoded_pkt, clients, MAX_WIFI_CLIENTS);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
const String &kissEncoded = encode_kiss(*loraReceivedFrameString);
|
||||
Serial.print(kissEncoded);
|
||||
//Serial.print("OPEN MODE");
|
||||
#ifdef ENABLE_BLUETOOTH
|
||||
if (SerialBT.hasClient()){
|
||||
SerialBT.print(kissEncoded);
|
||||
|
@ -116,7 +138,7 @@ void handleKISSData(char character, int bufferIndex) {
|
|||
}
|
||||
}, &kissEncoded, clients, MAX_WIFI_CLIENTS);
|
||||
#endif
|
||||
|
||||
}
|
||||
delete loraReceivedFrameString;
|
||||
}
|
||||
vTaskDelay(50 / portTICK_PERIOD_MS);
|
||||
|
|
Loading…
Reference in New Issue