1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

uavtalk: convert tx to use blocking send routines

The uavtalk layer was previously implementing a poor
version of packet fragmentation based on a hard-coded
max packet size.  Since this was hard-coded, there was
no guarantee that it would match the underlying devices.

Now that the COM layer sending routines support fragmentation,
remove fragmentation and use the COM layer directly.

This will support future buffer size reductions in the COM
layer.
This commit is contained in:
Stacey Sheldon 2011-12-27 12:19:05 -05:00
parent 16619584e4
commit 785a7ccd88
3 changed files with 25 additions and 26 deletions

View File

@ -133,7 +133,7 @@ int32_t TelemetryInitialize(void)
updateSettings();
// Initialise UAVTalk
uavTalkCon = UAVTalkInitialize(&transmitData,256);
uavTalkCon = UAVTalkInitialize(&transmitData);
// Create periodic event that will be used to update the telemetry stats
txErrors = 0;
@ -339,7 +339,8 @@ static void telemetryRxTask(void *parameters)
* Transmit data buffer to the modem or USB port.
* \param[in] data Data buffer to send
* \param[in] length Length of buffer
* \return 0 Success
* \return -1 on failure
* \return number of bytes transmitted on success
*/
static int32_t transmitData(uint8_t * data, int32_t length)
{
@ -356,7 +357,7 @@ static int32_t transmitData(uint8_t * data, int32_t length)
}
if (outputPort) {
return PIOS_COM_SendBufferNonBlocking(outputPort, data, length);
return PIOS_COM_SendBuffer(outputPort, data, length);
} else {
return -1;
}

View File

@ -46,7 +46,7 @@ typedef struct {
typedef void* UAVTalkConnection;
// Public functions
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream, uint32_t maxPacketSize);
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream);
int32_t UAVTalkSetOutputStream(UAVTalkConnection connection, UAVTalkOutputStream outputStream);
UAVTalkOutputStream UAVTalkGetOutputStream(UAVTalkConnection connection);
int32_t UAVTalkSendObject(UAVTalkConnection connection, UAVObjHandle obj, uint16_t instId, uint8_t acked, int32_t timeoutMs);

View File

@ -48,9 +48,8 @@ static void updateAck(UAVTalkConnectionData *connection, UAVObjHandle obj, uint1
* \return 0 Success
* \return -1 Failure
*/
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream, uint32_t maxPacketSize)
UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream)
{
if (maxPacketSize<1) return 0;
// allocate object
UAVTalkConnectionData * connection = pvPortMalloc(sizeof(UAVTalkConnectionData));
if (!connection) return 0;
@ -60,7 +59,6 @@ UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream, uint32_t m
connection->outStream = outputStream;
connection->lock = xSemaphoreCreateRecursiveMutex();
connection->transLock = xSemaphoreCreateRecursiveMutex();
connection->txSize = maxPacketSize;
// allocate buffers
connection->rxBuffer = pvPortMalloc(UAVTALK_MAX_PACKET_LENGTH);
if (!connection->rxBuffer) return 0;
@ -646,7 +644,9 @@ static int32_t sendSingleObject(UAVTalkConnectionData *connection, UAVObjHandle
int32_t length;
int32_t dataOffset;
uint32_t objId;
if (!connection->outStream) return -1;
// Setup type and object id fields
objId = UAVObjGetID(obj);
connection->txBuffer[0] = UAVTALK_SYNC_VAL; // sync byte
@ -701,22 +701,16 @@ static int32_t sendSingleObject(UAVTalkConnectionData *connection, UAVObjHandle
// Calculate checksum
connection->txBuffer[dataOffset+length] = PIOS_CRC_updateCRC(0, connection->txBuffer, dataOffset+length);
// Send buffer (partially if needed)
uint32_t sent=0;
while (sent < dataOffset+length+UAVTALK_CHECKSUM_LENGTH) {
uint32_t sending = dataOffset+length+UAVTALK_CHECKSUM_LENGTH - sent;
if ( sending > connection->txSize ) sending = connection->txSize;
if ( connection->outStream != NULL ) {
(*connection->outStream)(connection->txBuffer+sent, sending);
}
sent += sending;
uint16_t tx_msg_len = dataOffset+length+UAVTALK_CHECKSUM_LENGTH;
int32_t rc = (*connection->outStream)(connection->txBuffer, tx_msg_len);
if (rc == tx_msg_len) {
// Update stats
++connection->stats.txObjects;
connection->stats.txBytes += tx_msg_len;
connection->stats.txObjectBytes += length;
}
// Update stats
++connection->stats.txObjects;
connection->stats.txBytes += dataOffset+length+UAVTALK_CHECKSUM_LENGTH;
connection->stats.txObjectBytes += length;
// Done
return 0;
}
@ -732,6 +726,8 @@ static int32_t sendNack(UAVTalkConnectionData *connection, uint32_t objId)
{
int32_t dataOffset;
if (!connection->outStream) return -1;
connection->txBuffer[0] = UAVTALK_SYNC_VAL; // sync byte
connection->txBuffer[1] = UAVTALK_TYPE_NACK;
// data length inserted here below
@ -749,11 +745,13 @@ static int32_t sendNack(UAVTalkConnectionData *connection, uint32_t objId)
// Calculate checksum
connection->txBuffer[dataOffset] = PIOS_CRC_updateCRC(0, connection->txBuffer, dataOffset);
// Send buffer
if (connection->outStream!=NULL) (*connection->outStream)(connection->txBuffer, dataOffset+UAVTALK_CHECKSUM_LENGTH);
uint16_t tx_msg_len = dataOffset+UAVTALK_CHECKSUM_LENGTH;
int32_t rc = (*connection->outStream)(connection->txBuffer, tx_msg_len);
// Update stats
connection->stats.txBytes += dataOffset+UAVTALK_CHECKSUM_LENGTH;
if (rc == tx_msg_len) {
// Update stats
connection->stats.txBytes += tx_msg_len;
}
// Done
return 0;