Browse Source

Start autoswitch from packet to aprs mode

KISS_TNC
US1GHQ 1 month ago
parent
commit
a5db0dd2a8
  1. 6
      include/version.h
  2. 15
      lib/KISS_TO_TNC2/KISS_TO_PKT.cpp
  3. 4
      lib/KISS_TO_TNC2/KISS_TO_PKT.h
  4. 20
      lib/KISS_TO_TNC2/KISS_TO_TNC2.h
  5. 25
      src/taskTNC.cpp

6
include/version.h

@ -1,10 +1,10 @@
#ifndef BUILD_NUMBER
#define BUILD_NUMBER "134"
#define BUILD_NUMBER "196"
#endif
#ifndef VERSION
#define VERSION "v0.3.2.134-0b37f35 - 2021-09-11 01:20:06.902654"
#define VERSION "v0.3.2.196-0b37f35 - 2021-09-12 22:09:49.680370"
#endif
#ifndef VERSION_SHORT
#define VERSION_SHORT "v0.3.2.134-0b37f35"
#define VERSION_SHORT "v0.3.2.196-0b37f35"
#endif

15
lib/KISS_TO_TNC2/KISS_TO_PKT.cpp

@ -28,7 +28,7 @@ String decapsulateKISS_pkt(const String &frame);
*/
//HACK for working Packet mode
String encode_kiss_pkt(const String &tnc2FormattedFrame)
{
String TNC2Frame = "";
@ -73,7 +73,7 @@ String decapsulateKISS_pkt(const String &frame, uint8_t TNCCmd)
char currentChar = frame.charAt(i);
if (currentChar == (char)FESC)
{
char nextChar = frame.charAt(i+1);
char nextChar = frame.charAt(i + 1);
if (nextChar == (char)TFEND)
{
ax25Frame += (char)FEND;
@ -92,12 +92,17 @@ String decapsulateKISS_pkt(const String &frame, uint8_t TNCCmd)
return ax25Frame;
}
//HACK for PACKEt MODE
String decode_kiss_pkt(const String &inputKISSTNCFrame, bool &dataFrame) {
String decode_kiss_pkt(const String &inputKISSTNCFrame, bool &dataFrame, bool &pktFrame) {
String TNC2Frame = "";
if (validateKISSFrame_pkt(inputKISSTNCFrame)) {
dataFrame = inputKISSTNCFrame.charAt(1) == CMD_DATA;
if (dataFrame){
// Auto switch to packet mode if find cmd data.
if (inputKISSTNCFrame.charAt(16) == U_SABM) { pktFrame = true;}
else if (inputKISSTNCFrame.charAt(16) == U_UA) { pktFrame = true;}
else if (inputKISSTNCFrame.charAt(16) == I_I) { pktFrame = true;}
else { pktFrame = false; }
//END
if (dataFrame && pktFrame){
String ax25Frame = decapsulateKISS_pkt(inputKISSTNCFrame, CMD_DATA);
delay(250);
TNC2Frame += ax25Frame;

4
lib/KISS_TO_TNC2/KISS_TO_PKT.h

@ -23,10 +23,10 @@
#define S_REJ 0x19 //need test
#define S_SREJ 0x1d //need test
//I-Frame
#define I_I 0xff //need test
#define I_I 0xcf //need test
//END
//PACKET MODE
String encode_kiss_pkt(const String& tnc2FormattedFrame);
String decode_kiss_pkt(const String &inputKISSTNCFrame, bool &dataFrame);
String decode_kiss_pkt(const String &inputKISSTNCFrame, bool &dataFrame, bool &pktFrame);
String encapsulateKISS_pkt(const String &ax25Frame, uint8_t TNCCmd);

20
lib/KISS_TO_TNC2/KISS_TO_TNC2.h

@ -6,25 +6,7 @@
#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
//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 0xff //need test
//END
String encode_kiss(const String& tnc2FormattedFrame);
String decode_kiss(const String &inputKISSTNCFrame, bool &dataFrame);

25
src/taskTNC.cpp

@ -27,38 +27,43 @@ QueueHandle_t tncToSendQueue = nullptr;
*/
void handleKISSData(char character, int bufferIndex) {
String *inTNCData = &inTNCDataBuffers[bufferIndex];
if (inTNCData->length() == 0 && character != (char) FEND){
if (inTNCData->length() == 0 && character != (char) FEND)
{
// kiss frame begins with C0
return;
}
inTNCData->concat(character);
if (character == (char) U_SABME && inTNCData->length() > 3) {
if (character == (char) FEND && inTNCData->length() > 3)
{
bool isDataFrame = false;
const String &TNC2DataFrame = decode_kiss_pkt(*inTNCData, isDataFrame);
bool isPacketFrame = false;
const String &TNC2DataFrame = decode_kiss_pkt(*inTNCData, isDataFrame, isPacketFrame);
if (isDataFrame) {
if (isDataFrame && isPacketFrame) {
auto *buffer = new String();
buffer->concat(TNC2DataFrame);
if (xQueueSend(tncToSendQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS) {
if (xQueueSend(tncToSendQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS)
{
delete buffer;
}
}
inTNCData->clear();
inTNCData->clear();
}
if (character == (char) FEND && inTNCData->length() > 3) {
else if (character == (char) FEND && inTNCData->length() > 3)
{
bool isDataFrame = false;
const String &TNC2DataFrame = decode_kiss(*inTNCData, isDataFrame);
if (isDataFrame) {
auto *buffer = new String();
buffer->concat(TNC2DataFrame);
if (xQueueSend(tncToSendQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS) {
if (xQueueSend(tncToSendQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS)
{
delete buffer;
}
}
inTNCData->clear();
}
}
if (inTNCData->length() > 255){
// just in case of garbage input reset data
inTNCData->clear();

Loading…
Cancel
Save