Viscous digi in prototype state

pull/2/head
Mateusz Lubecki 2020-08-05 23:27:25 +02:00
rodzic a1b248a4aa
commit db2d637944
6 zmienionych plików z 189 dodań i 59 usunięć

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -4,8 +4,8 @@
#include "aprs/ax25.h"
#include "drivers/serial.h"
#define SW_VER "DF05"
#define SW_DATE "27072020"
#define SW_VER "DF06"
#define SW_DATE "04082020"
#define SYSTICK_TICKS_PER_SECONDS 100
#define SYSTICK_TICKS_PERIOD 10
@ -34,7 +34,7 @@ extern srl_context_t* main_wx_srl_ctx_ptr;
extern char after_tx_lock;
extern unsigned short rx10m, tx10m, digi10m, kiss10m;
extern unsigned short rx10m, tx10m, digi10m, digidrop10m, kiss10m;
uint16_t main_get_adc_sample(void);

Wyświetl plik

@ -152,7 +152,7 @@ umb_retval_t main_umb_retval = UMB_UNINITIALIZED;
char after_tx_lock;
unsigned short rx10m = 0, tx10m = 0, digi10m = 0, kiss10m = 0;
unsigned short rx10m = 0, tx10m = 0, digi10m = 0, digidrop10m = 0, kiss10m = 0;
static void message_callback(struct AX25Msg *msg) {
@ -529,8 +529,8 @@ int main(int argc, char* argv[]){
trace_printf("APRS-RF:RadioPacketFrom=%.6s-%d,FirstPathEl=%.6s-%d\r\n", ax25_rxed_frame.src.call, ax25_rxed_frame.src.ssid, ax25_rxed_frame.rpt_lst[0].call, ax25_rxed_frame.rpt_lst[0].ssid);
#endif
#ifdef _DIGI
// check if this packet needs to be repeated (digipeated) and do it if it is neccessary
Digi(&ax25_rxed_frame);
// check if this packet needs to be repeated (digipeated) and do it if it is necessary
digi_process(&ax25_rxed_frame);
#endif
ax25_new_msg_rx_flag = 0;
rx10m++;

Wyświetl plik

@ -10,14 +10,26 @@
#include "aprs/ax25.h"
#define DIGI_PACKET_DIGIPEATED 1
#define DIGI_PACKET_DIDNT_DIGIPEATED 0
#define DIGI_PACKET_TOO_LONG -1
typedef enum digi_mode_t {
DIGI_OFF = 0,
DIGI_ON_ALL_WIDE1 = 1,
DIGI_ON_SSID_WIDE1 = 2,
DIGI_VISCOUS_ALL_WIDE1 = 3,
DIGI_VISCOUS_SSID_WIDE1 = 4
}digi_mode_t;
#ifdef __cplusplus
extern "C"
{
#endif
char Digi(struct AX25Msg *msg);
uint8_t digi_process(struct AX25Msg *msg);
uint8_t digi_check_with_viscous(struct AX25Msg *msg);
uint8_t digi_pool_viscous(void);
#ifdef __cplusplus
}

Wyświetl plik

@ -15,39 +15,75 @@
#include "station_config.h"
#include "config.h"
char digi_q = 0;
// global variables to store a frame content to be digipeated
uint8_t digi_msg[CONFIG_AX25_FRAME_BUF_LEN];
uint16_t digi_msg_len;
AX25Call digi_path[7];
uint8_t digi_call_len = 0;
uint8_t digi_limit_to_ssid789;
// digipeater working mode
digi_mode_t digi_mode;
uint8_t digi_viscous_delay_sec;
uint8_t digi_viscous_counter_sec;
char Digi(struct AX25Msg *msg) {
#ifdef _DIGI
void digi_init(void) {
digi_viscous_counter_sec = 0;
digi_msg_len = 0;
digi_mode = DIGI_OFF;
#ifdef _DIGI_VISCOUS
#ifdef _DIGI_ONLY_789
digi_mode = DIGI_VISCOUS_SSID_WIDE1;
#else
digi_mode = DIGI_VISCOUS_ALL_WIDE1;
#endif
#ifdef _DIGI_ONLY_789
digi_limit_to_ssid789 = 1;
#else
digi_limit_to_ssid789 = 0;
#ifdef _DIGI_ONLY_789
digi_mode = DIGI_ON_SSID_WIDE1;
#else
digi_mode = DIGI_ON_ALL_WIDE1;
#endif
#endif
AX25Call digi_path[7];
uint8_t call_len = 0;
memset(digi_path, sizeof(AX25Call) * 7, 0x00);
#ifdef _DIGI_VISCOUS_DEALY
digi_viscous_delay_sec =_DIGI_VISCOUS_DEALY;
#else
digi_viscous_delay_sec = 3;
#endif
}
uint8_t digi_process(struct AX25Msg *msg) {
#ifdef _DIGI
uint8_t retval = DIGI_PACKET_DIDNT_DIGIPEATED;
// check if the received message is not too long for the transmit buffers
if (msg->len >= (CONFIG_AX25_FRAME_BUF_LEN - sizeof(AX25Call) * 7) ) {
return DIGI_PACKET_TOO_LONG;
}
if ((msg->src.ssid < 7 || msg->src.ssid > 9) && digi_limit_to_ssid789 == 1) {
return 0;
if ((msg->src.ssid < 7 || msg->src.ssid > 9) && (digi_mode == DIGI_ON_SSID_WIDE1 || digi_mode == DIGI_VISCOUS_SSID_WIDE1)) {
return DIGI_PACKET_DIDNT_DIGIPEATED;
}
if (main_afsk.sending != 1 && after_tx_lock == 0) {
/* funkcja wywoływana po odbiorze ramki - tu powinna być obsługa digi */
if((msg->rpt_cnt >= 1) /*&& CheckIsOwnPacket(msg) == 0*/) {
if (after_tx_lock == 0) {
// if the packet has any path and there is no packed waiting in viscous delay
if(msg->rpt_cnt >= 1 && digi_msg_len == 0) {
// initialize global variables used to store digipeated packet
memset(digi_path, 0x00, sizeof(AX25Call) * 7);
memset(digi_msg, 0x00, CONFIG_AX25_FRAME_BUF_LEN);
// if (msg->rpt_cnt == 1 && strcmp("WIDE2", msg->rpt_lst[0].call) == 0 && (msg->rpt_lst[0].ssid == 1 || msg->rpt_lst[0].ssid == 2)) {
// /* Powtarzanie ścieżki WIDE2-1 i WIDE2-2 */
// strcpy(digi_path[0].call, msg->dst.call); // znak docelowy
@ -74,8 +110,8 @@ char Digi(struct AX25Msg *msg) {
sprintf(digi_path[3].call, "%s", "WIDE1"); // dodawanie WIDE2*
digi_path[3].ssid = 0x40; /* 0x40 oznacza jedynkę na 6 bicie (przy numeracji od zera). Po przesunięciu o jedno miejsce
otrzymuje się 0x80 czyli jedynkę na H-bicie */
digi_q = 1;
call_len = 4; // długość ścieżki
retval = DIGI_PACKET_DIGIPEATED;
digi_call_len = 4; // długość ścieżki
}
else if(msg->rpt_cnt > 1 && strcmp("WIDE1", msg->rpt_lst[0].call) == 0 && strcmp("WIDE2", msg->rpt_lst[1].call) == 0 && msg->rpt_lst[0].ssid == 1 && msg->rpt_lst[1].ssid == 1) {
@ -90,8 +126,8 @@ char Digi(struct AX25Msg *msg) {
digi_path[3].ssid = 0x40;
sprintf(digi_path[4].call, "%s", msg->rpt_lst[1].call); // przepisywanie WIDE2-1
digi_path[4].ssid = msg->rpt_lst[1].ssid;
digi_q = 1;
call_len = 5;
retval = DIGI_PACKET_DIGIPEATED;
digi_call_len = 5;
}
else if(msg->rpt_cnt > 1 && strcmp("WIDE1", msg->rpt_lst[0].call) == 0 && strcmp("WIDE2", msg->rpt_lst[1].call) == 0 && msg->rpt_lst[0].ssid == 1 && msg->rpt_lst[1].ssid == 2) {
/* Powtarzanie aliasu WIDE1-1 w sciezce typu WIDE1-1,WIDE2-2 */
@ -105,8 +141,8 @@ char Digi(struct AX25Msg *msg) {
digi_path[3].ssid = 0x40;
sprintf(digi_path[4].call, "%s", "WIDE2"); // skracanie dalszej czesci do WIDE2-1
digi_path[4].ssid = 1;
digi_q = 1;
call_len = 5;
retval = DIGI_PACKET_DIGIPEATED;
digi_call_len = 5;
}
// else if (msg->rpt_cnt >= 2 && strcmp("WIDE2", msg->rpt_lst[1].call) == 0 && msg->rpt_lst[1].ssid == 1) {
// /* Powtarzanie aliasu WIDE2-1 w sciezce WIDE2*,WIDE2-1 */
@ -159,34 +195,116 @@ char Digi(struct AX25Msg *msg) {
// digi_q = 1;
// call_len = 7;
// }
else
digi_q = 0;
if (digi_q == 1) {
if (retval == DIGI_PACKET_DIGIPEATED) {
#ifdef _DBG_TRACE
trace_printf("Digi:call_len=%d\r\n", call_len);
#endif
digi10m++;
// copying the content
digi_msg_len = msg->len+1;
snprintf(digi_msg, msg->len+1, "%s", msg->info);
delay_from_preset();
while(main_ax25.dcd == true);
ax25_sendVia(&main_ax25, digi_path, call_len, digi_msg, digi_msg_len-1);
after_tx_lock = 1;
afsk_txStart(&main_afsk);
return 1;
// if Viscous mode is not enabled proceed to transmission immediately
if (digi_mode == DIGI_ON_SSID_WIDE1 || digi_mode == DIGI_ON_ALL_WIDE1) {
digi10m++;
// delaying retransmission.. well this will block I/O for a while
// and it could be refactor to ommit that but for now it needs to stay
// as it is.
delay_from_preset();
while(main_ax25.dcd == true);
ax25_sendVia(&main_ax25, digi_path, digi_call_len, digi_msg, digi_msg_len-1);
after_tx_lock = 1;
afsk_txStart(&main_afsk);
// clear variables when there are not needed
memset(digi_path, 0x00, sizeof(AX25Call) * 7);
memset(digi_msg, 0x00, CONFIG_AX25_FRAME_BUF_LEN);
digi_msg_len = 0;
return retval;
} // digi_mode == DIGI_ON_SSID_WIDE1 || digi_mode == DIGI_ON_ALL_WIDE1
} // retval == DIGI_PACKET_DIGIPEATED
} // msg->rpt_cnt >= 1 && digi_msg_len == 0
}
else {
after_tx_lock = 0;
}
#endif
return retval;
}
uint8_t digi_check_with_viscous(struct AX25Msg *msg) {
uint8_t retval = 0;
// if there is a message waiting in buffer for digipeating
if (digi_msg_len > 0) {
// check the source call
if (strncmp(msg->src.call, digi_path[1].call, 6) == 0) {
// if the source call is the same check the SSID
if (msg->src.ssid == digi_path[1].ssid) {
// this is a message from the same station check the message content
if (memcmp(msg->info, digi_msg, msg->len) == 0) {
// if the message content is the same it means that current buffer content shall be discarded
// and frame shall not be retransmited
digi_msg_len = 0;
memset(digi_msg, 0x00, CONFIG_AX25_FRAME_BUF_LEN);
// increase viscous drop counter
digidrop10m++;
}
}
else {
;
}
}
else {
;
}
}
else
after_tx_lock = 0;
#endif
return 0;
return retval;
}
uint8_t digi_pool_viscous(void) {
uint8_t retval = DIGI_PACKET_DIDNT_DIGIPEATED;
// proceed only if Viscous mode is enabled
if (digi_mode == DIGI_VISCOUS_ALL_WIDE1 || digi_mode == DIGI_VISCOUS_SSID_WIDE1) {
// if there is any message waiting in viscous delay
if (digi_msg_len > 0) {
digi_viscous_counter_sec++;
// if the counter reach the delay limit and packet still waits
// so it hasn't been cleared by 'digi_check_with_viscous'
if (digi_viscous_counter_sec >= digi_viscous_delay_sec) {
// wait when radio channel will became avaliable
while(main_ax25.dcd == true);
// put message vaiting in viscous dealy into AX25 buffer in correct, encoded form
ax25_sendVia(&main_ax25, digi_path, digi_call_len, digi_msg, digi_msg_len-1);
after_tx_lock = 1;
// start transmission (non blicking call)
afsk_txStart(&main_afsk);
// clear variables when there are not needed
memset(digi_path, 0x00, sizeof(AX25Call) * 7);
memset(digi_msg, 0x00, CONFIG_AX25_FRAME_BUF_LEN);
digi_msg_len = 0;
digi10m++;
retval = DIGI_PACKET_DIGIPEATED;
}
}
else {
// if there isn't only zero the counter and do nothing
digi_viscous_counter_sec = 0;
}
}
return retval;
}

Wyświetl plik

@ -35,7 +35,7 @@ int32_t ms5611_reset(ms5611_qf_t *qf) {
int txbuf[] = {0x1E, '\0' };
// Send a data to sensor
i2cSendData(TX_ADDR, txbuf, 0);
i2c_send_data(TX_ADDR, txbuf, 0);
// Wait until the transmission will finish or fail (due to timeout or any other error)
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -86,7 +86,7 @@ int32_t ms5611_read_calibration(int32_t* cal_data, ms5611_qf_t *out) {
txbuf[1] = '\0';
// Transmitting a command
i2cSendData(TX_ADDR, txbuf, 0);
i2c_send_data(TX_ADDR, txbuf, 0);
// Waiting to transmission completion or failure
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -101,7 +101,7 @@ int32_t ms5611_read_calibration(int32_t* cal_data, ms5611_qf_t *out) {
}
// Receiving the data with calibration coefficient.
i2cReceiveData(RX_ADDR, rxbuf, 2);
i2c_receive_data(RX_ADDR, 2);
// Waiting until receiving will be completed
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -145,7 +145,7 @@ int32_t ms5611_trigger_measure(int param_to_meas, int32_t* out) {
//// TRIGGERING TEMPERATURE MESUREMENET ////
////////////////////////////////////////////
txbuf[0] = 0x54; // oversampling 1024
i2cSendData(TX_ADDR,txbuf, 0); // wys<79>anie rozkazu rozpocz<63>cia pomiaru
i2c_send_data(TX_ADDR,txbuf, 0); // wys<79>anie rozkazu rozpocz<63>cia pomiaru
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -159,7 +159,7 @@ int32_t ms5611_trigger_measure(int param_to_meas, int32_t* out) {
//// READING TEMPERATURE ////
/////////////////////////////
txbuf[0] = 0x00;
i2cSendData(TX_ADDR,txbuf, 0x01);
i2c_send_data(TX_ADDR,txbuf, 0x01);
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -167,7 +167,7 @@ int32_t ms5611_trigger_measure(int param_to_meas, int32_t* out) {
return MS5611_TIMEOUT_DURING_MEASURMENT;
}
i2cReceiveData(RX_ADDR, txbuf, 3);
i2c_receive_data(RX_ADDR, 3);
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -180,7 +180,7 @@ int32_t ms5611_trigger_measure(int param_to_meas, int32_t* out) {
//// TRIGGERING PRESSURE MEASUREMENET ////
////////////////////////////////////////////
txbuf[0] = 0x44;
i2cSendData(TX_ADDR,txbuf, 0);
i2c_send_data(TX_ADDR,txbuf, 0);
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -195,7 +195,7 @@ int32_t ms5611_trigger_measure(int param_to_meas, int32_t* out) {
//// READING PRESSURE ////
//////////////////////////
txbuf[0] = 0x00;
i2cSendData(TX_ADDR,txbuf, 0x01); // wys<79>anie rozkazu odczytu wyniku
i2c_send_data(TX_ADDR,txbuf, 0x01); // wys<79>anie rozkazu odczytu wyniku
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -203,7 +203,7 @@ int32_t ms5611_trigger_measure(int param_to_meas, int32_t* out) {
return MS5611_TIMEOUT_DURING_MEASURMENT;
}
i2cReceiveData(RX_ADDR, txbuf, 3);
i2c_receive_data(RX_ADDR, 3);
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);
@ -216,7 +216,7 @@ int32_t ms5611_trigger_measure(int param_to_meas, int32_t* out) {
//// TRIGGERING TEMPERATURE MEASUREMENET ////
/////////////////////////////////////////////
txbuf[0] = 0x54;
i2cSendData(TX_ADDR,txbuf, 0);
i2c_send_data(TX_ADDR,txbuf, 0);
while (i2c_state != I2C_IDLE && i2c_state != I2C_ERROR);