Browse Source

Version 0.4.0: Added packet mode for BBS and Winlink nodes, now you can build own BBS/WINLINK gateway and connect to the this LoRa KISS TNC.

master
US1GHQ 1 month ago
parent
commit
9d9f780264
  1. 1
      include/taskTNC.h
  2. 124
      lib/KISS_TO_TNC2/KISS_TO_PKT.cpp
  3. 12
      lib/KISS_TO_TNC2/KISS_TO_PKT.h
  4. 38
      lib/KISS_TO_TNC2/KISS_TO_TNC2.cpp
  5. 5
      lib/KISS_TO_TNC2/KISS_TO_TNC2.h
  6. 55
      src/taskTNC.cpp
  7. 4
      tools/buildscript_versioning.py

1
include/taskTNC.h

@ -1,6 +1,5 @@
#include <Arduino.h>
#include <KISS_TO_TNC2.h>
#include <KISS_TO_PKT.h>
#if defined(ENABLE_BLUETOOTH)
#include "BluetoothSerial.h"

124
lib/KISS_TO_TNC2/KISS_TO_PKT.cpp

@ -1,124 +0,0 @@
#include "KISS_TO_PKT.h"
bool validateTNC2Frame_pkt(const String &tnc2FormattedFrame);
bool validateKISSFrame_pkt(const String &kissFormattedFrame);
String decapsulateKISS_pkt(const String &frame);
/*
* https://ham.zmailer.org/oh2mqk/aprx/PROTOCOLS
After successfull login, communication carries "TNC2" format
APRS messages. Namely text encoding of AX.25 UI frames in
what became known as "TNC2 monitor style":
SOURCE>DESTIN:payload
SOURCE>DESTIN,VIA,VIA:payload
The SOURCE, DESTIN, and VIA fields are AX.25 address fields,
and have "-SSID" value annexed if the SSID is not zero.
Also in VIA-fields, if the "HAS BEEN DIGIPEATED" bit is set
(AX.25 v2 protocol feature) a star ('*') character is appended.
VIA-fields are separated by comma (',') from DESTIN, and each
other.
A double-colon (':') separates address data from payload.
The payload is passed _AS_IS_ without altering any message
content bytes, however ending at first CR or LF character
encountered in the packet.
*/
String encode_kiss_pkt(const String &tnc2FormattedFrame, bool &pktFrame)
{
String TNC2Frame = "";
// Serial.print(tnc2FormattedFrame);
pktFrame = tnc2FormattedFrame.charAt(1) == R_PKT;
if (pktFrame) {
String ax25Frame = encapsulateKISS_pkt(tnc2FormattedFrame, CMD_DATA);
TNC2Frame += ax25Frame;
}
return TNC2Frame;
}
String encapsulateKISS_pkt(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)
{
char currentChar = ax25Frame.charAt(i);
if (currentChar == (char) FEND)
{
kissFrame += (char) FESC;
kissFrame += (char) TFEND;
}
else if (currentChar == (char) FESC)
{
kissFrame += (char) FESC;
kissFrame += (char) TFESC;
}
else
{
kissFrame += currentChar;
}
}
kissFrame += (char) FEND; // end of frame
return kissFrame;
}
String decapsulateKISS_pkt(const String &frame, uint8_t TNCCmd)
{
String ax25Frame = "";
for (int i = 2; i < frame.length() - 1; ++i)
{
char currentChar = frame.charAt(i);
if (currentChar == (char)FESC)
{
char nextChar = frame.charAt(i + 1);
if (nextChar == (char)TFEND)
{
ax25Frame += (char)FEND;
}
else if (nextChar == (char)TFESC)
{
ax25Frame += (char)FESC;
}
++i;
}
else
{
ax25Frame += currentChar;
}
}
return ax25Frame;
}
String decode_kiss_pkt(const String &inputKISSTNCFrame, bool &dataFrame, bool &pktFrame) {
String TNC2Frame = "";
if (validateKISSFrame_pkt(inputKISSTNCFrame)) {
dataFrame = inputKISSTNCFrame.charAt(1) == CMD_DATA;
// Auto switch to packet mode if find cmd data.
if (inputKISSTNCFrame.charAt(2) == T_PKT) { pktFrame = true;}
else { pktFrame = false; }
//END
if (dataFrame && pktFrame){
String ax25Frame = decapsulateKISS_pkt(inputKISSTNCFrame, CMD_DATA);
delay(250);
TNC2Frame += ax25Frame;
}
}
return TNC2Frame;
}
bool validateTNC2Frame_pkt(const String &tnc2FormattedFrame) {
return (tnc2FormattedFrame.indexOf(':') != -1) &&
(tnc2FormattedFrame.indexOf('>') != -1);
}
bool validateKISSFrame_pkt(const String &kissFormattedFrame) {
return kissFormattedFrame.charAt(0) == (char) FEND &&
kissFormattedFrame.charAt(kissFormattedFrame.length() - 1) == (char) FEND;
}

