mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-914: Reformatted the RadioComBridge module.
This commit is contained in:
parent
a9079bfb7e
commit
9bb3b5870c
@ -1,17 +1,17 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||
* @{
|
||||
* @addtogroup RadioComBridgeModule Com Port to Radio Bridge Module
|
||||
* @brief Bridge Com and Radio ports
|
||||
* @{
|
||||
*
|
||||
* @file RadioComBridge.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @brief Bridges selected Com Port to the COM VCP emulated serial port
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
******************************************************************************
|
||||
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||
* @{
|
||||
* @addtogroup RadioComBridgeModule Com Port to Radio Bridge Module
|
||||
* @brief Bridge Com and Radio ports
|
||||
* @{
|
||||
*
|
||||
* @file RadioComBridge.c
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
||||
* @brief Bridges selected Com Port to the COM VCP emulated serial port
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -118,8 +118,8 @@ static RadioComBridgeData *data;
|
||||
|
||||
/**
|
||||
* Start the module
|
||||
* \return -1 if initialisation failed
|
||||
* \return 0 on success
|
||||
*
|
||||
* @return -1 if initialisation failed, 0 on success
|
||||
*/
|
||||
static int32_t RadioComBridgeStart(void)
|
||||
{
|
||||
@ -137,8 +137,7 @@ static int32_t RadioComBridgeStart(void)
|
||||
if (is_coordinator) {
|
||||
|
||||
// Set the maximum radio RF power.
|
||||
switch (oplinkSettings.MaxRFPower)
|
||||
{
|
||||
switch (oplinkSettings.MaxRFPower) {
|
||||
case OPLINKSETTINGS_MAXRFPOWER_125:
|
||||
PIOS_RFM22B_SetTxPower(pios_rfm22b_id, RFM22_tx_pwr_txpow_0);
|
||||
break;
|
||||
@ -198,16 +197,17 @@ static int32_t RadioComBridgeStart(void)
|
||||
|
||||
/**
|
||||
* Initialise the module
|
||||
* \return -1 if initialisation failed
|
||||
* \return 0 on success
|
||||
*
|
||||
* @return -1 if initialisation failed on success
|
||||
*/
|
||||
static int32_t RadioComBridgeInitialize(void)
|
||||
{
|
||||
|
||||
// allocate and initialize the static data storage only if module is enabled
|
||||
data = (RadioComBridgeData *)pvPortMalloc(sizeof(RadioComBridgeData));
|
||||
if (!data)
|
||||
if (!data) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize the UAVObjects that we use
|
||||
OPLinkStatusInitialize();
|
||||
@ -241,6 +241,8 @@ MODULE_INITCALL(RadioComBridgeInitialize, RadioComBridgeStart)
|
||||
|
||||
/**
|
||||
* Telemetry transmit task, regular priority
|
||||
*
|
||||
* @param[in] parameters The task parameters
|
||||
*/
|
||||
static void telemetryTxTask(void *parameters)
|
||||
{
|
||||
@ -253,8 +255,7 @@ static void telemetryTxTask(void *parameters)
|
||||
#endif
|
||||
// Wait for queue message
|
||||
if (xQueueReceive(data->uavtalkEventQueue, &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)
|
||||
uint32_t retries = 0;
|
||||
int32_t success = -1;
|
||||
@ -264,9 +265,7 @@ static void telemetryTxTask(void *parameters)
|
||||
++retries;
|
||||
}
|
||||
data->comTxRetries += retries;
|
||||
}
|
||||
else if(ev.event == EV_SEND_ACK)
|
||||
{
|
||||
} else if(ev.event == EV_SEND_ACK) {
|
||||
// Send the ACK
|
||||
uint32_t retries = 0;
|
||||
int32_t success = -1;
|
||||
@ -276,9 +275,7 @@ static void telemetryTxTask(void *parameters)
|
||||
++retries;
|
||||
}
|
||||
data->comTxRetries += retries;
|
||||
}
|
||||
else if(ev.event == EV_SEND_NACK)
|
||||
{
|
||||
} else if(ev.event == EV_SEND_NACK) {
|
||||
// Send the NACK
|
||||
uint32_t retries = 0;
|
||||
int32_t success = -1;
|
||||
@ -295,6 +292,8 @@ static void telemetryTxTask(void *parameters)
|
||||
|
||||
/**
|
||||
* Radio rx task. Receive data packets from the radio and pass them on.
|
||||
*
|
||||
* @param[in] parameters The task parameters
|
||||
*/
|
||||
static void radioRxTask(void *parameters)
|
||||
{
|
||||
@ -305,15 +304,20 @@ static void radioRxTask(void *parameters)
|
||||
#endif
|
||||
uint8_t serial_data[1];
|
||||
uint16_t bytes_to_process = PIOS_COM_ReceiveBuffer(PIOS_COM_RADIO, serial_data, sizeof(serial_data), MAX_PORT_DELAY);
|
||||
if (bytes_to_process > 0)
|
||||
for (uint8_t i = 0; i < bytes_to_process; i++)
|
||||
if (UAVTalkRelayInputStream(data->outUAVTalkCon, serial_data[i]) == UAVTALK_STATE_ERROR)
|
||||
if (bytes_to_process > 0) {
|
||||
for (uint8_t i = 0; i < bytes_to_process; i++) {
|
||||
if (UAVTalkRelayInputStream(data->outUAVTalkCon, serial_data[i]) == UAVTALK_STATE_ERROR) {
|
||||
data->UAVTalkErrors++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Radio rx task. Receive data from a com port and pass it on to the radio.
|
||||
*
|
||||
* @param[in] parameters The task parameters
|
||||
*/
|
||||
static void radioTxTask(void *parameters)
|
||||
{
|
||||
@ -325,8 +329,9 @@ static void radioTxTask(void *parameters)
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_USB)
|
||||
// Determine output port (USB takes priority over telemetry port)
|
||||
if (PIOS_USB_CheckAvailable(0) && PIOS_COM_TELEM_USB_HID)
|
||||
if (PIOS_USB_CheckAvailable(0) && PIOS_COM_TELEM_USB_HID) {
|
||||
inputPort = PIOS_COM_TELEM_USB_HID;
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_USB */
|
||||
if(inputPort) {
|
||||
uint8_t serial_data[1];
|
||||
@ -335,38 +340,43 @@ static void radioTxTask(void *parameters)
|
||||
for (uint8_t i = 0; i < bytes_to_process; i++)
|
||||
ProcessInputStream(data->inUAVTalkCon, serial_data[i]);
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
vTaskDelay(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transmit data buffer to the com port.
|
||||
* \param[in] buf Data buffer to send
|
||||
* \param[in] length Length of buffer
|
||||
* \return -1 on failure
|
||||
* \return number of bytes transmitted on success
|
||||
*
|
||||
* @param[in] buf Data buffer to send
|
||||
* @param[in] length Length of buffer
|
||||
* @return -1 on failure
|
||||
* @return number of bytes transmitted on success
|
||||
*/
|
||||
static int32_t UAVTalkSendHandler(uint8_t *buf, int32_t length)
|
||||
{
|
||||
uint32_t outputPort = PIOS_COM_TELEMETRY;
|
||||
#if defined(PIOS_INCLUDE_USB)
|
||||
// Determine output port (USB takes priority over telemetry port)
|
||||
if (PIOS_COM_TELEM_USB_HID && PIOS_COM_Available(PIOS_COM_TELEM_USB_HID))
|
||||
if (PIOS_COM_TELEM_USB_HID && PIOS_COM_Available(PIOS_COM_TELEM_USB_HID)) {
|
||||
outputPort = PIOS_COM_TELEM_USB_HID;
|
||||
}
|
||||
#endif /* PIOS_INCLUDE_USB */
|
||||
if(outputPort)
|
||||
if(outputPort) {
|
||||
return PIOS_COM_SendBufferNonBlocking(outputPort, buf, length);
|
||||
else
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transmit data buffer to the com port.
|
||||
* \param[in] buf Data buffer to send
|
||||
* \param[in] length Length of buffer
|
||||
* \return -1 on failure
|
||||
* \return number of bytes transmitted on success
|
||||
*
|
||||
* @param[in] buf Data buffer to send
|
||||
* @param[in] length Length of buffer
|
||||
* @return -1 on failure
|
||||
* @return number of bytes transmitted on success
|
||||
*/
|
||||
static int32_t RadioSendHandler(uint8_t *buf, int32_t length)
|
||||
{
|
||||
@ -380,6 +390,12 @@ static int32_t RadioSendHandler(uint8_t *buf, int32_t length)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a byte of data received
|
||||
*
|
||||
* @param[in] connectionHandle The UAVTalk connection handle
|
||||
* @param[in] rxbyte The received byte.
|
||||
*/
|
||||
static void ProcessInputStream(UAVTalkConnection connectionHandle, uint8_t rxbyte)
|
||||
{
|
||||
// Keep reading until we receive a completed packet.
|
||||
@ -387,15 +403,12 @@ static void ProcessInputStream(UAVTalkConnection connectionHandle, uint8_t rxbyt
|
||||
UAVTalkConnectionData *connection = (UAVTalkConnectionData*)(connectionHandle);
|
||||
UAVTalkInputProcessor *iproc = &(connection->iproc);
|
||||
|
||||
if (state == UAVTALK_STATE_COMPLETE)
|
||||
{
|
||||
if (state == UAVTALK_STATE_COMPLETE) {
|
||||
// Is this a local UAVObject?
|
||||
// We only generate GcsReceiver ojects, we don't consume them.
|
||||
if ((iproc->obj != NULL) && (iproc->objId != GCSRECEIVER_OBJID))
|
||||
{
|
||||
if ((iproc->obj != NULL) && (iproc->objId != GCSRECEIVER_OBJID)) {
|
||||
// We treat the ObjectPersistence object differently
|
||||
if(iproc->objId == OBJECTPERSISTENCE_OBJID)
|
||||
{
|
||||
if(iproc->objId == OBJECTPERSISTENCE_OBJID) {
|
||||
// Unpack object, if the instance does not exist it will be created!
|
||||
UAVObjUnpack(iproc->obj, iproc->instId, connection->rxBuffer);
|
||||
|
||||
@ -404,15 +417,13 @@ static void ProcessInputStream(UAVTalkConnection connectionHandle, uint8_t rxbyt
|
||||
ObjectPersistenceGet(&obj_per);
|
||||
|
||||
// Is this concerning or setting object?
|
||||
if (obj_per.ObjectID == OPLINKSETTINGS_OBJID)
|
||||
{
|
||||
if (obj_per.ObjectID == OPLINKSETTINGS_OBJID) {
|
||||
// Queue up the ACK.
|
||||
queueEvent(data->uavtalkEventQueue, (void*)iproc->obj, iproc->instId, EV_SEND_ACK);
|
||||
|
||||
// Is this a save, load, or delete?
|
||||
bool success = true;
|
||||
switch (obj_per.Operation)
|
||||
{
|
||||
switch (obj_per.Operation) {
|
||||
case OBJECTPERSISTENCE_OPERATION_LOAD:
|
||||
{
|
||||
#if defined(PIOS_INCLUDE_FLASH_EEPROM)
|
||||
@ -453,17 +464,13 @@ static void ProcessInputStream(UAVTalkConnection connectionHandle, uint8_t rxbyt
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (success == true)
|
||||
{
|
||||
if (success == true) {
|
||||
obj_per.Operation = OBJECTPERSISTENCE_OPERATION_COMPLETED;
|
||||
ObjectPersistenceSet(&obj_per);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (iproc->type)
|
||||
{
|
||||
} else {
|
||||
switch (iproc->type) {
|
||||
case UAVTALK_TYPE_OBJ:
|
||||
// Unpack object, if the instance does not exist it will be created!
|
||||
UAVObjUnpack(iproc->obj, iproc->instId, connection->rxBuffer);
|
||||
@ -485,17 +492,19 @@ static void ProcessInputStream(UAVTalkConnection connectionHandle, uint8_t rxbyt
|
||||
data->UAVTalkErrors++;
|
||||
|
||||
// Send a NACK if required.
|
||||
if((iproc->obj) && (iproc->type == UAVTALK_TYPE_OBJ_ACK))
|
||||
if((iproc->obj) && (iproc->type == UAVTALK_TYPE_OBJ_ACK)) {
|
||||
// Queue up a NACK
|
||||
queueEvent(data->uavtalkEventQueue, iproc->obj, iproc->instId, EV_SEND_NACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue and event into an event queue.
|
||||
* \param[in] queue The event queue
|
||||
* \param[in] obj The data pointer
|
||||
* \param[in] type The event type
|
||||
*
|
||||
* @param[in] queue The event queue
|
||||
* @param[in] obj The data pointer
|
||||
* @param[in] type The event type
|
||||
*/
|
||||
static void queueEvent(xQueueHandle queue, void *obj, uint16_t instId, UAVObjEventType type)
|
||||
{
|
||||
@ -508,8 +517,9 @@ static void queueEvent(xQueueHandle queue, void *obj, uint16_t instId, UAVObjEve
|
||||
|
||||
/**
|
||||
* Configure the output port based on a configuration event from the remote coordinator.
|
||||
* \param[in] com_port The com port to configure
|
||||
* \param[in] com_speed The com port speed
|
||||
*
|
||||
* @param[in] com_port The com port to configure
|
||||
* @param[in] com_speed The com port speed
|
||||
*/
|
||||
static void configureComCallback(OPLinkSettingsRemoteMainPortOptions main_port, OPLinkSettingsRemoteFlexiPortOptions flexi_port,
|
||||
OPLinkSettingsRemoteVCPPortOptions vcp_port, OPLinkSettingsComSpeedOptions com_speed,
|
||||
@ -582,8 +592,7 @@ static void updateSettings()
|
||||
|
||||
// Configure the main port
|
||||
bool is_coordinator = PIOS_RFM22B_IsCoordinator(pios_rfm22b_id);
|
||||
switch (oplinkSettings.MainPort)
|
||||
{
|
||||
switch (oplinkSettings.MainPort) {
|
||||
case OPLINKSETTINGS_MAINPORT_TELEMETRY:
|
||||
data->parseUAVTalk = true;
|
||||
case OPLINKSETTINGS_MAINPORT_SERIAL:
|
||||
@ -599,8 +608,7 @@ static void updateSettings()
|
||||
}
|
||||
|
||||
// Configure the flexi port
|
||||
switch (oplinkSettings.FlexiPort)
|
||||
{
|
||||
switch (oplinkSettings.FlexiPort) {
|
||||
case OPLINKSETTINGS_FLEXIPORT_TELEMETRY:
|
||||
data->parseUAVTalk = true;
|
||||
case OPLINKSETTINGS_FLEXIPORT_SERIAL:
|
||||
@ -616,8 +624,7 @@ static void updateSettings()
|
||||
}
|
||||
|
||||
// Configure the USB VCP port
|
||||
switch (oplinkSettings.VCPPort)
|
||||
{
|
||||
switch (oplinkSettings.VCPPort) {
|
||||
case OPLINKSETTINGS_VCPPORT_SERIAL:
|
||||
PIOS_COM_TELEMETRY = PIOS_COM_TELEM_USB_VCP;
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user