From 6fbc3339d52ebfdace1dc02b6026fc13cf50d70d Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Thu, 17 May 2012 18:37:45 -0700 Subject: [PATCH 1/2] Fixed processing of UAVTalk packets when in transparent com mode. --- flight/Libraries/packet_handler.c | 2 +- .../Modules/RadioComBridge/RadioComBridge.c | 29 ++++++++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/flight/Libraries/packet_handler.c b/flight/Libraries/packet_handler.c index cbb82d77e..83d79990c 100644 --- a/flight/Libraries/packet_handler.c +++ b/flight/Libraries/packet_handler.c @@ -91,7 +91,7 @@ PHInstHandle PHInitialize(PacketHandlerConfig *cfg) data->lock = xSemaphoreCreateRecursiveMutex(); // Initialize the ECC library. - initialize_ecc(); + initialize_ecc(); // Return the structure. return (PHInstHandle)data; diff --git a/flight/Modules/RadioComBridge/RadioComBridge.c b/flight/Modules/RadioComBridge/RadioComBridge.c index 76c3040a5..429b76f02 100644 --- a/flight/Modules/RadioComBridge/RadioComBridge.c +++ b/flight/Modules/RadioComBridge/RadioComBridge.c @@ -291,7 +291,7 @@ static void comUAVTalkTask(void *parameters) data->txBytes++; // Get a TX packet from the packet handler if required. - if (p == NULL) + if ((p == NULL) && !PIOS_COM_TRANS_COM) { // Wait until we receive a sync. @@ -320,7 +320,8 @@ static void comUAVTalkTask(void *parameters) } // Insert this byte. - p->data[p->header.data_size++] = rx_byte; + if(p) + p->data[p->header.data_size++] = rx_byte; // Keep reading until we receive a completed packet. UAVTalkRxState state = UAVTalkProcessInputStreamQuiet(data->inUAVTalkCon, rx_byte); @@ -390,12 +391,14 @@ static void comUAVTalkTask(void *parameters) } // Release the packet, since we don't need it. - PHReleaseTXPacket(pios_packet_handler, p); + if(p) + PHReleaseTXPacket(pios_packet_handler, p); } else { - // Otherwise, queue the packet for transmission. - xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); + // Otherwise, queue the packet for transmission if we're using UAVTalk comms. + if(p) + xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); } } else @@ -425,13 +428,15 @@ static void comUAVTalkTask(void *parameters) } // Release the packet, since we don't need it. - PHReleaseTXPacket(pios_packet_handler, p); + if(p) + PHReleaseTXPacket(pios_packet_handler, p); } } else { - // Queue the packet for transmission. - xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); + // Queue the packet for transmission if we're using UAVTalk comms. + if(p) + xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); } p = NULL; @@ -449,12 +454,14 @@ static void comUAVTalkTask(void *parameters) xQueueSend(data->objEventQueue, &ev, MAX_PORT_DELAY); // Release the packet and start over again. - PHReleaseTXPacket(pios_packet_handler, p); + if(p) + PHReleaseTXPacket(pios_packet_handler, p); } else { // Transmit the packet anyway... - xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); + if(p) + xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); } p = NULL; } @@ -630,7 +637,7 @@ static void transparentCommTask(void * parameters) // Receive data from the com port uint32_t cur_rx_bytes = PIOS_COM_ReceiveBuffer(PIOS_COM_TRANS_COM, p->data + p->header.data_size, - PH_MAX_DATA - p->header.data_size, timeout); + PH_MAX_DATA - p->header.data_size, timeout); // Do we have an data to send? p->header.data_size += cur_rx_bytes; From 68d66d4181ddfe325e36f68fef1431f5966eca57 Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Thu, 17 May 2012 20:35:17 -0700 Subject: [PATCH 2/2] Fixed firmware description in PipX status. --- .../Modules/RadioComBridge/RadioComBridge.c | 30 ++++++-------- flight/PipXtreme/Makefile | 1 + .../plugins/config/configpipxtremewidget.cpp | 40 +++++++++++-------- 3 files changed, 36 insertions(+), 35 deletions(-) mode change 100755 => 100644 flight/PipXtreme/Makefile diff --git a/flight/Modules/RadioComBridge/RadioComBridge.c b/flight/Modules/RadioComBridge/RadioComBridge.c index 429b76f02..4b82ac9ed 100644 --- a/flight/Modules/RadioComBridge/RadioComBridge.c +++ b/flight/Modules/RadioComBridge/RadioComBridge.c @@ -291,7 +291,7 @@ static void comUAVTalkTask(void *parameters) data->txBytes++; // Get a TX packet from the packet handler if required. - if ((p == NULL) && !PIOS_COM_TRANS_COM) + if (p == NULL) { // Wait until we receive a sync. @@ -320,8 +320,7 @@ static void comUAVTalkTask(void *parameters) } // Insert this byte. - if(p) - p->data[p->header.data_size++] = rx_byte; + p->data[p->header.data_size++] = rx_byte; // Keep reading until we receive a completed packet. UAVTalkRxState state = UAVTalkProcessInputStreamQuiet(data->inUAVTalkCon, rx_byte); @@ -391,14 +390,12 @@ static void comUAVTalkTask(void *parameters) } // Release the packet, since we don't need it. - if(p) - PHReleaseTXPacket(pios_packet_handler, p); + PHReleaseTXPacket(pios_packet_handler, p); } else { - // Otherwise, queue the packet for transmission if we're using UAVTalk comms. - if(p) - xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); + // Otherwise, queue the packet for transmission. + xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); } } else @@ -428,15 +425,13 @@ static void comUAVTalkTask(void *parameters) } // Release the packet, since we don't need it. - if(p) - PHReleaseTXPacket(pios_packet_handler, p); + PHReleaseTXPacket(pios_packet_handler, p); } } else { - // Queue the packet for transmission if we're using UAVTalk comms. - if(p) - xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); + // Queue the packet for transmission. + xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); } p = NULL; @@ -454,14 +449,12 @@ static void comUAVTalkTask(void *parameters) xQueueSend(data->objEventQueue, &ev, MAX_PORT_DELAY); // Release the packet and start over again. - if(p) - PHReleaseTXPacket(pios_packet_handler, p); + PHReleaseTXPacket(pios_packet_handler, p); } else { // Transmit the packet anyway... - if(p) - xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); + xQueueSend(data->sendPacketQueue, &p, MAX_PORT_DELAY); } p = NULL; } @@ -637,7 +630,7 @@ static void transparentCommTask(void * parameters) // Receive data from the com port uint32_t cur_rx_bytes = PIOS_COM_ReceiveBuffer(PIOS_COM_TRANS_COM, p->data + p->header.data_size, - PH_MAX_DATA - p->header.data_size, timeout); + PH_MAX_DATA - p->header.data_size, timeout); // Do we have an data to send? p->header.data_size += cur_rx_bytes; @@ -698,6 +691,7 @@ static void radioStatusTask(void *parameters) PipXSettingsPairIDGet(&pairID); // Update the status + PIOS_BL_HELPER_FLASH_Read_Description(pipxStatus.Description, PIPXSTATUS_DESCRIPTION_NUMELEM); pipxStatus.DeviceID = PIOS_RFM22B_DeviceID(pios_rfm22b_id); pipxStatus.RSSI = PIOS_RFM22B_RSSI(pios_rfm22b_id); pipxStatus.Retries = data->comTxRetries; diff --git a/flight/PipXtreme/Makefile b/flight/PipXtreme/Makefile old mode 100755 new mode 100644 index 3123cacc2..8872a9f8d --- a/flight/PipXtreme/Makefile +++ b/flight/PipXtreme/Makefile @@ -160,6 +160,7 @@ SRC += $(PIOSSTM32F10X)/pios_wdg.c SRC += $(PIOSSTM32F10X)/pios_tim.c SRC += $(PIOSSTM32F10X)/pios_pwm.c SRC += $(PIOSSTM32F10X)/pios_eeprom.c +SRC += $(PIOSSTM32F10X)/pios_bl_helper.c # PIOS USB related files (separated to make code maintenance more easy) SRC += $(PIOSSTM32F10X)/pios_usb.c diff --git a/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp b/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp index a5e934c99..f4d20fc5d 100644 --- a/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp +++ b/ground/openpilotgcs/src/plugins/config/configpipxtremewidget.cpp @@ -188,10 +188,29 @@ void ConfigPipXtremeWidget::updateStatus(UAVObject *object) // Update the Description field UAVObjectField* descField = object->getField("Description"); if (descField) { + /* + * This looks like a binary with a description at the end + * 4 bytes: header: "OpFw" + * 4 bytes: git commit hash (short version of SHA1) + * 4 bytes: Unix timestamp of last git commit + * 2 bytes: target platform. Should follow same rule as BOARD_TYPE and BOARD_REVISION in board define files. + * 26 bytes: commit tag if it is there, otherwise "Unreleased". Zero-padded + * ---- 40 bytes limit --- + * 20 bytes: SHA1 sum of the firmware. + * 40 bytes: free for now. + */ char buf[PipXStatus::DESCRIPTION_NUMELEM]; - for (unsigned int i = 0; i < PipXStatus::DESCRIPTION_NUMELEM; ++i) - buf[i] = descField->getValue(i).toChar().toAscii(); - m_pipx->FirmwareVersion->setText(buf); + for (unsigned int i = 0; i < 26; ++i) + buf[i] = descField->getValue(i + 14).toChar().toAscii(); + buf[26] = '\0'; + QString descstr(buf); + quint32 gitDate = descField->getValue(11).toChar().toAscii() & 0xFF; + for (int i = 1; i < 4; i++) { + gitDate = gitDate << 8; + gitDate += descField->getValue(11-i).toChar().toAscii() & 0xFF; + } + QString date = QDateTime::fromTime_t(gitDate).toUTC().toString("yyyy-MM-dd HH:mm"); + m_pipx->FirmwareVersion->setText(descstr + " " + date); } else { qDebug() << "PipXtremeGadgetWidget: Count not read Description field."; } @@ -224,20 +243,7 @@ void ConfigPipXtremeWidget::updateStatus(UAVObject *object) // Update the link state UAVObjectField* linkField = object->getField("LinkState"); if (linkField) { - const char *msg = "Unknown"; - switch (linkField->getValue().toInt()) - { - case PipXStatus::LINKSTATE_DISCONNECTED: - msg = "Disconnected"; - break; - case PipXStatus::LINKSTATE_CONNECTING: - msg = "Connecting"; - break; - case PipXStatus::LINKSTATE_CONNECTED: - msg = "Connected"; - break; - } - m_pipx->LinkState->setText(msg); + m_pipx->LinkState->setText(linkField->getValue().toString()); } else { qDebug() << "PipXtremeGadgetWidget: Count not read link state field."; }