12
lib/KISS_TO_TNC2/KISS_TO_PKT.h

@ -1,12 +0,0 @@
#include <Arduino.h>
#include "KISS.h"
//Data control frames, ported from Direwolf
#define T_PKT 0xaa
#define R_PKT 0xa6
//END
//PACKET MODE
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);

38
lib/KISS_TO_TNC2/KISS_TO_TNC2.cpp

@ -33,18 +33,12 @@ String decapsulateKISS(const String &frame);
*/
<<<<<<< HEAD
String encode_kiss(const String &tnc2FormattedFrame) {
String ax25Frame = "";
=======
String encode_kiss(const String &tnc2FormattedFrame, bool &pktFrame) {
pktFrame = tnc2FormattedFrame.charAt(1) == R_PKT;
String TNC2Frame = "";
String ax25Frame = "";
if (!pktFrame) {
>>>>>>> remotes/origin/KISS_TNC
if (validateTNC2Frame(tnc2FormattedFrame)) {
String address = "";
bool dst_addres_written = false;
@ -70,12 +64,6 @@ String encode_kiss(const String &tnc2FormattedFrame, bool &pktFrame) {
ax25Frame += (char) APRS_INFORMATION_FIELD;
ax25Frame += tnc2FormattedFrame.substring(tnc2FormattedFrame.indexOf(':') + 1);
}
<<<<<<< HEAD
String kissFrame = encapsulateKISS(ax25Frame, CMD_DATA);
return kissFrame;
}
=======
String kissFrame = encapsulateKISS(ax25Frame, CMD_DATA);
return kissFrame;
}
@ -86,7 +74,6 @@ String encode_kiss(const String &tnc2FormattedFrame, bool &pktFrame) {
return TNC2Frame;
}
}
>>>>>>> remotes/origin/KISS_TNC
String encapsulateKISS(const String &ax25Frame, uint8_t TNCCmd) {
String kissFrame = "";
@ -135,35 +122,11 @@ String decapsulateKISS(const String &frame) {
* @param dataFrame
* @return Decapsulated TNC2KISS APRS data frame, or raw command data frame
*/
<<<<<<< HEAD
String decode_kiss(const String &inputKISSTNCFrame, bool &dataFrame) {
=======
String decode_kiss(const String &inputKISSTNCFrame, bool &dataFrame, bool &pktFrame) {
>>>>>>> remotes/origin/KISS_TNC
String TNC2Frame = "";
if (validateKISSFrame(inputKISSTNCFrame)) {
dataFrame = inputKISSTNCFrame.charAt(1) == CMD_DATA;
<<<<<<< HEAD
if (dataFrame){
String ax25Frame = decapsulateKISS(inputKISSTNCFrame);
bool isLast = false;
String dst_addr = decode_address_ax25(ax25Frame.substring(0, 7), isLast, false);
String src_addr = decode_address_ax25(ax25Frame.substring(7, 14), isLast, false);
TNC2Frame = src_addr + ">" + dst_addr;
int digi_info_index = 14;
while (!isLast && digi_info_index + 7 < ax25Frame.length()) {
String digi_addr = decode_address_ax25(ax25Frame.substring(digi_info_index, digi_info_index + 7), isLast, true);
TNC2Frame += ',' + digi_addr;
digi_info_index += 7;
}
TNC2Frame += ':';
TNC2Frame += ax25Frame.substring(digi_info_index + 2);
} else {
// command frame, currently ignored
TNC2Frame += inputKISSTNCFrame;
}
=======
pktFrame = inputKISSTNCFrame.charAt(2) == T_PKT;
if (dataFrame && pktFrame) {
String ax25Frame = decapsulateKISS(inputKISSTNCFrame);
@ -188,7 +151,6 @@ String decode_kiss(const String &inputKISSTNCFrame, bool &dataFrame, bool &pktFr
// command frame, currently ignored
TNC2Frame += inputKISSTNCFrame;
}
>>>>>>> remotes/origin/KISS_TNC
}
return TNC2Frame;
}

5
lib/KISS_TO_TNC2/KISS_TO_TNC2.h

@ -7,12 +7,7 @@
#define HAS_BEEN_DIGIPITED_MASK 0b10000000
#define IS_LAST_ADDRESS_POSITION_MASK 0b1
<<<<<<< HEAD
String encode_kiss(const String& tnc2FormattedFrame);
String decode_kiss(const String &inputKISSTNCFrame, bool &dataFrame);
=======
String encode_kiss(const String& tnc2FormattedFrame, bool &pktFrame);
String decode_kiss(const String &inputKISSTNCFrame, bool &dataFrame, bool &pktFrame);
>>>>>>> remotes/origin/KISS_TNC
String encapsulateKISS(const String &ax25Frame, uint8_t TNCCmd);

55
src/taskTNC.cpp

@ -33,48 +33,20 @@ void handleKISSData(char character, int bufferIndex) {
return;
}
inTNCData->concat(character);
<<<<<<< HEAD
if (character == (char) FEND && inTNCData->length() > 3)
{
bool isDataFrame = false;
bool isPacketFrame = false;
const String &TNC2DataFrame = decode_kiss_pkt(*inTNCData, isDataFrame, isPacketFrame);
if (isDataFrame && isPacketFrame) {
auto *buffer = new String();
buffer->concat(TNC2DataFrame);
if (xQueueSend(tncToSendQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS)
{
delete buffer;
}
inTNCData->clear();
}
else if (character == (char) FEND && inTNCData->length() > 3)
{
bool isDataFrame = false;
const String &TNC2DataFrame = decode_kiss(*inTNCData, isDataFrame);
=======
if (character == (char) FEND && inTNCData->length() > 3) {
bool isDataFrame = false;
bool isPacketFrame = false;
const String &TNC2DataFrame = decode_kiss(*inTNCData, isDataFrame, isPacketFrame);
>>>>>>> remotes/origin/KISS_TNC
if (isDataFrame) {
auto *buffer = new String();
buffer->concat(TNC2DataFrame);
<<<<<<< HEAD
if (xQueueSend(tncToSendQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS)
{
=======
if (xQueueSend(tncToSendQueue, &buffer, (1000 / portTICK_PERIOD_MS)) != pdPASS) {
>>>>>>> remotes/origin/KISS_TNC
delete buffer;
}
}
inTNCData->clear();
}
}
if (inTNCData->length() > 255){
// just in case of garbage input reset data
inTNCData->clear();
@ -113,30 +85,7 @@ void handleKISSData(char character, int bufferIndex) {
if (xQueueReceive(tncReceivedQueue, &loraReceivedFrameString, (1 / portTICK_PERIOD_MS)) == pdPASS) {
bool isPacketFrame = false;
<<<<<<< HEAD
const String &kissEncoded_pkt = encode_kiss_pkt(*loraReceivedFrameString, isPacketFrame);
const String &kissEncoded = encode_kiss(*loraReceivedFrameString);
if (isPacketFrame) {
Serial.print(kissEncoded_pkt);
#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, isPacketFrame);
>>>>>>> remotes/origin/KISS_TNC
Serial.print(kissEncoded);
#ifdef ENABLE_BLUETOOTH
if (SerialBT.hasClient()){
@ -151,10 +100,6 @@ void handleKISSData(char character, int bufferIndex) {
}
}, &kissEncoded, clients, MAX_WIFI_CLIENTS);
#endif
<<<<<<< HEAD
}
=======
>>>>>>> remotes/origin/KISS_TNC
delete loraReceivedFrameString;
}
vTaskDelay(50 / portTICK_PERIOD_MS);

4
tools/buildscript_versioning.py

@ -1,10 +1,6 @@
FILENAME_BUILDNO = '.pio/versioning'
FILENAME_VERSION_H = 'include/version.h'
<<<<<<< HEAD
version = 'v0.4.0.'
=======
version = 'v0.3.2.'
>>>>>>> remotes/origin/KISS_TNC
import datetime
from subprocess import *

Loading…
Cancel
Save