mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-05 21:52:10 +01:00
Merge remote-tracking branch 'origin/filnet/OP-1246_RadioComBridge_bugs' into next
This commit is contained in:
commit
18be34db05
@ -290,20 +290,20 @@ static void updateRadioComBridgeStats()
|
|||||||
RadioComBridgeStatsData radioComBridgeStats;
|
RadioComBridgeStatsData radioComBridgeStats;
|
||||||
|
|
||||||
// Get telemetry stats
|
// Get telemetry stats
|
||||||
UAVTalkGetStats(data->telemUAVTalkCon, &telemetryUAVTalkStats);
|
UAVTalkGetStats(data->telemUAVTalkCon, &telemetryUAVTalkStats, true);
|
||||||
UAVTalkResetStats(data->telemUAVTalkCon);
|
|
||||||
|
|
||||||
// Get radio stats
|
// Get radio stats
|
||||||
UAVTalkGetStats(data->radioUAVTalkCon, &radioUAVTalkStats);
|
UAVTalkGetStats(data->radioUAVTalkCon, &radioUAVTalkStats, true);
|
||||||
UAVTalkResetStats(data->radioUAVTalkCon);
|
|
||||||
|
|
||||||
// Get stats object data
|
// Get stats object data
|
||||||
RadioComBridgeStatsGet(&radioComBridgeStats);
|
RadioComBridgeStatsGet(&radioComBridgeStats);
|
||||||
|
|
||||||
|
radioComBridgeStats.TelemetryTxRetries = data->telemetryTxRetries;
|
||||||
|
radioComBridgeStats.RadioTxRetries = data->radioTxRetries;
|
||||||
|
|
||||||
// Update stats object
|
// Update stats object
|
||||||
radioComBridgeStats.TelemetryTxBytes += telemetryUAVTalkStats.txBytes;
|
radioComBridgeStats.TelemetryTxBytes += telemetryUAVTalkStats.txBytes;
|
||||||
radioComBridgeStats.TelemetryTxFailures += telemetryUAVTalkStats.txErrors;
|
radioComBridgeStats.TelemetryTxFailures += telemetryUAVTalkStats.txErrors;
|
||||||
radioComBridgeStats.TelemetryTxRetries += data->telemetryTxRetries;
|
|
||||||
|
|
||||||
radioComBridgeStats.TelemetryRxBytes += telemetryUAVTalkStats.rxBytes;
|
radioComBridgeStats.TelemetryRxBytes += telemetryUAVTalkStats.rxBytes;
|
||||||
radioComBridgeStats.TelemetryRxFailures += telemetryUAVTalkStats.rxErrors;
|
radioComBridgeStats.TelemetryRxFailures += telemetryUAVTalkStats.rxErrors;
|
||||||
@ -312,7 +312,6 @@ static void updateRadioComBridgeStats()
|
|||||||
|
|
||||||
radioComBridgeStats.RadioTxBytes += radioUAVTalkStats.txBytes;
|
radioComBridgeStats.RadioTxBytes += radioUAVTalkStats.txBytes;
|
||||||
radioComBridgeStats.RadioTxFailures += radioUAVTalkStats.txErrors;
|
radioComBridgeStats.RadioTxFailures += radioUAVTalkStats.txErrors;
|
||||||
radioComBridgeStats.RadioTxRetries += data->radioTxRetries;
|
|
||||||
|
|
||||||
radioComBridgeStats.RadioRxBytes += radioUAVTalkStats.rxBytes;
|
radioComBridgeStats.RadioRxBytes += radioUAVTalkStats.rxBytes;
|
||||||
radioComBridgeStats.RadioRxFailures += radioUAVTalkStats.rxErrors;
|
radioComBridgeStats.RadioRxFailures += radioUAVTalkStats.rxErrors;
|
||||||
@ -343,11 +342,11 @@ static void telemetryTxTask(__attribute__((unused)) void *parameters)
|
|||||||
updateRadioComBridgeStats();
|
updateRadioComBridgeStats();
|
||||||
}
|
}
|
||||||
// Send update (with retries)
|
// Send update (with retries)
|
||||||
|
int32_t ret = -1;
|
||||||
uint32_t retries = 0;
|
uint32_t retries = 0;
|
||||||
int32_t success = -1;
|
while (retries <= MAX_RETRIES && ret == -1) {
|
||||||
while (retries < MAX_RETRIES && success == -1) {
|
ret = UAVTalkSendObject(data->telemUAVTalkCon, ev.obj, ev.instId, 0, RETRY_TIMEOUT_MS);
|
||||||
success = UAVTalkSendObject(data->telemUAVTalkCon, ev.obj, ev.instId, 0, RETRY_TIMEOUT_MS) == 0;
|
if (ret == -1) {
|
||||||
if (success == -1) {
|
|
||||||
++retries;
|
++retries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -377,11 +376,11 @@ static void radioTxTask(__attribute__((unused)) void *parameters)
|
|||||||
if (xQueueReceive(data->radioEventQueue, &ev, MAX_PORT_DELAY) == pdTRUE) {
|
if (xQueueReceive(data->radioEventQueue, &ev, MAX_PORT_DELAY) == pdTRUE) {
|
||||||
if ((ev.event == EV_UPDATED) || (ev.event == EV_UPDATE_REQ)) {
|
if ((ev.event == EV_UPDATED) || (ev.event == EV_UPDATE_REQ)) {
|
||||||
// Send update (with retries)
|
// Send update (with retries)
|
||||||
|
int32_t ret = -1;
|
||||||
uint32_t retries = 0;
|
uint32_t retries = 0;
|
||||||
int32_t success = -1;
|
while (retries <= MAX_RETRIES && ret == -1) {
|
||||||
while (retries < MAX_RETRIES && success == -1) {
|
ret = UAVTalkSendObject(data->radioUAVTalkCon, ev.obj, ev.instId, 0, RETRY_TIMEOUT_MS);
|
||||||
success = UAVTalkSendObject(data->radioUAVTalkCon, ev.obj, ev.instId, 0, RETRY_TIMEOUT_MS) == 0;
|
if (ret == -1) {
|
||||||
if (success == -1) {
|
|
||||||
++retries;
|
++retries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -414,8 +413,8 @@ static void radioRxTask(__attribute__((unused)) void *parameters)
|
|||||||
}
|
}
|
||||||
} else if (PIOS_COM_TELEMETRY) {
|
} else if (PIOS_COM_TELEMETRY) {
|
||||||
// Send the data straight to the telemetry port.
|
// Send the data straight to the telemetry port.
|
||||||
// FIXME following call can fail (with -2 error code) if buffer is full
|
// Following call can fail with -2 error code (buffer full) or -3 error code (could not acquire send mutex)
|
||||||
// it is the caller responsibility to retry in such cases...
|
// It is the caller responsibility to retry in such cases...
|
||||||
int32_t ret = -2;
|
int32_t ret = -2;
|
||||||
uint8_t count = 5;
|
uint8_t count = 5;
|
||||||
while (count-- > 0 && ret < -1) {
|
while (count-- > 0 && ret < -1) {
|
||||||
@ -514,8 +513,8 @@ static void serialRxTask(__attribute__((unused)) void *parameters)
|
|||||||
|
|
||||||
if (bytes_to_process > 0) {
|
if (bytes_to_process > 0) {
|
||||||
// Send the data over the radio link.
|
// Send the data over the radio link.
|
||||||
// FIXME following call can fail (with -2 error code) if buffer is full
|
// Following call can fail with -2 error code (buffer full) or -3 error code (could not acquire send mutex)
|
||||||
// it is the caller responsibility to retry in such cases...
|
// It is the caller responsibility to retry in such cases...
|
||||||
int32_t ret = -2;
|
int32_t ret = -2;
|
||||||
uint8_t count = 5;
|
uint8_t count = 5;
|
||||||
while (count-- > 0 && ret < -1) {
|
while (count-- > 0 && ret < -1) {
|
||||||
@ -548,8 +547,8 @@ static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length)
|
|||||||
}
|
}
|
||||||
#endif /* PIOS_INCLUDE_USB */
|
#endif /* PIOS_INCLUDE_USB */
|
||||||
if (outputPort) {
|
if (outputPort) {
|
||||||
// FIXME following call can fail (with -2 error code) if buffer is full
|
// Following call can fail with -2 error code (buffer full) or -3 error code (could not acquire send mutex)
|
||||||
// it is the caller responsibility to retry in such cases...
|
// It is the caller responsibility to retry in such cases...
|
||||||
ret = -2;
|
ret = -2;
|
||||||
uint8_t count = 5;
|
uint8_t count = 5;
|
||||||
while (count-- > 0 && ret < -1) {
|
while (count-- > 0 && ret < -1) {
|
||||||
@ -578,8 +577,8 @@ static int32_t RadioSendHandler(uint8_t *buf, int32_t length)
|
|||||||
|
|
||||||
// Don't send any data unless the radio port is available.
|
// Don't send any data unless the radio port is available.
|
||||||
if (outputPort && PIOS_COM_Available(outputPort)) {
|
if (outputPort && PIOS_COM_Available(outputPort)) {
|
||||||
// FIXME following call can fail (with -2 error code) if buffer is full
|
// Following call can fail with -2 error code (buffer full) or -3 error code (could not acquire send mutex)
|
||||||
// it is the caller responsibility to retry in such cases...
|
// It is the caller responsibility to retry in such cases...
|
||||||
int32_t ret = -2;
|
int32_t ret = -2;
|
||||||
uint8_t count = 5;
|
uint8_t count = 5;
|
||||||
while (count-- > 0 && ret < -1) {
|
while (count-- > 0 && ret < -1) {
|
||||||
|
@ -544,12 +544,10 @@ static void updateTelemetryStats()
|
|||||||
uint32_t timeNow;
|
uint32_t timeNow;
|
||||||
|
|
||||||
// Get stats
|
// Get stats
|
||||||
UAVTalkGetStats(uavTalkCon, &utalkStats);
|
UAVTalkGetStats(uavTalkCon, &utalkStats, true);
|
||||||
#ifdef PIOS_INCLUDE_RFM22B
|
#ifdef PIOS_INCLUDE_RFM22B
|
||||||
UAVTalkAddStats(radioUavTalkCon, &utalkStats);
|
UAVTalkAddStats(radioUavTalkCon, &utalkStats, true);
|
||||||
UAVTalkResetStats(radioUavTalkCon);
|
|
||||||
#endif
|
#endif
|
||||||
UAVTalkResetStats(uavTalkCon);
|
|
||||||
|
|
||||||
// Get object data
|
// Get object data
|
||||||
FlightTelemetryStatsGet(&flightStats);
|
FlightTelemetryStatsGet(&flightStats);
|
||||||
|
@ -59,10 +59,10 @@ int32_t UAVTalkSendObjectTimestamped(UAVTalkConnection connectionHandle, UAVObjH
|
|||||||
int32_t UAVTalkSendObjectRequest(UAVTalkConnection connection, UAVObjHandle obj, uint16_t instId, int32_t timeoutMs);
|
int32_t UAVTalkSendObjectRequest(UAVTalkConnection connection, UAVObjHandle obj, uint16_t instId, int32_t timeoutMs);
|
||||||
UAVTalkRxState UAVTalkProcessInputStream(UAVTalkConnection connection, uint8_t rxbyte);
|
UAVTalkRxState UAVTalkProcessInputStream(UAVTalkConnection connection, uint8_t rxbyte);
|
||||||
UAVTalkRxState UAVTalkProcessInputStreamQuiet(UAVTalkConnection connection, uint8_t rxbyte);
|
UAVTalkRxState UAVTalkProcessInputStreamQuiet(UAVTalkConnection connection, uint8_t rxbyte);
|
||||||
UAVTalkRxState UAVTalkRelayPacket(UAVTalkConnection inConnectionHandle, UAVTalkConnection outConnectionHandle);
|
int32_t UAVTalkRelayPacket(UAVTalkConnection inConnectionHandle, UAVTalkConnection outConnectionHandle);
|
||||||
int32_t UAVTalkReceiveObject(UAVTalkConnection connectionHandle);
|
int32_t UAVTalkReceiveObject(UAVTalkConnection connectionHandle);
|
||||||
void UAVTalkGetStats(UAVTalkConnection connection, UAVTalkStats *stats);
|
void UAVTalkGetStats(UAVTalkConnection connection, UAVTalkStats *stats, bool reset);
|
||||||
void UAVTalkAddStats(UAVTalkConnection connection, UAVTalkStats *stats);
|
void UAVTalkAddStats(UAVTalkConnection connection, UAVTalkStats *stats, bool reset);
|
||||||
void UAVTalkResetStats(UAVTalkConnection connection);
|
void UAVTalkResetStats(UAVTalkConnection connection);
|
||||||
void UAVTalkGetLastTimestamp(UAVTalkConnection connection, uint16_t *timestamp);
|
void UAVTalkGetLastTimestamp(UAVTalkConnection connection, uint16_t *timestamp);
|
||||||
uint32_t UAVTalkGetPacketObjId(UAVTalkConnection connection);
|
uint32_t UAVTalkGetPacketObjId(UAVTalkConnection connection);
|
||||||
|
@ -133,7 +133,7 @@ UAVTalkOutputStream UAVTalkGetOutputStream(UAVTalkConnection connectionHandle)
|
|||||||
* \param[in] connection UAVTalkConnection to be used
|
* \param[in] connection UAVTalkConnection to be used
|
||||||
* @param[out] statsOut Statistics counters
|
* @param[out] statsOut Statistics counters
|
||||||
*/
|
*/
|
||||||
void UAVTalkGetStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut)
|
void UAVTalkGetStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut, bool reset)
|
||||||
{
|
{
|
||||||
UAVTalkConnectionData *connection;
|
UAVTalkConnectionData *connection;
|
||||||
|
|
||||||
@ -145,6 +145,11 @@ void UAVTalkGetStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut)
|
|||||||
// Copy stats
|
// Copy stats
|
||||||
memcpy(statsOut, &connection->stats, sizeof(UAVTalkStats));
|
memcpy(statsOut, &connection->stats, sizeof(UAVTalkStats));
|
||||||
|
|
||||||
|
if (reset) {
|
||||||
|
// Clear stats
|
||||||
|
memset(&connection->stats, 0, sizeof(UAVTalkStats));
|
||||||
|
}
|
||||||
|
|
||||||
// Release lock
|
// Release lock
|
||||||
xSemaphoreGiveRecursive(connection->lock);
|
xSemaphoreGiveRecursive(connection->lock);
|
||||||
}
|
}
|
||||||
@ -154,7 +159,7 @@ void UAVTalkGetStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut)
|
|||||||
* \param[in] connection UAVTalkConnection to be used
|
* \param[in] connection UAVTalkConnection to be used
|
||||||
* @param[out] statsOut Statistics counters
|
* @param[out] statsOut Statistics counters
|
||||||
*/
|
*/
|
||||||
void UAVTalkAddStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut)
|
void UAVTalkAddStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut, bool reset)
|
||||||
{
|
{
|
||||||
UAVTalkConnectionData *connection;
|
UAVTalkConnectionData *connection;
|
||||||
|
|
||||||
@ -175,6 +180,11 @@ void UAVTalkAddStats(UAVTalkConnection connectionHandle, UAVTalkStats *statsOut)
|
|||||||
statsOut->rxSyncErrors += connection->stats.rxSyncErrors;
|
statsOut->rxSyncErrors += connection->stats.rxSyncErrors;
|
||||||
statsOut->rxCrcErrors += connection->stats.rxCrcErrors;
|
statsOut->rxCrcErrors += connection->stats.rxCrcErrors;
|
||||||
|
|
||||||
|
if (reset) {
|
||||||
|
// Clear stats
|
||||||
|
memset(&connection->stats, 0, sizeof(UAVTalkStats));
|
||||||
|
}
|
||||||
|
|
||||||
// Release lock
|
// Release lock
|
||||||
xSemaphoreGiveRecursive(connection->lock);
|
xSemaphoreGiveRecursive(connection->lock);
|
||||||
}
|
}
|
||||||
@ -589,7 +599,7 @@ UAVTalkRxState UAVTalkProcessInputStream(UAVTalkConnection connectionHandle, uin
|
|||||||
* \return 0 Success
|
* \return 0 Success
|
||||||
* \return -1 Failure
|
* \return -1 Failure
|
||||||
*/
|
*/
|
||||||
UAVTalkRxState UAVTalkRelayPacket(UAVTalkConnection inConnectionHandle, UAVTalkConnection outConnectionHandle)
|
int32_t UAVTalkRelayPacket(UAVTalkConnection inConnectionHandle, UAVTalkConnection outConnectionHandle)
|
||||||
{
|
{
|
||||||
UAVTalkConnectionData *inConnection;
|
UAVTalkConnectionData *inConnection;
|
||||||
|
|
||||||
@ -656,17 +666,17 @@ UAVTalkRxState UAVTalkRelayPacket(UAVTalkConnection inConnectionHandle, UAVTalkC
|
|||||||
outConnection->stats.txBytes += (rc > 0) ? rc : 0;
|
outConnection->stats.txBytes += (rc > 0) ? rc : 0;
|
||||||
|
|
||||||
// evaluate return value before releasing the lock
|
// evaluate return value before releasing the lock
|
||||||
UAVTalkRxState rxState = 0;
|
int32_t ret = 0;
|
||||||
if (rc != (int32_t)(headerLength + inIproc->length + UAVTALK_CHECKSUM_LENGTH)) {
|
if (rc != (int32_t)(headerLength + inIproc->length + UAVTALK_CHECKSUM_LENGTH)) {
|
||||||
outConnection->stats.txErrors++;
|
outConnection->stats.txErrors++;
|
||||||
rxState = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release lock
|
// Release lock
|
||||||
xSemaphoreGiveRecursive(outConnection->lock);
|
xSemaphoreGiveRecursive(outConnection->lock);
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
return rxState;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -862,7 +872,7 @@ static int32_t sendObject(UAVTalkConnectionData *connection, uint8_t type, uint3
|
|||||||
{
|
{
|
||||||
uint32_t numInst;
|
uint32_t numInst;
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
uint32_t ret = -1;
|
int32_t ret = -1;
|
||||||
|
|
||||||
// Important note : obj can be null (when type is NACK for example) so protect all obj dereferences.
|
// Important note : obj can be null (when type is NACK for example) so protect all obj dereferences.
|
||||||
|
|
||||||
@ -880,8 +890,8 @@ static int32_t sendObject(UAVTalkConnectionData *connection, uint8_t type, uint3
|
|||||||
// This allows the receiver to detect when the last object has been received (i.e. when instance 0 is received)
|
// This allows the receiver to detect when the last object has been received (i.e. when instance 0 is received)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
for (n = 0; n < numInst; ++n) {
|
for (n = 0; n < numInst; ++n) {
|
||||||
if (sendSingleObject(connection, type, objId, numInst - n - 1, obj) == -1) {
|
ret = sendSingleObject(connection, type, objId, numInst - n - 1, obj);
|
||||||
ret = -1;
|
if (ret == -1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -904,8 +914,7 @@ static int32_t sendObject(UAVTalkConnectionData *connection, uint8_t type, uint3
|
|||||||
* \param[in] connection UAVTalkConnection to be used
|
* \param[in] connection UAVTalkConnection to be used
|
||||||
* \param[in] type Transaction type
|
* \param[in] type Transaction type
|
||||||
* \param[in] objId The object ID
|
* \param[in] objId The object ID
|
||||||
* \param[in] instId The instance ID (can NOT be UAVOBJ_ALL_INSTANCES, use
|
* \param[in] instId The instance ID (can NOT be UAVOBJ_ALL_INSTANCES, use () instead)
|
||||||
() instead)
|
|
||||||
* \param[in] obj Object handle to send (null when type is NACK)
|
* \param[in] obj Object handle to send (null when type is NACK)
|
||||||
* \return 0 Success
|
* \return 0 Success
|
||||||
* \return -1 Failure
|
* \return -1 Failure
|
||||||
@ -982,7 +991,7 @@ static int32_t sendSingleObject(UAVTalkConnectionData *connection, uint8_t type,
|
|||||||
connection->stats.txBytes += tx_msg_len;
|
connection->stats.txBytes += tx_msg_len;
|
||||||
} else {
|
} else {
|
||||||
connection->stats.txErrors++;
|
connection->stats.txErrors++;
|
||||||
// TDOD rc == -1 connection not open, -2 buffer full should retry
|
// TODO rc == -1 connection not open, -2 buffer full should retry
|
||||||
connection->stats.txBytes += (rc > 0) ? rc : 0;
|
connection->stats.txBytes += (rc > 0) ? rc : 0;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,6 @@ private:
|
|||||||
|
|
||||||
static const int TX_BUFFER_SIZE = 2 * 1024;
|
static const int TX_BUFFER_SIZE = 2 * 1024;
|
||||||
|
|
||||||
static const quint8 crc_table[256];
|
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STATE_SYNC, STATE_TYPE, STATE_SIZE, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS, STATE_COMPLETE, STATE_ERROR
|
STATE_SYNC, STATE_TYPE, STATE_SIZE, STATE_OBJID, STATE_INSTID, STATE_DATA, STATE_CS, STATE_COMPLETE, STATE_ERROR
|
||||||
|
Loading…
x
Reference in New Issue
Block a user