kopia lustrzana https://github.com/SP8EBC/ParaTNC
few bugfixed around KISS communication with host
rodzic
d40e78fd32
commit
36f080d80d
|
@ -32,7 +32,7 @@
|
|||
#endif
|
||||
|
||||
int32_t SendKISSToHost(uint8_t* input_frame, uint16_t input_frame_len, uint8_t* output, uint16_t output_len);
|
||||
short ParseReceivedKISS(uint8_t* SrlRXData, AX25Ctx* ax25, Afsk* a);
|
||||
short ParseReceivedKISS(uint8_t* input_frame_from_host, uint16_t input_len, AX25Ctx* ax25, Afsk* a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include "aprs/ax25.h"
|
||||
|
||||
#define SW_VER "DA01"
|
||||
#define SW_DATE "27012019"
|
||||
#define SW_VER "DA02"
|
||||
#define SW_DATE "10022019"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
#define SYSTICK_TICKS_PERIOD 10
|
||||
|
|
|
@ -8,13 +8,13 @@
|
|||
#include "KissCommunication.h"
|
||||
//#include "main.h"
|
||||
|
||||
#include "drivers/serial.h"
|
||||
|
||||
#include "diag/Trace.h"
|
||||
#include "station_config.h"
|
||||
#include "TimerConfig.h"
|
||||
|
||||
extern unsigned short tx10m;
|
||||
extern volatile int delay_5us;
|
||||
|
||||
|
||||
int32_t SendKISSToHost(uint8_t* input_frame, uint16_t input_frame_len, uint8_t* output, uint16_t output_len) {
|
||||
#define FEND (uint8_t)0xC0
|
||||
|
@ -57,31 +57,41 @@ int32_t SendKISSToHost(uint8_t* input_frame, uint16_t input_frame_len, uint8_t*
|
|||
return j;
|
||||
}
|
||||
|
||||
short ParseReceivedKISS(uint8_t* SrlRXData, AX25Ctx* ax25, Afsk* a) {
|
||||
short ParseReceivedKISS(uint8_t* input_frame_from_host, uint16_t input_len, AX25Ctx* ax25, Afsk* a) {
|
||||
int i/* zmienna do poruszania sie po buforze odbiorczym usart */;
|
||||
int j/* zmienna do poruszania sie po lokalnej tablicy do przepisywania*/;
|
||||
uint8_t FrameBuff[100];
|
||||
if (*(SrlRXData) != FEND)
|
||||
// uint8_t FrameBuff[100];
|
||||
|
||||
// to save some memory utilize the serial port buffer
|
||||
uint8_t *FrameBuff = srl_tx_buffer;
|
||||
|
||||
// check if frame from host is not too long
|
||||
if (input_len >= TX_BUFFER_LN)
|
||||
return 1;
|
||||
if (*(SrlRXData+1) != 0x00)
|
||||
|
||||
if (*(input_frame_from_host) != FEND)
|
||||
return 1;
|
||||
for (i=2, j=0; (i<100 && *(SrlRXData+i) != FEND); i++, j++) {
|
||||
if (*(SrlRXData+i) == FESC) {
|
||||
if(*(SrlRXData+i+1) == TFEND)
|
||||
if (*(input_frame_from_host+1) != 0x00)
|
||||
return 1;
|
||||
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(*(SrlRXData+i+1) == TFESC)
|
||||
else if(*(input_frame_from_host+i+1) == TFESC)
|
||||
FrameBuff[j]=FESC;
|
||||
else;
|
||||
i++;
|
||||
}
|
||||
else
|
||||
FrameBuff[j] = *(SrlRXData+i);
|
||||
FrameBuff[j] = *(input_frame_from_host+i);
|
||||
}
|
||||
#ifdef _DBG_TRACE
|
||||
trace_printf("KISS-FromHost:Ln=%d;Content=%s\r\n", j, FrameBuff);
|
||||
#endif
|
||||
tx10m++;
|
||||
while(ax25->dcd == true);
|
||||
|
||||
// keep this commented until reseting the DCD variable will be moved outside main for (;;) loop
|
||||
// while(ax25->dcd == true);
|
||||
while(a->sending == true);
|
||||
|
||||
|
||||
|
|
16
src/main.c
16
src/main.c
|
@ -139,11 +139,11 @@ main(int argc, char* argv[])
|
|||
|
||||
#ifdef _METEO
|
||||
dht22_init();
|
||||
dallas_init(GPIOC, GPIO_Pin_6, GPIO_PinSource6);
|
||||
dallas_init(GPIOB, GPIO_Pin_5, GPIO_PinSource5);
|
||||
TX20Init();
|
||||
#endif
|
||||
#ifdef _DALLAS_AS_TELEM
|
||||
dallas_init(GPIOC, GPIO_Pin_6, GPIO_PinSource6);
|
||||
dallas_init(GPIOB, GPIO_Pin_5, GPIO_PinSource5);
|
||||
#endif
|
||||
|
||||
// initializing UART drvier
|
||||
|
@ -258,8 +258,13 @@ main(int argc, char* argv[])
|
|||
// if new KISS message has been received from the host
|
||||
if (srl_rx_state == SRL_RX_DONE) {
|
||||
|
||||
// because ParseReceivedKISS uses srl_tx_buffer as internal buffer to save a memory
|
||||
// the code need to wait till UART will finish possible transmission. Overwise transmission will be
|
||||
// totally screw up. UART will start to retransmit what were received from HOST.
|
||||
while(srl_tx_state != SRL_TX_IDLE && srl_tx_state != SRL_TX_ERROR);
|
||||
|
||||
// parse incoming data and then transmit on radio freq
|
||||
short res = ParseReceivedKISS(srl_get_rx_buffer(), &main_ax25, &main_afsk);
|
||||
short res = ParseReceivedKISS(srl_get_rx_buffer(), srl_get_num_bytes_rxed(), &main_ax25, &main_afsk);
|
||||
if (res == 0)
|
||||
kiss10m++; // increase kiss messages counter
|
||||
|
||||
|
@ -267,6 +272,11 @@ main(int argc, char* argv[])
|
|||
srl_receive_data(120, FEND, FEND, 0, 0, 0);
|
||||
}
|
||||
|
||||
// if there were an error during receiving frame from host, restart rxing once again
|
||||
if (srl_rx_state == SRL_RX_ERROR) {
|
||||
srl_receive_data(120, FEND, FEND, 0, 0, 0);
|
||||
}
|
||||
|
||||
// get all meteo measuremenets each 65 seconds. some values may not be
|
||||
// downloaded from sensors if _METEO and/or _DALLAS_AS_TELEM aren't defined
|
||||
if (main_wx_sensors_pool_timer < 10) {
|
||||
|
|
|
@ -47,6 +47,7 @@ uint8_t srl_send_data(uint8_t* data, uint8_t mode, uint16_t leng, uint8_t intern
|
|||
uint8_t srl_start_tx(short leng);
|
||||
void srl_irq_handler(void);
|
||||
uint8_t srl_receive_data(int num, char start, char stop, char echo, char len_addr, char len_modifier);
|
||||
uint16_t srl_get_num_bytes_rxed();
|
||||
uint8_t* srl_get_rx_buffer();
|
||||
void srl_keep_timeout(void);
|
||||
void srl_switch_timeout(uint8_t disable_enable);
|
||||
|
|
|
@ -135,7 +135,7 @@ void telemetry_send_values( uint8_t rx_pkts,
|
|||
#ifdef _DALLAS_AS_TELEM
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "T#%03d,%03d,%03d,%03d,%03d,%03d,%c%c%c%c%c000", telemetry_counter++, rx_pkts, tx_pkts, digi_pkts, kiss_pkts, scaled_temperature, qf, degr, nav, ms_qf_navaliable, dht_qf_navaliable);
|
||||
#else
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "T#%03d,%03d,%03d,%03d,%03d,%03d,%c%c%c%c%c000", telemetry_counter++, rx_pkts, tx_pkts, digi_pkts, kiss_pkts, 0, qf, degr, nav, ms_qf_navaliable, dht_qf_navaliable);
|
||||
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "T#%03d,%03d,%03d,%03d,%03d,%03d,%c%c%c%c%c000", telemetry_counter++, rx_pkts, tx_pkts, digi_pkts, kiss_pkts, scaled_temperature, qf, degr, nav, ms_qf_navaliable, dht_qf_navaliable);
|
||||
#endif
|
||||
|
||||
if (telemetry_counter > 999)
|
||||
|
|
|
@ -415,6 +415,17 @@ void srl_irq_handler(void) {
|
|||
PORT->SR &= (0xFFFFFFFF ^ USART_SR_TC);
|
||||
srl_tx_state = SRL_TX_IDLE;
|
||||
}
|
||||
|
||||
if (srl_tx_bytes_counter >= TX_BUFFER_LN ||
|
||||
srl_tx_bytes_req >= TX_BUFFER_LN) {
|
||||
|
||||
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_TE); //wyġṗczanie nadajnika portu szeregowego
|
||||
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_TXEIE);
|
||||
PORT->CR1 &= (0xFFFFFFFF ^ USART_CR1_TCIE); // wyġṗczanie przerwañ od portu szeregowego
|
||||
PORT->SR &= (0xFFFFFFFF ^ USART_SR_TC);
|
||||
srl_tx_state = SRL_TX_IDLE;
|
||||
}
|
||||
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
@ -422,6 +433,10 @@ void srl_irq_handler(void) {
|
|||
|
||||
}
|
||||
|
||||
uint16_t srl_get_num_bytes_rxed() {
|
||||
return srl_rx_bytes_counter;
|
||||
}
|
||||
|
||||
uint8_t* srl_get_rx_buffer() {
|
||||
return srl_rx_buf_pointer;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue