KISS diagnostics: decoding hex-encoded kiss request from aprs request and passing this to diagnotics engine

master
Mateusz Lubecki 2024-05-17 22:21:37 +02:00
rodzic 6a0766e22c
commit f93c4e553e
13 zmienionych plików z 216 dodań i 38 usunięć

16
.vscode/c_cpp_properties.json vendored 100644
Wyświetl plik

@ -0,0 +1,16 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": ["PARAMETEO", "STM32L471xx"],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}

28
.vscode/launch.json vendored 100644
Wyświetl plik

@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Debug STM32L476_ParaMETEO",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/STM32L476_ParaMETEO/ParaTNC.elf",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

12
.vscode/settings.json vendored 100644
Wyświetl plik

@ -0,0 +1,12 @@
{
"files.associations": {
"ax25_t.h": "c",
"*.tcc": "c",
"variant.h": "c",
"sim800c_tcpip.h": "c",
"rte_main.h": "c",
"config_data.h": "c",
"random": "c",
"message.h": "c"
}
}

35
.vscode/tasks.json vendored 100644
Wyświetl plik

@ -0,0 +1,35 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "make STM32L476_ParaMETEO",
"type": "shell",
"command": "make",
"args": [
"all"
],
"options": {
"cwd": "${workspaceFolder}/STM32L476_ParaMETEO"
},
"problemMatcher": [
"$gcc"
]
},
{
"label": "clean STM32L476_ParaMETEO",
"type": "shell",
"command": "make",
"args": [
"clean"
],
"options": {
"cwd": "${workspaceFolder}/STM32L476_ParaMETEO"
},
"problemMatcher": [
"$gcc"
]
}
]
}

Wyświetl plik

@ -6,18 +6,21 @@
C_SRCS += \
../src/kiss_protocol/kiss_callback.c \
../src/kiss_protocol/kiss_communication.c \
../src/kiss_protocol/kiss_communication_aprsmsg.c \
../src/kiss_protocol/kiss_did.c \
../src/kiss_protocol/kiss_nrc_response.c
OBJS += \
./src/kiss_protocol/kiss_callback.o \
./src/kiss_protocol/kiss_communication.o \
./src/kiss_protocol/kiss_communication_aprsmsg.o \
./src/kiss_protocol/kiss_did.o \
./src/kiss_protocol/kiss_nrc_response.o
C_DEPS += \
./src/kiss_protocol/kiss_callback.d \
./src/kiss_protocol/kiss_communication.d \
./src/kiss_protocol/kiss_communication_aprsmsg.d \
./src/kiss_protocol/kiss_did.d \
./src/kiss_protocol/kiss_nrc_response.d

Wyświetl plik

@ -79,6 +79,8 @@ typedef enum kiss_communication_aprsmsg_transport_t {
*/
APRSMSG_TRANSPORT_ERROR_UNSUPPORTED,
APRSMSG_TRANSPORT_NOT_KISS,
APRSMSG_TRANSPORT_UNINITIALIZED
} kiss_communication_aprsmsg_transport_t;

Wyświetl plik

@ -17,6 +17,8 @@
extern message_t rte_main_received_message;
extern message_t rte_main_message_for_transmitting;
//!< Trigger preparing and sending ACK
extern uint8_t rte_main_trigger_message_ack;

Wyświetl plik

