diff --git a/flight/PipXtreme/api_config.c b/flight/PipXtreme/api_config.c index b78c9f6f0..525e3f9bd 100644 --- a/flight/PipXtreme/api_config.c +++ b/flight/PipXtreme/api_config.c @@ -106,6 +106,7 @@ typedef struct int8_t apiconfig_previous_com_port = -1; +volatile uint16_t apiconfig_rx_config_timer = 0; volatile uint16_t apiconfig_rx_timer = 0; volatile uint16_t apiconfig_tx_timer = 0; @@ -365,7 +366,10 @@ uint16_t apiconfig_scanForConfigPacket(void *buf, uint16_t *len, bool rf_packet) #endif if (!rf_packet) + { + apiconfig_rx_config_timer = 0; // reset timer apiconfig_rx_timer = 0; // reset the timer + } int total_packet_size = sizeof(t_pipx_config_header) + header->data_size; @@ -409,6 +413,7 @@ uint16_t apiconfig_scanForConfigPacket(void *buf, uint16_t *len, bool rf_packet) void apiconfig_1ms_tick(void) { // call this once every 1ms + if (apiconfig_rx_config_timer < 0xffff) apiconfig_rx_config_timer++; if (apiconfig_rx_timer < 0xffff) apiconfig_rx_timer++; if (apiconfig_tx_timer < 0xffff) apiconfig_tx_timer++; } @@ -496,6 +501,8 @@ void apiconfig_process(void) uint16_t time_out = 5; // ms if (!usb_comms) time_out = (15000 * sizeof(t_pipx_config_header)) / saved_settings.serial_baudrate; // allow enough time to rx a config header + if (time_out < 5) time_out = 5; + if (data_size == 0 && apiconfig_rx_timer >= time_out) { // no config packet found in the buffer within the timeout period, treat any data in the buffer as data to be sent over the air data_size = apiconfig_rx_buffer_wr; @@ -648,6 +655,9 @@ void apiconfig_process(void) } // ******************** + + // speed the pinging speed up if the GCS is connected and monitoring the signal level etc + ph_setFastPing(apiconfig_rx_config_timer < 2000); } // ***************************************************************************** @@ -662,6 +672,7 @@ void apiconfig_init(void) apiconfig_tx_config_buffer_wr = 0; + apiconfig_rx_config_timer = 0xffff; apiconfig_rx_timer = 0; apiconfig_tx_timer = 0; } diff --git a/flight/PipXtreme/inc/packet_handler.h b/flight/PipXtreme/inc/packet_handler.h index 0567dc556..db39901bd 100644 --- a/flight/PipXtreme/inc/packet_handler.h +++ b/flight/PipXtreme/inc/packet_handler.h @@ -45,6 +45,8 @@ uint16_t ph_putData(const int connection_index, const void *data, uint16_t len); uint16_t ph_getData_used(const int connection_index); uint16_t ph_getData(const int connection_index, void *data, uint16_t len); +void ph_setFastPing(bool fast); + uint8_t ph_getCurrentLinkState(const int connection_index); int16_t ph_getLastRSSI(const int connection_index); diff --git a/flight/PipXtreme/packet_handler.c b/flight/PipXtreme/packet_handler.c index d4712fa8f..054c7338c 100644 --- a/flight/PipXtreme/packet_handler.c +++ b/flight/PipXtreme/packet_handler.c @@ -184,6 +184,7 @@ typedef struct volatile uint32_t rx_data_speed; // holds the number of data bits we have received each second uint16_t ping_time; // ping timer + uint16_t fast_ping_time; // ping timer bool pinging; // TRUE if we are doing a ping test with the other modem - to check if it is still present bool rx_not_ready_mode; // TRUE if we have told the other modem we cannot receive data (due to buffer filling up). @@ -217,6 +218,8 @@ uint8_t ph_rx_buffer[256] __attribute__ ((aligned(4))); // holds the int16_t rx_rssi_dBm; int32_t rx_afc_Hz; +bool fast_ping; + // ***************************************************************************** // return TRUE if we are connected to the remote modem @@ -313,7 +316,8 @@ int ph_startConnect(int connection_index, uint32_t sn) conn->rx_data_speed_count = 0; conn->rx_data_speed = 0; - conn->ping_time = 7000 + (random32 % 100) * 10; + conn->ping_time = 8000 + (random32 % 100) * 10; + conn->fast_ping_time = 600 + (random32 % 50) * 10; conn->pinging = false; conn->rx_not_ready_mode = false; @@ -749,7 +753,8 @@ void ph_processPacket2(bool was_encrypted, t_packet_header *header, uint8_t *dat conn->rx_data_speed_count = 0; conn->rx_data_speed = 0; - conn->ping_time = 7000 + (random32 % 100) * 10; + conn->ping_time = 8000 + (random32 % 100) * 10; + conn->fast_ping_time = 600 + (random32 % 50) * 10; conn->pinging = false; conn->rx_not_ready_mode = false; @@ -794,7 +799,8 @@ void ph_processPacket2(bool was_encrypted, t_packet_header *header, uint8_t *dat conn->rx_data_speed_count = 0; conn->rx_data_speed = 0; - conn->ping_time = 7000 + (random32 % 100) * 10; + conn->ping_time = 8000 + (random32 % 100) * 10; + conn->fast_ping_time = 600 + (random32 % 50) * 10; conn->pinging = false; conn->rx_not_ready_mode = false; @@ -1233,6 +1239,9 @@ void ph_processLinks(int connection_index) bool tomanyRetries = (conn->tx_retry_counter >= RETRY_RECONNECT_COUNT); + if (conn->tx_retry_counter >= 3) + conn->rx_rssi_dBm = -200; + switch (conn->link_state) { case link_disconnected: @@ -1298,11 +1307,14 @@ void ph_processLinks(int connection_index) break; } - if (conn->tx_packet_timer >= conn->ping_time) + uint16_t ping_time = conn->ping_time; + if (fast_ping) ping_time = conn->fast_ping_time; + if (conn->tx_packet_timer >= ping_time) { // start pinging if (ph_sendPacket(connection_index, conn->send_encrypted, packet_type_ping, false)) { conn->ping_time = 8000 + (random32 % 100) * 10; + conn->fast_ping_time = 600 + (random32 % 50) * 10; conn->tx_packet_timer = 0; conn->tx_retry_time = conn->tx_retry_time_slot_len * 4 + (random32 % conn->tx_retry_time_slots) * conn->tx_retry_time_slot_len * 4; conn->pinging = true; @@ -1382,6 +1394,13 @@ void ph_processLinks(int connection_index) // ***************************************************************************** +void ph_setFastPing(bool fast) +{ + fast_ping = fast; +} + +// ***************************************************************************** + uint8_t ph_getCurrentLinkState(const int connection_index) { if (connection_index < 0 || connection_index >= PH_MAX_CONNECTIONS) @@ -1573,6 +1592,8 @@ void ph_init(uint32_t our_sn, uint32_t datarate_bps, uint8_t tx_power) { our_serial_number = our_sn; // remember our own serial number + fast_ping = false; + for (int i = 0; i < PH_MAX_CONNECTIONS; i++) { random32 = updateCRC32(random32, 0xff); @@ -1605,6 +1626,7 @@ void ph_init(uint32_t our_sn, uint32_t datarate_bps, uint8_t tx_power) conn->rx_data_speed = 0; conn->ping_time = 8000 + (random32 % 100) * 10; + conn->fast_ping_time = 600 + (random32 % 50) * 10; conn->pinging = false; conn->rx_not_ready_mode = false;