@ -18,6 +18,8 @@
#include <stored_configuration_nvm/config_data_externs.h>
#include <stored_configuration_nvm/configuration_handler.h>
#include "variant.h"
extern unsigned short tx10m;
/**
@ -112,7 +114,7 @@ int32_t kiss_parse_received(uint8_t* input_frame_from_host, uint16_t input_len,
int32_t output = 0;
if (input_frame_from_host == 0x00 || ax25 == 0x00 || a == 0x00) {
if (variant_validate_is_within_ram(input_frame_from_host) == 0x00) {
output = -2;
}
else if (input_len >= OWN_APRS_MSG_LN) {
@ -132,33 +134,35 @@ int32_t kiss_parse_received(uint8_t* input_frame_from_host, uint16_t input_len,
switch (frame_type) {
case KISS_DATA: {
memset(FrameBuff, 0x00, OWN_APRS_MSG_LN);
if (variant_validate_is_within_ram(ax25) && variant_validate_is_within_ram(a)) {
memset(FrameBuff, 0x00, OWN_APRS_MSG_LN);
// if this is data frame
for (i=2, j=0; (i<input_len && *(input_frame_from_host+i) != FEND); i++, j++) {
if (*(input_frame_from_host+i) == FESC) {
if(*(input_frame_from_host+i+1) == TFEND)
FrameBuff[j]=FEND;
else if(*(input_frame_from_host+i+1) == TFESC)
FrameBuff[j]=FESC;
else {
;
// if this is data frame
for (i=2, j=0; (i<input_len && *(input_frame_from_host+i) != FEND); i++, j++) {
if (*(input_frame_from_host+i) == FESC) {
if(*(input_frame_from_host+i+1) == TFEND)
FrameBuff[j]=FEND;
else if(*(input_frame_from_host+i+1) == TFESC)
FrameBuff[j]=FESC;
else {
;
}
i++;
}
i++;
else
FrameBuff[j] = *(input_frame_from_host+i);
}
else
FrameBuff[j] = *(input_frame_from_host+i);
tx10m++;
// keep this commented until reseting the DCD variable will be moved outside main for (;;) loop
// while(ax25->dcd == true);
while(a->sending == true);
ax25_sendRaw(ax25,FrameBuff,j);
afsk_txStart(a);
}
tx10m++;
// keep this commented until reseting the DCD variable will be moved outside main for (;;) loop
// while(ax25->dcd == true);
while(a->sending == true);
ax25_sendRaw(ax25,FrameBuff,j);
afsk_txStart(a);
} break;
case KISS_GET_RUNNING_CONFIG: {

Wyświetl plik

@ -22,6 +22,10 @@
#define KISS_COMMUNICATION_APRSMSG_GET_CHAR(b) kiss_communication_aprsmsg_tohexstr_lookup_table[b]
#define KISS_COMMUNICATION_APRSMSG_IS_HEXSTRING(s) ((*(s) == 'H') && (*(s + 1) == 'S'))
#define KISS_COMMUNICATION_APRSMSG_IS_ENCR_HEXSTRING(s) (*(s) == 'P')
static uint8_t kiss_communication_aprsmsg_lookup_table[] =
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
-1, -1, -1, -1, -1, -1, -1,
@ -44,11 +48,19 @@ static uint8_t kiss_communication_aprsmsg_tohexstr_lookup_table[] =
*/
kiss_communication_aprsmsg_transport_t kiss_communication_aprsmsg_check_type(uint8_t * message_payload, uint16_t message_payload_ln)
{
kiss_communication_aprsmsg_transport_t out;
kiss_communication_aprsmsg_transport_t out = APRSMSG_TRANSPORT_UNINITIALIZED;
if (variant_validate_is_within_ram(message_payload) == 1 && message_payload_ln > 6) {
}
if (variant_validate_is_within_ram(message_payload) == 1 && message_payload_ln > 6 && message_payload_ln <= 67) {
if (KISS_COMMUNICATION_APRSMSG_IS_HEXSTRING(message_payload)) {
out = APRSMSG_TRANSPORT_HEXSTRING;
}
else if (KISS_COMMUNICATION_APRSMSG_IS_ENCR_HEXSTRING(message_payload)) {
out = APRSMSG_TRANSPORT_ERROR_UNSUPPORTED;
}
else {
out = APRSMSG_TRANSPORT_NOT_KISS;
}
}
return out;
}
@ -75,7 +87,7 @@ uint16_t kiss_communication_aprsmsg_decode_hexstring(uint8_t * message_payload,
uint8_t ln = 0;
// checck if input string is located in legoit RAM memory
if (variant_validate_is_within_ram(message_payload) == 1 && message_payload_ln > 6) {
if (variant_validate_is_within_ram(message_payload) == 1 && message_payload_ln > 0) {
// check second time of string begins with 'HS'
if (KISS_COMMUNICATION_APRSMSG_DEC_CURRENT_CHAR == 'H' && KISS_COMMUNICATION_APRSMSG_DEC_NEXT_CHAR == 'S') {

Wyświetl plik

@ -94,6 +94,7 @@
#include "drivers/dallas.h"
#include <kiss_communication/kiss_communication.h>
#include <kiss_communication/kiss_communication_aprsmsg.h>
#include <etc/kiss_configuation.h>
#include <etc/dallas_temperature_limits.h>
@ -194,27 +195,27 @@ int32_t main_ten_second_pool_timer = 10000;
int8_t main_one_hour_pool_timer = 60;
//! serial context for UART used to KISS
srl_context_t main_kiss_srl_ctx;
static srl_context_t main_kiss_srl_ctx;
//! serial context for UART used for comm with wx sensors
srl_context_t main_wx_srl_ctx;
static srl_context_t main_wx_srl_ctx;
#if defined(PARAMETEO)
//! serial context for communication with GSM module
srl_context_t main_gsm_srl_ctx;
static srl_context_t main_gsm_srl_ctx;
#endif
//! operation mode of USART1 (RS232 on RJ45 socket)
main_usart_mode_t main_usart1_kiss_mode = USART_MODE_UNDEF;
static main_usart_mode_t main_usart1_kiss_mode = USART_MODE_UNDEF;
//! operation mode of USART2 (RS485)
main_usart_mode_t main_usart2_wx_mode = USART_MODE_UNDEF;
static main_usart_mode_t main_usart2_wx_mode = USART_MODE_UNDEF;
//! function configuration for left button on ParaMETEO
configuration_button_function_t main_button_one_left;
static configuration_button_function_t main_button_one_left;
//! function configuration for right button on ParaMETEO
configuration_button_function_t main_button_two_right;
static configuration_button_function_t main_button_two_right;
//! a pointer to KISS context
srl_context_t* main_kiss_srl_ctx_ptr;
@ -256,6 +257,21 @@ char main_string_longitude[9];
char main_callsign_with_ssid[10];
uint8_t main_small_buffer[KISS_CONFIG_DIAGNOSTIC_BUFFER_LN];
#if defined(PARAMETEO)
//! Lenght of a buffer for KISS diagnostic request
#define MAIN_KISS_FROM_MESSAGE_LEN 33
//! KISS (diagnostic) request decoded from APRS message
static uint8_t main_kiss_from_message[MAIN_KISS_FROM_MESSAGE_LEN];
static uint8_t main_kiss_from_message_ln = 0;
//! binary response to DID request from APRS message
static uint8_t main_kiss_response_message[32];
static uint8_t main_kiss_response_message_ln = 0;
#endif
char main_symbol_f = '/';
char main_symbol_s = '#';
@ -1252,14 +1268,54 @@ int main(int argc, char* argv[]){
gsm_sim800_tx_done_event_handler(main_gsm_srl_ctx_ptr, &main_gsm_state);
}
// if message ACK has been scheduled
if (rte_main_trigger_message_ack == 1) {
if (rte_main_received_message.source == MESSAGE_SOURCE_APRSIS && gsm_sim800_tcpip_tx_busy() == 0) {
// if TCP/IP connection is not busy and received message comes from APRS-IS
if ((rte_main_received_message.source == MESSAGE_SOURCE_APRSIS || rte_main_received_message.source == MESSAGE_SOURCE_APRSIS_HEXCNTR)
&& gsm_sim800_tcpip_tx_busy() == 0) {
// clear ACK request
rte_main_trigger_message_ack = 0;
// create and send ACK for this message
aprsis_send_ack_for_message(&rte_main_received_message);
rte_main_received_message.source = MESSAGE_SOURCE_UNINITIALIZED;
// decode message, do it after ACK is scheduled to be sure about right sequence
const kiss_communication_aprsmsg_transport_t type = kiss_communication_aprsmsg_check_type(rte_main_received_message.content, MESSAGE_MAX_LENGHT);
// decode HEXSTRING
if (type == APRSMSG_TRANSPORT_HEXSTRING) {
main_kiss_from_message_ln = kiss_communication_aprsmsg_decode_hexstring(rte_main_received_message.content, rte_main_received_message.content_ln, main_kiss_from_message + 1, MAIN_KISS_FROM_MESSAGE_LEN - 1);
}
else {
// zero message lenght if message cannot be decoded for some reason
main_kiss_from_message_ln = 0;
}
// if KISS request has been parsed from APRS message
if (main_kiss_from_message_ln != 0) {
// put artificial FEND at the begining of a buffer to make it compatible with 'kiss_parse_received'
*(main_kiss_from_message) = FEND;
// parse KISS request
const uint8_t kiss_response_message_ln = kiss_parse_received(main_kiss_from_message, main_kiss_from_message_ln, NULL, NULL, main_kiss_response_message, MAIN_KISS_FROM_MESSAGE_LEN);
// if a response was generated
if (kiss_response_message_ln > 0) {
// check if a beginning and an end of generated response contains FEND.
if ((*(main_kiss_response_message) == FEND) && (*(main_kiss_response_message + kiss_response_message_ln - 1) == FEND)) {
// if yes encode the response w/o them
rte_main_message_for_transmitting.content_ln = kiss_communication_aprsmsg_encode_hexstring(main_kiss_response_message + 1, kiss_response_message_ln - 2, rte_main_message_for_transmitting.content, MESSAGE_MAX_LENGHT);
}
else {
rte_main_message_for_transmitting.content_ln = kiss_communication_aprsmsg_encode_hexstring(main_kiss_response_message, kiss_response_message_ln, rte_main_message_for_transmitting.content, MESSAGE_MAX_LENGHT);
}
}
}
}
else if (rte_main_received_message.source == MESSAGE_SOURCE_RADIO) {

Wyświetl plik

@ -17,8 +17,12 @@ uint8_t rte_main_trigger_status = 0;
uint8_t rte_main_trigger_wx_packet = 0;
//!< message received from APRS-IS or RF radio network
message_t rte_main_received_message;
//!< message to be send via APRS-IS or RF radio network
message_t rte_main_message_for_transmitting;
#ifdef PARAMETEO
//!< Trigger preparing and sending ACK
uint8_t rte_main_trigger_message_ack = 0;

Wyświetl plik

@ -34,6 +34,7 @@ typedef struct message_t {
AX25Call from;
AX25Call to;
uint8_t content[MESSAGE_MAX_LENGHT];
uint8_t content_ln;
uint8_t number;
uint8_t number_str[MESSAGE_NUMBER_STRING_BUFFER]; //!< Message sequence number but stored as string not decoded to integer
message_source_t source;

Wyświetl plik

@ -68,7 +68,7 @@ STATIC uint32_t message_atoi_message_counter(const uint8_t const * string, uint8
// set to non zero if any digit from A fo F was found in input string
int8_t is_hex = 0;
// checck if input string is located in legoit RAM memory
// checck if input string is located in legit RAM memory
if (variant_validate_is_within_ram(string) == 1 && string_ln <= 6) {
// clear intermediate convertion buffer
@ -322,9 +322,12 @@ uint8_t message_decode(const uint8_t * const message, const uint16_t message_ln,
result = 0;
output->content_ln = 0;
// then copy message, which ends on a counter, something like '{1'
while(MESSAGE_CURRENT_CHAR != ':' && i + content_position < message_ln) {
output->content[result++] = MESSAGE_CURRENT_CHAR;
output->content_ln++;
i++;
// break on message counter separator