mirror of
https://github.com/EdgeTX/edgetx.git
synced 2025-07-21 23:35:12 +03:00
[Horus] S.PORT devices update should work (not tested)
[Horus] SD Manager files renaming fixed (quick & dirty, I would prefer a popup)
This commit is contained in:
parent
fd138cf22a
commit
cc2c2b094e
22 changed files with 585 additions and 500 deletions
|
@ -61,75 +61,6 @@ inline bool isFilenameLower(bool isfile, const char * fn, const char * line)
|
||||||
return (!isfile && IS_FILE(line)) || (isfile==IS_FILE(line) && strcasecmp(fn, line) < 0);
|
return (!isfile && IS_FILE(line)) || (isfile==IS_FILE(line) && strcasecmp(fn, line) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBootloader(const char * filename)
|
|
||||||
{
|
|
||||||
FIL file;
|
|
||||||
f_open(&file, filename, FA_READ);
|
|
||||||
uint8_t buffer[1024];
|
|
||||||
UINT count;
|
|
||||||
|
|
||||||
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isBootloaderStart((uint32_t *)buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void flashBootloader(const char * filename)
|
|
||||||
{
|
|
||||||
FIL file;
|
|
||||||
f_open(&file, filename, FA_READ);
|
|
||||||
uint8_t buffer[1024];
|
|
||||||
UINT count;
|
|
||||||
|
|
||||||
lcdClear();
|
|
||||||
drawProgressBar(STR_WRITING);
|
|
||||||
|
|
||||||
static uint8_t unlocked = 0;
|
|
||||||
if (!unlocked) {
|
|
||||||
unlocked = 1;
|
|
||||||
unlockFlash();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i=0; i<BOOTLOADER_SIZE; i+=1024) {
|
|
||||||
watchdogSuspend(100/*1s*/);
|
|
||||||
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
|
|
||||||
POPUP_WARNING(STR_SDCARD_ERROR);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i==0 && !isBootloaderStart((uint32_t *)buffer)) {
|
|
||||||
POPUP_WARNING(STR_INCOMPATIBLE);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (int j=0; j<1024; j+=FLASH_PAGESIZE) {
|
|
||||||
writeFlash(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
|
|
||||||
}
|
|
||||||
updateProgressBar(i, BOOTLOADER_SIZE);
|
|
||||||
SIMU_SLEEP(30/*ms*/);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unlocked) {
|
|
||||||
lockFlash();
|
|
||||||
unlocked = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
f_close(&file);
|
|
||||||
}
|
|
||||||
|
|
||||||
void flashSportDevice(ModuleIndex module, const char *filename)
|
|
||||||
{
|
|
||||||
pausePulses();
|
|
||||||
watchdogSuspend(60*60*100/*1h*/);
|
|
||||||
|
|
||||||
lcdClear();
|
|
||||||
drawProgressBar(STR_WRITING);
|
|
||||||
|
|
||||||
sportFirmwareUpdate(module, filename);
|
|
||||||
|
|
||||||
watchdogSuspend(100/*1s*/);
|
|
||||||
resumePulses();
|
|
||||||
}
|
|
||||||
|
|
||||||
void getSelectionFullPath(char *lfn)
|
void getSelectionFullPath(char *lfn)
|
||||||
{
|
{
|
||||||
f_getcwd(lfn, _MAX_LFN);
|
f_getcwd(lfn, _MAX_LFN);
|
||||||
|
@ -137,7 +68,7 @@ void getSelectionFullPath(char *lfn)
|
||||||
strcat(lfn, reusableBuffer.sdmanager.lines[menuVerticalPosition - menuVerticalOffset]);
|
strcat(lfn, reusableBuffer.sdmanager.lines[menuVerticalPosition - menuVerticalOffset]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSdManagerMenu(const char *result)
|
void onSdManagerMenu(const char * result)
|
||||||
{
|
{
|
||||||
TCHAR lfn[_MAX_LFN+1];
|
TCHAR lfn[_MAX_LFN+1];
|
||||||
|
|
||||||
|
@ -209,15 +140,15 @@ void onSdManagerMenu(const char *result)
|
||||||
}
|
}
|
||||||
else if (result == STR_FLASH_BOOTLOADER) {
|
else if (result == STR_FLASH_BOOTLOADER) {
|
||||||
getSelectionFullPath(lfn);
|
getSelectionFullPath(lfn);
|
||||||
flashBootloader(lfn);
|
bootloaderFlash(lfn);
|
||||||
}
|
}
|
||||||
else if (result == STR_FLASH_INTERNAL_MODULE) {
|
else if (result == STR_FLASH_INTERNAL_MODULE) {
|
||||||
getSelectionFullPath(lfn);
|
getSelectionFullPath(lfn);
|
||||||
flashSportDevice(INTERNAL_MODULE, lfn);
|
sportFlashDevice(INTERNAL_MODULE, lfn);
|
||||||
}
|
}
|
||||||
else if (result == STR_FLASH_EXTERNAL_DEVICE) {
|
else if (result == STR_FLASH_EXTERNAL_DEVICE) {
|
||||||
getSelectionFullPath(lfn);
|
getSelectionFullPath(lfn);
|
||||||
flashSportDevice(EXTERNAL_MODULE, lfn);
|
sportFlashDevice(EXTERNAL_MODULE, lfn);
|
||||||
}
|
}
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
else if (result == STR_EXECUTE_FILE) {
|
else if (result == STR_EXECUTE_FILE) {
|
||||||
|
|
|
@ -128,23 +128,18 @@ void onSdManagerMenu(const char * result)
|
||||||
audioQueue.stopAll();
|
audioQueue.stopAll();
|
||||||
audioQueue.playFile(lfn, 0, ID_PLAY_FROM_SD_MANAGER);
|
audioQueue.playFile(lfn, 0, ID_PLAY_FROM_SD_MANAGER);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
else if (result == STR_ASSIGN_BITMAP) {
|
|
||||||
strAppendFilename(g_model.header.bitmap, line, sizeof(g_model.header.bitmap));
|
|
||||||
memcpy(modelHeaders[g_eeGeneral.currModel].bitmap, g_model.header.bitmap, sizeof(g_model.header.bitmap));
|
|
||||||
storageDirty(EE_MODEL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
else if (result == STR_VIEW_TEXT) {
|
else if (result == STR_VIEW_TEXT) {
|
||||||
getSelectionFullPath(lfn);
|
getSelectionFullPath(lfn);
|
||||||
pushMenuTextView(lfn);
|
pushMenuTextView(lfn);
|
||||||
}
|
}
|
||||||
#if 0
|
else if (result == STR_FLASH_INTERNAL_MODULE) {
|
||||||
else if (result == STR_FLASH_BOOTLOADER) {
|
|
||||||
getSelectionFullPath(lfn);
|
getSelectionFullPath(lfn);
|
||||||
flashBootloader(lfn);
|
sportFlashDevice(INTERNAL_MODULE, lfn);
|
||||||
|
}
|
||||||
|
else if (result == STR_FLASH_EXTERNAL_DEVICE) {
|
||||||
|
getSelectionFullPath(lfn);
|
||||||
|
sportFlashDevice(EXTERNAL_MODULE, lfn);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
else if (result == STR_EXECUTE_FILE) {
|
else if (result == STR_EXECUTE_FILE) {
|
||||||
getSelectionFullPath(lfn);
|
getSelectionFullPath(lfn);
|
||||||
|
@ -276,7 +271,7 @@ bool menuRadioSdManager(event_t _event)
|
||||||
|
|
||||||
reusableBuffer.sdmanager.count = 0;
|
reusableBuffer.sdmanager.count = 0;
|
||||||
|
|
||||||
FRESULT res = f_opendir(&dir, "."); /* Open the directory */
|
FRESULT res = f_opendir(&dir, "."); // Open the directory
|
||||||
if (res == FR_OK) {
|
if (res == FR_OK) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
res = f_readdir(&dir, &fno); /* Read a directory item */
|
res = f_readdir(&dir, &fno); /* Read a directory item */
|
||||||
|
@ -294,8 +289,8 @@ bool menuRadioSdManager(event_t _event)
|
||||||
bool isfile = !(fno.fattrib & AM_DIR);
|
bool isfile = !(fno.fattrib & AM_DIR);
|
||||||
|
|
||||||
if (menuVerticalOffset == 0) {
|
if (menuVerticalOffset == 0) {
|
||||||
for (int i=0; i<NUM_BODY_LINES; i++) {
|
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
||||||
char *line = reusableBuffer.sdmanager.lines[i];
|
char * line = reusableBuffer.sdmanager.lines[i];
|
||||||
if (line[0] == '\0' || isFilenameLower(isfile, fn, line)) {
|
if (line[0] == '\0' || isFilenameLower(isfile, fn, line)) {
|
||||||
if (i < NUM_BODY_LINES-1) memmove(reusableBuffer.sdmanager.lines[i+1], line, sizeof(reusableBuffer.sdmanager.lines[i]) * (NUM_BODY_LINES-1-i));
|
if (i < NUM_BODY_LINES-1) memmove(reusableBuffer.sdmanager.lines[i+1], line, sizeof(reusableBuffer.sdmanager.lines[i]) * (NUM_BODY_LINES-1-i));
|
||||||
memset(line, 0, sizeof(reusableBuffer.sdmanager.lines[0]));
|
memset(line, 0, sizeof(reusableBuffer.sdmanager.lines[0]));
|
||||||
|
@ -341,7 +336,22 @@ bool menuRadioSdManager(event_t _event)
|
||||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||||
LcdFlags attr = (index == i ? INVERS : 0);
|
LcdFlags attr = (index == i ? INVERS : 0);
|
||||||
if (reusableBuffer.sdmanager.lines[i][0]) {
|
if (reusableBuffer.sdmanager.lines[i][0]) {
|
||||||
if (IS_DIRECTORY(reusableBuffer.sdmanager.lines[i])) {
|
if (s_editMode == EDIT_MODIFY_STRING && attr) {
|
||||||
|
editName(MENUS_MARGIN_LEFT, y, reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH-4, _event, attr, 0);
|
||||||
|
if (s_editMode == 0) {
|
||||||
|
unsigned int len = effectiveLen(reusableBuffer.sdmanager.lines[i], SD_SCREEN_FILE_LENGTH-LEN_FILE_EXTENSION);
|
||||||
|
char * ext = getFileExtension(reusableBuffer.sdmanager.originalName, sizeof(reusableBuffer.sdmanager.originalName));
|
||||||
|
if (ext) {
|
||||||
|
strAppend(&reusableBuffer.sdmanager.lines[i][len], ext);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
reusableBuffer.sdmanager.lines[i][len] = 0;
|
||||||
|
}
|
||||||
|
f_rename(reusableBuffer.sdmanager.originalName, reusableBuffer.sdmanager.lines[i]);
|
||||||
|
REFRESH_FILES();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (IS_DIRECTORY(reusableBuffer.sdmanager.lines[i])) {
|
||||||
char s[sizeof(reusableBuffer.sdmanager.lines[0])+2];
|
char s[sizeof(reusableBuffer.sdmanager.lines[0])+2];
|
||||||
char * ptr = s;
|
char * ptr = s;
|
||||||
*ptr++ = '[';
|
*ptr++ = '[';
|
||||||
|
|
76
radio/src/io/bootloader_flash.cpp
Normal file
76
radio/src/io/bootloader_flash.cpp
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "opentx.h"
|
||||||
|
|
||||||
|
bool isBootloader(const char * filename)
|
||||||
|
{
|
||||||
|
FIL file;
|
||||||
|
f_open(&file, filename, FA_READ);
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
UINT count;
|
||||||
|
|
||||||
|
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return isBootloaderStart(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bootloaderFlash(const char * filename)
|
||||||
|
{
|
||||||
|
FIL file;
|
||||||
|
f_open(&file, filename, FA_READ);
|
||||||
|
uint8_t buffer[1024];
|
||||||
|
UINT count;
|
||||||
|
|
||||||
|
lcdClear();
|
||||||
|
drawProgressBar(STR_WRITING);
|
||||||
|
|
||||||
|
static uint8_t unlocked = 0;
|
||||||
|
if (!unlocked) {
|
||||||
|
unlocked = 1;
|
||||||
|
unlockFlash();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<BOOTLOADER_SIZE; i+=1024) {
|
||||||
|
watchdogSuspend(100/*1s*/);
|
||||||
|
if (f_read(&file, buffer, 1024, &count) != FR_OK || count != 1024) {
|
||||||
|
POPUP_WARNING(STR_SDCARD_ERROR);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i==0 && !isBootloaderStart(buffer)) {
|
||||||
|
POPUP_WARNING(STR_INCOMPATIBLE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (int j=0; j<1024; j+=FLASH_PAGESIZE) {
|
||||||
|
flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
|
||||||
|
}
|
||||||
|
updateProgressBar(i, BOOTLOADER_SIZE);
|
||||||
|
SIMU_SLEEP(30/*ms*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unlocked) {
|
||||||
|
lockFlash();
|
||||||
|
unlocked = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
f_close(&file);
|
||||||
|
}
|
338
radio/src/io/frsky_sport.cpp
Normal file
338
radio/src/io/frsky_sport.cpp
Normal file
|
@ -0,0 +1,338 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "opentx.h"
|
||||||
|
|
||||||
|
#if defined(STM32)
|
||||||
|
#define PRIM_REQ_POWERUP (0)
|
||||||
|
#define PRIM_REQ_VERSION (1)
|
||||||
|
#define PRIM_CMD_DOWNLOAD (3)
|
||||||
|
#define PRIM_DATA_WORD (4)
|
||||||
|
#define PRIM_DATA_EOF (5)
|
||||||
|
|
||||||
|
#define PRIM_ACK_POWERUP (0x80)
|
||||||
|
#define PRIM_ACK_VERSION (0x81)
|
||||||
|
#define PRIM_REQ_DATA_ADDR (0x82)
|
||||||
|
#define PRIM_END_DOWNLOAD (0x83)
|
||||||
|
#define PRIM_DATA_CRC_ERR (0x84)
|
||||||
|
|
||||||
|
enum SportUpdateState {
|
||||||
|
SPORT_IDLE,
|
||||||
|
SPORT_POWERUP_REQ,
|
||||||
|
SPORT_POWERUP_ACK,
|
||||||
|
SPORT_VERSION_REQ,
|
||||||
|
SPORT_VERSION_ACK,
|
||||||
|
SPORT_DATA_TRANSFER,
|
||||||
|
SPORT_DATA_REQ,
|
||||||
|
SPORT_COMPLETE,
|
||||||
|
SPORT_FAIL
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t sportUpdateState = SPORT_IDLE;
|
||||||
|
uint32_t sportUpdateAddr = 0;
|
||||||
|
|
||||||
|
void sportOutputPushByte(uint8_t byte)
|
||||||
|
{
|
||||||
|
if (byte == 0x7E || byte == 0x7D) {
|
||||||
|
telemetryOutputPushByte(0x7D);
|
||||||
|
telemetryOutputPushByte(0x20 ^ byte);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
telemetryOutputPushByte(byte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSportOutputBufferAvailable()
|
||||||
|
{
|
||||||
|
return (outputTelemetryBufferSize == 0 && outputTelemetryBufferTrigger == 0x7E);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO merge it with S.PORT update function when finished
|
||||||
|
void sportOutputPushPacket(SportTelemetryPacket * packet)
|
||||||
|
{
|
||||||
|
uint16_t crc = 0;
|
||||||
|
|
||||||
|
for (uint8_t i=1; i<sizeof(SportTelemetryPacket); i++) {
|
||||||
|
uint8_t byte = packet->raw[i];
|
||||||
|
sportOutputPushByte(byte);
|
||||||
|
crc += byte; // 0-1FF
|
||||||
|
crc += crc >> 8; // 0-100
|
||||||
|
crc &= 0x00ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
telemetryOutputPushByte(0xFF-crc);
|
||||||
|
telemetryOutputSetTrigger(packet->raw[0]); // physicalId
|
||||||
|
}
|
||||||
|
|
||||||
|
void sportProcessUpdatePacket(uint8_t * packet)
|
||||||
|
{
|
||||||
|
if (packet[0]==0x5E && packet[1]==0x50) {
|
||||||
|
switch (packet[2]) {
|
||||||
|
case PRIM_ACK_POWERUP :
|
||||||
|
if (sportUpdateState == SPORT_POWERUP_REQ) {
|
||||||
|
sportUpdateState = SPORT_POWERUP_ACK;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRIM_ACK_VERSION:
|
||||||
|
if (sportUpdateState == SPORT_VERSION_REQ) {
|
||||||
|
sportUpdateState = SPORT_VERSION_ACK;
|
||||||
|
// SportVersion[0] = packet[3] ;
|
||||||
|
// SportVersion[1] = packet[4] ;
|
||||||
|
// SportVersion[2] = packet[5] ;
|
||||||
|
// SportVersion[3] = packet[6] ;
|
||||||
|
// SportVerValid = 1 ;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRIM_REQ_DATA_ADDR :
|
||||||
|
if (sportUpdateState == SPORT_DATA_TRANSFER) {
|
||||||
|
sportUpdateAddr = *((uint32_t *)(&packet[3]));
|
||||||
|
sportUpdateState = SPORT_DATA_REQ;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRIM_END_DOWNLOAD :
|
||||||
|
sportUpdateState = SPORT_COMPLETE ;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PRIM_DATA_CRC_ERR :
|
||||||
|
sportUpdateState = SPORT_FAIL ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sportWaitState(SportUpdateState state, int timeout)
|
||||||
|
{
|
||||||
|
#if defined(SIMU)
|
||||||
|
SIMU_SLEEP_NORET(1);
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
watchdogSuspend(timeout / 10);
|
||||||
|
for (int i=timeout/2; i>=0; i--) {
|
||||||
|
uint8_t byte ;
|
||||||
|
while (telemetryGetByte(&byte)) {
|
||||||
|
processFrskyTelemetryData(byte);
|
||||||
|
}
|
||||||
|
if (sportUpdateState == state) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (sportUpdateState == SPORT_FAIL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CoTickDelay(1);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void sportClearPacket(uint8_t * packet)
|
||||||
|
{
|
||||||
|
memset(packet+2, 0, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO merge this function
|
||||||
|
void sportWritePacket(uint8_t * packet)
|
||||||
|
{
|
||||||
|
uint8_t * ptr = outputTelemetryBuffer;
|
||||||
|
*ptr++ = 0x7E;
|
||||||
|
*ptr++ = 0xFF;
|
||||||
|
packet[7] = crc16(packet, 7);
|
||||||
|
for (int i=0; i<8; i++) {
|
||||||
|
if (packet[i] == 0x7E || packet[i] == 0x7D) {
|
||||||
|
*ptr++ = 0x7D;
|
||||||
|
*ptr++ = 0x20 ^ packet[i];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
*ptr++ = packet[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sportSendBuffer(outputTelemetryBuffer, ptr-outputTelemetryBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sportUpdatePowerOn(ModuleIndex module)
|
||||||
|
{
|
||||||
|
uint8_t packet[8];
|
||||||
|
|
||||||
|
sportUpdateState = SPORT_POWERUP_REQ;
|
||||||
|
|
||||||
|
sportWaitState(SPORT_IDLE, 500); // Clear the fifo
|
||||||
|
|
||||||
|
telemetryPortInit(FRSKY_SPORT_BAUDRATE, TELEMETRY_SERIAL_8N1);
|
||||||
|
|
||||||
|
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||||
|
if (module == INTERNAL_MODULE)
|
||||||
|
INTERNAL_MODULE_ON();
|
||||||
|
else
|
||||||
|
EXTERNAL_MODULE_ON();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sportWaitState(SPORT_IDLE, 50); // Clear the fifo
|
||||||
|
|
||||||
|
for (int i=0; i<10; i++) {
|
||||||
|
// max 10 attempts
|
||||||
|
sportClearPacket(packet);
|
||||||
|
packet[0] = 0x50 ;
|
||||||
|
packet[1] = PRIM_REQ_POWERUP;
|
||||||
|
sportWritePacket(packet);
|
||||||
|
if (sportWaitState(SPORT_POWERUP_ACK, 100))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sportUpdateReqVersion()
|
||||||
|
{
|
||||||
|
uint8_t packet[8];
|
||||||
|
sportWaitState(SPORT_IDLE, 20); // Clear the fifo
|
||||||
|
sportUpdateState = SPORT_VERSION_REQ;
|
||||||
|
for (int i=0; i<10; i++) {
|
||||||
|
// max 10 attempts
|
||||||
|
sportClearPacket(packet) ;
|
||||||
|
packet[0] = 0x50 ;
|
||||||
|
packet[1] = PRIM_REQ_VERSION ;
|
||||||
|
sportWritePacket(packet);
|
||||||
|
if (sportWaitState(SPORT_VERSION_ACK, 200))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sportUpdateUploadFile(const char *filename)
|
||||||
|
{
|
||||||
|
FIL file;
|
||||||
|
uint32_t buffer[1024/4];
|
||||||
|
UINT count;
|
||||||
|
uint8_t packet[8];
|
||||||
|
|
||||||
|
if (f_open(&file, filename, FA_READ) != FR_OK) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
sportWaitState(SPORT_IDLE, 200); // Clear the fifo
|
||||||
|
sportUpdateState = SPORT_DATA_TRANSFER;
|
||||||
|
sportClearPacket(packet) ;
|
||||||
|
packet[0] = 0x50 ;
|
||||||
|
packet[1] = PRIM_CMD_DOWNLOAD ;
|
||||||
|
// Stop here for testing
|
||||||
|
sportWritePacket(packet);
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
if (f_read(&file, buffer, 1024, &count) != FR_OK) {
|
||||||
|
f_close(&file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
count >>= 2;
|
||||||
|
|
||||||
|
for (UINT i=0; i<count; i++) {
|
||||||
|
if (!sportWaitState(SPORT_DATA_REQ, 2000)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
packet[0] = 0x50 ;
|
||||||
|
packet[1] = PRIM_DATA_WORD ;
|
||||||
|
packet[6] = sportUpdateAddr & 0x000000FF;
|
||||||
|
uint32_t offset = ( sportUpdateAddr & 1023 ) >> 2; // 32 bit word offset into buffer
|
||||||
|
uint32_t *data = (uint32_t *)(&packet[2]);
|
||||||
|
*data = buffer[offset];
|
||||||
|
sportUpdateState = SPORT_DATA_TRANSFER,
|
||||||
|
sportWritePacket(packet);
|
||||||
|
if (i==0) {
|
||||||
|
updateProgressBar(file.fptr, file.fsize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count < 256) {
|
||||||
|
f_close(&file);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool sportUpdateEnd()
|
||||||
|
{
|
||||||
|
uint8_t packet[8];
|
||||||
|
if (!sportWaitState(SPORT_DATA_REQ, 2000))
|
||||||
|
return false;
|
||||||
|
sportClearPacket(packet);
|
||||||
|
packet[0] = 0x50 ;
|
||||||
|
packet[1] = PRIM_DATA_EOF;
|
||||||
|
sportWritePacket(packet);
|
||||||
|
return sportWaitState(SPORT_COMPLETE, 2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sportFlashDevice(ModuleIndex module, const char * filename)
|
||||||
|
{
|
||||||
|
pausePulses();
|
||||||
|
|
||||||
|
lcdClear();
|
||||||
|
drawProgressBar(STR_WRITING);
|
||||||
|
|
||||||
|
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||||
|
uint8_t intPwr = IS_INTERNAL_MODULE_ON();
|
||||||
|
uint8_t extPwr = IS_EXTERNAL_MODULE_ON();
|
||||||
|
INTERNAL_MODULE_OFF();
|
||||||
|
EXTERNAL_MODULE_OFF();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool result = sportUpdatePowerOn(module);
|
||||||
|
if (result)
|
||||||
|
result = sportUpdateReqVersion();
|
||||||
|
if (result)
|
||||||
|
result = sportUpdateUploadFile(filename);
|
||||||
|
if (result)
|
||||||
|
result = sportUpdateEnd();
|
||||||
|
|
||||||
|
if (result == false) {
|
||||||
|
POPUP_WARNING("Firmware Update Error");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||||
|
INTERNAL_MODULE_OFF();
|
||||||
|
EXTERNAL_MODULE_OFF();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sportWaitState(SPORT_IDLE, 500); // Clear the fifo
|
||||||
|
|
||||||
|
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||||
|
if (intPwr)
|
||||||
|
INTERNAL_MODULE_ON();
|
||||||
|
if (extPwr)
|
||||||
|
EXTERNAL_MODULE_ON();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sportUpdateState = SPORT_IDLE;
|
||||||
|
|
||||||
|
resumePulses();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void sportProcessPacket(uint8_t * packet)
|
||||||
|
{
|
||||||
|
#if defined(STM32)
|
||||||
|
if (sportUpdateState != SPORT_IDLE) {
|
||||||
|
sportProcessUpdatePacket(packet); // Uses different chksum
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
sportProcessTelemetryPacket(packet);
|
||||||
|
}
|
49
radio/src/io/io_arm.h
Normal file
49
radio/src/io/io_arm.h
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) OpenTX
|
||||||
|
*
|
||||||
|
* Based on code named
|
||||||
|
* th9x - http://code.google.com/p/th9x
|
||||||
|
* er9x - http://code.google.com/p/er9x
|
||||||
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||||
|
*
|
||||||
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _IO_ARM_H_
|
||||||
|
#define _IO_ARM_H_
|
||||||
|
|
||||||
|
#include "dataconstants.h"
|
||||||
|
|
||||||
|
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||||
|
PACK(union SportTelemetryPacket
|
||||||
|
{
|
||||||
|
struct {
|
||||||
|
uint8_t physicalId;
|
||||||
|
uint8_t primId;
|
||||||
|
uint16_t dataId;
|
||||||
|
uint32_t value;
|
||||||
|
};
|
||||||
|
uint8_t raw[8];
|
||||||
|
});
|
||||||
|
|
||||||
|
void sportProcessPacket(uint8_t * packet);
|
||||||
|
bool isSportOutputBufferAvailable();
|
||||||
|
void sportOutputPushPacket(SportTelemetryPacket * packet);
|
||||||
|
void sportFlashDevice(ModuleIndex module, const char * filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(STM32)
|
||||||
|
bool isBootloader(const char * filename);
|
||||||
|
void bootloaderFlash(const char * filename);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _IO_ARM_H_
|
|
@ -339,7 +339,7 @@ static int luaSportTelemetryPush(lua_State * L)
|
||||||
packet.primId = luaL_checkunsigned(L, 2);
|
packet.primId = luaL_checkunsigned(L, 2);
|
||||||
packet.dataId = luaL_checkunsigned(L, 3);
|
packet.dataId = luaL_checkunsigned(L, 3);
|
||||||
packet.value = luaL_checkunsigned(L, 4);
|
packet.value = luaL_checkunsigned(L, 4);
|
||||||
sportOutputPushPacket(packet);
|
sportOutputPushPacket(&packet);
|
||||||
lua_pushboolean(L, true);
|
lua_pushboolean(L, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -342,6 +342,7 @@ void memswap(void * a, void * b, uint8_t size);
|
||||||
|
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
#include "fifo.h"
|
#include "fifo.h"
|
||||||
|
#include "io/io_arm.h"
|
||||||
// This doesn't need protection on this processor
|
// This doesn't need protection on this processor
|
||||||
typedef uint32_t tmr10ms_t;
|
typedef uint32_t tmr10ms_t;
|
||||||
extern volatile tmr10ms_t g_tmr10ms;
|
extern volatile tmr10ms_t g_tmr10ms;
|
||||||
|
|
|
@ -84,6 +84,7 @@ set(SRC
|
||||||
main_arm.cpp
|
main_arm.cpp
|
||||||
tasks_arm.cpp
|
tasks_arm.cpp
|
||||||
audio_arm.cpp
|
audio_arm.cpp
|
||||||
|
io/frsky_sport.cpp
|
||||||
telemetry/telemetry.cpp
|
telemetry/telemetry.cpp
|
||||||
telemetry/telemetry_holders.cpp
|
telemetry/telemetry_holders.cpp
|
||||||
telemetry/telemetry_sensors.cpp
|
telemetry/telemetry_sensors.cpp
|
||||||
|
|
|
@ -87,6 +87,7 @@ set(SRC
|
||||||
${SRC}
|
${SRC}
|
||||||
sbus.cpp
|
sbus.cpp
|
||||||
telemetry/crossfire.cpp
|
telemetry/crossfire.cpp
|
||||||
|
io/bootloader_flash.cpp
|
||||||
)
|
)
|
||||||
set(PULSES_SRC
|
set(PULSES_SRC
|
||||||
${PULSES_SRC}
|
${PULSES_SRC}
|
||||||
|
|
|
@ -759,7 +759,7 @@ int32_t fat12Write(const uint8_t * buffer, uint16_t sector, uint16_t count)
|
||||||
operation = FATWRITE_FIRMWARE;
|
operation = FATWRITE_FIRMWARE;
|
||||||
}
|
}
|
||||||
if (operation == FATWRITE_FIRMWARE) {
|
if (operation == FATWRITE_FIRMWARE) {
|
||||||
writeFlash((uint32_t *)address, (uint32_t *)buffer);
|
flashWrite((uint32_t *)address, (uint32_t *)buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
address += FLASH_PAGESIZE;
|
address += FLASH_PAGESIZE;
|
||||||
|
|
|
@ -145,9 +145,9 @@ DRESULT __disk_write(BYTE drv, const BYTE * buff, DWORD sector, UINT count);
|
||||||
#define FLASH_PAGESIZE 256
|
#define FLASH_PAGESIZE 256
|
||||||
void unlockFlash(void);
|
void unlockFlash(void);
|
||||||
void lockFlash(void);
|
void lockFlash(void);
|
||||||
void writeFlash(uint32_t * address, uint32_t * buffer);
|
void flashWrite(uint32_t * address, uint32_t * buffer);
|
||||||
uint32_t isFirmwareStart(const void * buffer);
|
uint32_t isFirmwareStart(const uint8_t * buffer);
|
||||||
uint32_t isBootloaderStart(const void * buffer);
|
uint32_t isBootloaderStart(const uint8_t * buffer);
|
||||||
|
|
||||||
// SDRAM driver
|
// SDRAM driver
|
||||||
void SDRAM_Init(void);
|
void SDRAM_Init(void);
|
||||||
|
|
|
@ -182,7 +182,7 @@ const char * OpenTxSimulator::getError()
|
||||||
void OpenTxSimulator::sendTelemetry(uint8_t * data, unsigned int len)
|
void OpenTxSimulator::sendTelemetry(uint8_t * data, unsigned int len)
|
||||||
{
|
{
|
||||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||||
processSportPacket(data);
|
sportProcessTelemetryPacket(data);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1233,8 +1233,8 @@ FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG) { return SET; }
|
||||||
ErrorStatus RTC_WaitForSynchro(void) { return SUCCESS; }
|
ErrorStatus RTC_WaitForSynchro(void) { return SUCCESS; }
|
||||||
void unlockFlash() { }
|
void unlockFlash() { }
|
||||||
void lockFlash() { }
|
void lockFlash() { }
|
||||||
void writeFlash(uint32_t *address, uint32_t *buffer) { SIMU_SLEEP(100); }
|
void flashWrite(uint32_t *address, uint32_t *buffer) { SIMU_SLEEP(100); }
|
||||||
uint32_t isBootloaderStart(const void *block) { return 1; }
|
uint32_t isBootloaderStart(const uint8_t * block) { return 1; }
|
||||||
#endif // defined(PCBTARANIS)
|
#endif // defined(PCBTARANIS)
|
||||||
|
|
||||||
#if defined(PCBFLAMENCO)
|
#if defined(PCBFLAMENCO)
|
||||||
|
|
|
@ -234,7 +234,7 @@ void init_trainer_capture();
|
||||||
|
|
||||||
// Write Flash driver
|
// Write Flash driver
|
||||||
#define FLASH_PAGESIZE 256
|
#define FLASH_PAGESIZE 256
|
||||||
void writeFlash(uint32_t * address, uint32_t * buffer);
|
void flashWrite(uint32_t * address, uint32_t * buffer);
|
||||||
|
|
||||||
// Keys driver
|
// Keys driver
|
||||||
uint8_t keyState(uint8_t index);
|
uint8_t keyState(uint8_t index);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
uint32_t (*IAP_Function)(uint32_t, uint32_t);
|
uint32_t (*IAP_Function)(uint32_t, uint32_t);
|
||||||
|
|
||||||
void writeFlash(uint32_t *address, uint32_t *buffer) // size is 256 bytes
|
void flashWrite(uint32_t *address, uint32_t *buffer) // size is 256 bytes
|
||||||
{
|
{
|
||||||
uint32_t FlashSectorNum;
|
uint32_t FlashSectorNum;
|
||||||
uint32_t flash_cmd = 0;
|
uint32_t flash_cmd = 0;
|
||||||
|
@ -76,7 +76,7 @@ void clearLockBits()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t isFirmwareStart(const void * buffer)
|
uint32_t isFirmwareStart(const uint8_t * buffer)
|
||||||
{
|
{
|
||||||
const uint32_t * block = (const uint32_t *)buffer;
|
const uint32_t * block = (const uint32_t *)buffer;
|
||||||
|
|
||||||
|
|
|
@ -155,9 +155,9 @@ uint32_t sdMounted(void);
|
||||||
#define FLASH_PAGESIZE 256
|
#define FLASH_PAGESIZE 256
|
||||||
void unlockFlash(void);
|
void unlockFlash(void);
|
||||||
void lockFlash(void);
|
void lockFlash(void);
|
||||||
void writeFlash(uint32_t * address, uint32_t * buffer);
|
void flashWrite(uint32_t * address, uint32_t * buffer);
|
||||||
uint32_t isFirmwareStart(const void * buffer);
|
uint32_t isFirmwareStart(const uint8_t * buffer);
|
||||||
uint32_t isBootloaderStart(const void * buffer);
|
uint32_t isBootloaderStart(const uint8_t * buffer);
|
||||||
|
|
||||||
// Pulses driver
|
// Pulses driver
|
||||||
#define INTERNAL_MODULE_ON() GPIO_SetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN)
|
#define INTERNAL_MODULE_ON() GPIO_SetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN)
|
||||||
|
|
|
@ -64,8 +64,6 @@ enum MemoryTypes {
|
||||||
MEM_EEPROM
|
MEM_EEPROM
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BLOCK_LEN 4096
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------
|
/*----------------------------------------------------------------------------
|
||||||
* Local variables
|
* Local variables
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
|
@ -89,7 +87,8 @@ TCHAR Filenames[20][50];
|
||||||
uint32_t FileSize[20];
|
uint32_t FileSize[20];
|
||||||
uint32_t Valid;
|
uint32_t Valid;
|
||||||
|
|
||||||
uint32_t Block_buffer[1024];
|
#define BLOCK_LEN 4096
|
||||||
|
uint8_t Block_buffer[BLOCK_LEN];
|
||||||
UINT BlockCount;
|
UINT BlockCount;
|
||||||
|
|
||||||
uint32_t memoryType;
|
uint32_t memoryType;
|
||||||
|
@ -229,7 +228,7 @@ FRESULT openBinaryFile(uint32_t index)
|
||||||
return fr;
|
return fr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fr = f_read(&FlashFile, (BYTE *)Block_buffer, BLOCK_LEN, &BlockCount);
|
fr = f_read(&FlashFile, Block_buffer, BLOCK_LEN, &BlockCount);
|
||||||
|
|
||||||
if (BlockCount == BLOCK_LEN)
|
if (BlockCount == BLOCK_LEN)
|
||||||
return fr;
|
return fr;
|
||||||
|
@ -237,7 +236,7 @@ FRESULT openBinaryFile(uint32_t index)
|
||||||
return FR_INVALID_OBJECT;
|
return FR_INVALID_OBJECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t isValidBufferStart(const void * buffer)
|
uint32_t isValidBufferStart(const uint8_t * buffer)
|
||||||
{
|
{
|
||||||
if (memoryType == MEM_FLASH)
|
if (memoryType == MEM_FLASH)
|
||||||
return isFirmwareStart(buffer);
|
return isFirmwareStart(buffer);
|
||||||
|
@ -295,12 +294,12 @@ extern Key keys[];
|
||||||
|
|
||||||
static uint32_t PowerUpDelay;
|
static uint32_t PowerUpDelay;
|
||||||
|
|
||||||
void writeFlashBlock()
|
void flashWriteBlock()
|
||||||
{
|
{
|
||||||
uint32_t blockOffset = 0;
|
uint32_t blockOffset = 0;
|
||||||
while (BlockCount) {
|
while (BlockCount) {
|
||||||
writeFlash((uint32_t *)firmwareAddress, &Block_buffer[blockOffset]);
|
flashWrite((uint32_t *)firmwareAddress, (uint32_t *)&Block_buffer[blockOffset]);
|
||||||
blockOffset += FLASH_PAGESIZE/4; // 32-bit words
|
blockOffset += FLASH_PAGESIZE;
|
||||||
firmwareAddress += FLASH_PAGESIZE;
|
firmwareAddress += FLASH_PAGESIZE;
|
||||||
if (BlockCount > FLASH_PAGESIZE) {
|
if (BlockCount > FLASH_PAGESIZE) {
|
||||||
BlockCount -= FLASH_PAGESIZE;
|
BlockCount -= FLASH_PAGESIZE;
|
||||||
|
@ -313,7 +312,7 @@ void writeFlashBlock()
|
||||||
|
|
||||||
void writeEepromBlock()
|
void writeEepromBlock()
|
||||||
{
|
{
|
||||||
eepromWriteBlock((uint8_t *)Block_buffer, eepromAddress, BlockCount);
|
eepromWriteBlock(Block_buffer, eepromAddress, BlockCount);
|
||||||
eepromAddress += BlockCount;
|
eepromAddress += BlockCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +550,7 @@ int main()
|
||||||
|
|
||||||
int progress;
|
int progress;
|
||||||
if (memoryType == MEM_FLASH) {
|
if (memoryType == MEM_FLASH) {
|
||||||
writeFlashBlock();
|
flashWriteBlock();
|
||||||
firmwareWritten += sizeof(Block_buffer);
|
firmwareWritten += sizeof(Block_buffer);
|
||||||
progress = (200*firmwareWritten) / FirmwareSize;
|
progress = (200*firmwareWritten) / FirmwareSize;
|
||||||
}
|
}
|
||||||
|
@ -566,7 +565,7 @@ int main()
|
||||||
lcdDrawSolidHorizontalLine(5, 6*FH+7, progress, FORCE);
|
lcdDrawSolidHorizontalLine(5, 6*FH+7, progress, FORCE);
|
||||||
lcdDrawSolidHorizontalLine(5, 6*FH+8, progress, FORCE);
|
lcdDrawSolidHorizontalLine(5, 6*FH+8, progress, FORCE);
|
||||||
|
|
||||||
fr = f_read(&FlashFile, (BYTE *)Block_buffer, sizeof(Block_buffer), &BlockCount);
|
fr = f_read(&FlashFile, Block_buffer, sizeof(Block_buffer), &BlockCount);
|
||||||
if (BlockCount == 0) {
|
if (BlockCount == 0) {
|
||||||
state = ST_FLASH_DONE; // EOF
|
state = ST_FLASH_DONE; // EOF
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ void eraseSector(uint32_t sector)
|
||||||
FLASH->CR &= SECTOR_MASK;
|
FLASH->CR &= SECTOR_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeFlash(uint32_t *address, uint32_t *buffer) // page size is 256 bytes
|
void flashWrite(uint32_t * address, uint32_t * buffer) // page size is 256 bytes
|
||||||
{
|
{
|
||||||
if ((uint32_t) address == 0x08000000) {
|
if ((uint32_t) address == 0x08000000) {
|
||||||
eraseSector(0);
|
eraseSector(0);
|
||||||
|
@ -123,7 +123,7 @@ void writeFlash(uint32_t *address, uint32_t *buffer) // page size is 256 bytes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t isFirmwareStart(const void * buffer)
|
uint32_t isFirmwareStart(const uint8_t * buffer)
|
||||||
{
|
{
|
||||||
const uint32_t * block = (const uint32_t *)buffer;
|
const uint32_t * block = (const uint32_t *)buffer;
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ uint32_t isFirmwareStart(const void * buffer)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t isBootloaderStart(const void * buffer)
|
uint32_t isBootloaderStart(const uint8_t * buffer)
|
||||||
{
|
{
|
||||||
const uint32_t * block = (const uint32_t *)buffer;
|
const uint32_t * block = (const uint32_t *)buffer;
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,7 @@ NOINLINE void processFrskyTelemetryData(uint8_t data)
|
||||||
|
|
||||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||||
if (IS_FRSKY_SPORT_PROTOCOL() && telemetryRxBufferCount >= FRSKY_SPORT_PACKET_SIZE) {
|
if (IS_FRSKY_SPORT_PROTOCOL() && telemetryRxBufferCount >= FRSKY_SPORT_PACKET_SIZE) {
|
||||||
processSportPacket(telemetryRxBuffer);
|
sportProcessPacket(telemetryRxBuffer);
|
||||||
dataState = STATE_DATA_IDLE;
|
dataState = STATE_DATA_IDLE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -414,17 +414,14 @@ typedef enum {
|
||||||
} TS_STATE;
|
} TS_STATE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// FrSky D Protocol
|
// FrSky D Telemetry Protocol
|
||||||
void processHubPacket(uint8_t id, int16_t value);
|
void processHubPacket(uint8_t id, int16_t value);
|
||||||
void frskyDSendNextAlarm();
|
void frskyDSendNextAlarm();
|
||||||
void frskyDProcessPacket(uint8_t *packet);
|
void frskyDProcessPacket(uint8_t *packet);
|
||||||
|
|
||||||
// FrSky S.PORT Protocol
|
// FrSky S.PORT Telemetry Protocol
|
||||||
void processSportPacket(uint8_t * packet);
|
void sportProcessTelemetryPacket(uint8_t * packet);
|
||||||
|
|
||||||
#if defined(PCBTARANIS)
|
|
||||||
void sportFirmwareUpdate(ModuleIndex module, const char * filename);
|
|
||||||
#endif
|
|
||||||
void telemetryWakeup();
|
void telemetryWakeup();
|
||||||
void telemetryReset();
|
void telemetryReset();
|
||||||
|
|
||||||
|
@ -486,18 +483,4 @@ void frskyUpdateCells();
|
||||||
|
|
||||||
void processFrskyTelemetryData(uint8_t data);
|
void processFrskyTelemetryData(uint8_t data);
|
||||||
|
|
||||||
PACK(union SportTelemetryPacket
|
|
||||||
{
|
|
||||||
struct {
|
|
||||||
uint8_t physicalId;
|
|
||||||
uint8_t primId;
|
|
||||||
uint16_t dataId;
|
|
||||||
uint32_t value;
|
|
||||||
};
|
|
||||||
uint8_t raw[8];
|
|
||||||
});
|
|
||||||
|
|
||||||
bool isSportOutputBufferAvailable();
|
|
||||||
void sportOutputPushPacket(SportTelemetryPacket & packet);
|
|
||||||
|
|
||||||
#endif // _FRSKY_H_
|
#endif // _FRSKY_H_
|
||||||
|
|
|
@ -20,18 +20,6 @@
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
|
|
||||||
#define PRIM_REQ_POWERUP (0)
|
|
||||||
#define PRIM_REQ_VERSION (1)
|
|
||||||
#define PRIM_CMD_DOWNLOAD (3)
|
|
||||||
#define PRIM_DATA_WORD (4)
|
|
||||||
#define PRIM_DATA_EOF (5)
|
|
||||||
|
|
||||||
#define PRIM_ACK_POWERUP (0x80)
|
|
||||||
#define PRIM_ACK_VERSION (0x81)
|
|
||||||
#define PRIM_REQ_DATA_ADDR (0x82)
|
|
||||||
#define PRIM_END_DOWNLOAD (0x83)
|
|
||||||
#define PRIM_DATA_CRC_ERR (0x84)
|
|
||||||
|
|
||||||
struct FrSkySportSensor {
|
struct FrSkySportSensor {
|
||||||
const uint16_t firstId;
|
const uint16_t firstId;
|
||||||
const uint16_t lastId;
|
const uint16_t lastId;
|
||||||
|
@ -107,64 +95,10 @@ bool checkSportPacket(uint8_t *packet)
|
||||||
#define SPORT_DATA_U32(packet) (*((uint32_t *)(packet+4)))
|
#define SPORT_DATA_U32(packet) (*((uint32_t *)(packet+4)))
|
||||||
#define HUB_DATA_U16(packet) (*((uint16_t *)(packet+4)))
|
#define HUB_DATA_U16(packet) (*((uint16_t *)(packet+4)))
|
||||||
|
|
||||||
enum SportUpdateState {
|
|
||||||
SPORT_IDLE,
|
|
||||||
SPORT_POWERUP_REQ,
|
|
||||||
SPORT_POWERUP_ACK,
|
|
||||||
SPORT_VERSION_REQ,
|
|
||||||
SPORT_VERSION_ACK,
|
|
||||||
SPORT_DATA_TRANSFER,
|
|
||||||
SPORT_DATA_REQ,
|
|
||||||
SPORT_COMPLETE,
|
|
||||||
SPORT_FAIL
|
|
||||||
};
|
|
||||||
|
|
||||||
uint8_t sportUpdateState = SPORT_IDLE;
|
|
||||||
uint32_t sportUpdateAddr = 0;
|
|
||||||
bool intPwr, extPwr;
|
|
||||||
uint16_t servosState;
|
uint16_t servosState;
|
||||||
uint16_t rboxState;
|
uint16_t rboxState;
|
||||||
|
|
||||||
void processSportUpdatePacket(uint8_t * packet)
|
void sportProcessTelemetryPacket(uint16_t id, uint8_t subId, uint8_t instance, uint32_t data, TelemetryUnit unit=UNIT_RAW)
|
||||||
{
|
|
||||||
if (packet[0]==0x5E && packet[1]==0x50) {
|
|
||||||
switch (packet[2]) {
|
|
||||||
case PRIM_ACK_POWERUP :
|
|
||||||
if (sportUpdateState == SPORT_POWERUP_REQ) {
|
|
||||||
sportUpdateState = SPORT_POWERUP_ACK;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PRIM_ACK_VERSION:
|
|
||||||
if (sportUpdateState == SPORT_VERSION_REQ) {
|
|
||||||
sportUpdateState = SPORT_VERSION_ACK;
|
|
||||||
// SportVersion[0] = packet[3] ;
|
|
||||||
// SportVersion[1] = packet[4] ;
|
|
||||||
// SportVersion[2] = packet[5] ;
|
|
||||||
// SportVersion[3] = packet[6] ;
|
|
||||||
// SportVerValid = 1 ;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PRIM_REQ_DATA_ADDR :
|
|
||||||
if (sportUpdateState == SPORT_DATA_TRANSFER) {
|
|
||||||
sportUpdateAddr = *((uint32_t *)(&packet[3]));
|
|
||||||
sportUpdateState = SPORT_DATA_REQ;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PRIM_END_DOWNLOAD :
|
|
||||||
sportUpdateState = SPORT_COMPLETE ;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PRIM_DATA_CRC_ERR :
|
|
||||||
sportUpdateState = SPORT_FAIL ;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void processSportPacket(uint16_t id, uint8_t subId, uint8_t instance, uint32_t data, TelemetryUnit unit=UNIT_RAW)
|
|
||||||
{
|
{
|
||||||
const FrSkySportSensor * sensor = getFrSkySportSensor(id, subId);
|
const FrSkySportSensor * sensor = getFrSkySportSensor(id, subId);
|
||||||
uint8_t precision = 0;
|
uint8_t precision = 0;
|
||||||
|
@ -188,55 +122,15 @@ void processSportPacket(uint16_t id, uint8_t subId, uint8_t instance, uint32_t d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sportOutputPushByte(uint8_t byte)
|
void sportProcessTelemetryPacket(uint8_t * packet)
|
||||||
{
|
|
||||||
if (byte == 0x7E || byte == 0x7D) {
|
|
||||||
telemetryOutputPushByte(0x7D);
|
|
||||||
telemetryOutputPushByte(0x20 ^ byte);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
telemetryOutputPushByte(byte);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSportOutputBufferAvailable()
|
|
||||||
{
|
|
||||||
return (outputTelemetryBufferSize == 0 && outputTelemetryBufferTrigger == 0x7E);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO merge it with S.PORT update function when finished
|
|
||||||
void sportOutputPushPacket(SportTelemetryPacket & packet)
|
|
||||||
{
|
|
||||||
uint16_t crc = 0;
|
|
||||||
|
|
||||||
for (uint8_t i=1; i<sizeof(packet); i++) {
|
|
||||||
uint8_t byte = packet.raw[i];
|
|
||||||
sportOutputPushByte(byte);
|
|
||||||
crc += byte; // 0-1FF
|
|
||||||
crc += crc >> 8; // 0-100
|
|
||||||
crc &= 0x00ff;
|
|
||||||
}
|
|
||||||
|
|
||||||
telemetryOutputPushByte(0xFF-crc);
|
|
||||||
telemetryOutputSetTrigger(packet.raw[0]); // physicalId
|
|
||||||
}
|
|
||||||
|
|
||||||
void processSportPacket(uint8_t * packet)
|
|
||||||
{
|
{
|
||||||
uint8_t physicalId = packet[0] & 0x1F;
|
uint8_t physicalId = packet[0] & 0x1F;
|
||||||
uint8_t primId = packet[1];
|
uint8_t primId = packet[1];
|
||||||
uint16_t id = *((uint16_t *)(packet+2));
|
uint16_t id = *((uint16_t *)(packet+2));
|
||||||
uint32_t data = SPORT_DATA_S32(packet);
|
uint32_t data = SPORT_DATA_S32(packet);
|
||||||
|
|
||||||
#if defined(STM32) && !defined(SIMU)
|
|
||||||
if (sportUpdateState != SPORT_IDLE) {
|
|
||||||
processSportUpdatePacket(packet); // Uses different chksum
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!checkSportPacket(packet)) {
|
if (!checkSportPacket(packet)) {
|
||||||
TRACE("processSportPacket(): checksum error ");
|
TRACE("sportProcessTelemetryPacket(): checksum error ");
|
||||||
DUMP(packet, FRSKY_SPORT_PACKET_SIZE);
|
DUMP(packet, FRSKY_SPORT_PACKET_SIZE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -279,17 +173,17 @@ void processSportPacket(uint8_t * packet)
|
||||||
value = -value;
|
value = -value;
|
||||||
value = (value * 5) / 3; // min/10000 => deg/1000000
|
value = (value * 5) / 3; // min/10000 => deg/1000000
|
||||||
if (data & (1 << 31))
|
if (data & (1 << 31))
|
||||||
processSportPacket(id, 0, instance, value, UNIT_GPS_LATITUDE);
|
sportProcessTelemetryPacket(id, 0, instance, value, UNIT_GPS_LATITUDE);
|
||||||
else
|
else
|
||||||
processSportPacket(id, 0, instance, value, UNIT_GPS_LONGITUDE);
|
sportProcessTelemetryPacket(id, 0, instance, value, UNIT_GPS_LONGITUDE);
|
||||||
}
|
}
|
||||||
else if (id >= RBOX_BATT1_FIRST_ID && id <= RBOX_BATT2_LAST_ID) {
|
else if (id >= RBOX_BATT1_FIRST_ID && id <= RBOX_BATT2_LAST_ID) {
|
||||||
processSportPacket(id, 0, instance, data & 0xffff);
|
sportProcessTelemetryPacket(id, 0, instance, data & 0xffff);
|
||||||
processSportPacket(id, 1, instance, data >> 16);
|
sportProcessTelemetryPacket(id, 1, instance, data >> 16);
|
||||||
}
|
}
|
||||||
else if (id >= RBOX_CNSP_FIRST_ID && id <= RBOX_CNSP_LAST_ID) {
|
else if (id >= RBOX_CNSP_FIRST_ID && id <= RBOX_CNSP_LAST_ID) {
|
||||||
processSportPacket(id, 0, instance, data & 0xffff);
|
sportProcessTelemetryPacket(id, 0, instance, data & 0xffff);
|
||||||
processSportPacket(id, 1, instance, data >> 16);
|
sportProcessTelemetryPacket(id, 1, instance, data >> 16);
|
||||||
}
|
}
|
||||||
else if (id >= RBOX_STATE_FIRST_ID && id <= RBOX_STATE_LAST_ID) {
|
else if (id >= RBOX_STATE_FIRST_ID && id <= RBOX_STATE_LAST_ID) {
|
||||||
uint16_t newServosState = data & 0xffff;
|
uint16_t newServosState = data & 0xffff;
|
||||||
|
@ -302,8 +196,8 @@ void processSportPacket(uint8_t * packet)
|
||||||
}
|
}
|
||||||
servosState = newServosState;
|
servosState = newServosState;
|
||||||
rboxState = newRboxState;
|
rboxState = newRboxState;
|
||||||
processSportPacket(id, 0, instance, servosState);
|
sportProcessTelemetryPacket(id, 0, instance, servosState);
|
||||||
processSportPacket(id, 1, instance, rboxState);
|
sportProcessTelemetryPacket(id, 1, instance, rboxState);
|
||||||
}
|
}
|
||||||
else if (id >= DIY_FIRST_ID && id <= DIY_LAST_ID) {
|
else if (id >= DIY_FIRST_ID && id <= DIY_LAST_ID) {
|
||||||
#if defined(LUA)
|
#if defined(LUA)
|
||||||
|
@ -320,7 +214,7 @@ void processSportPacket(uint8_t * packet)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
processSportPacket(id, 0, instance, data);
|
sportProcessTelemetryPacket(id, 0, instance, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,201 +280,3 @@ void frskySportSetDefault(int index, uint16_t id, uint8_t subId, uint8_t instanc
|
||||||
|
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(STM32)
|
|
||||||
bool sportWaitState(SportUpdateState state, int timeout)
|
|
||||||
{
|
|
||||||
#if defined(SIMU)
|
|
||||||
SIMU_SLEEP_NORET(1);
|
|
||||||
return true;
|
|
||||||
#else
|
|
||||||
for (int i=timeout/2; i>=0; i--) {
|
|
||||||
uint8_t byte ;
|
|
||||||
while (telemetryGetByte(&byte)) {
|
|
||||||
processFrskyTelemetryData(byte);
|
|
||||||
}
|
|
||||||
if (sportUpdateState == state) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (sportUpdateState == SPORT_FAIL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
CoTickDelay(1);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void blankPacket(uint8_t * packet)
|
|
||||||
{
|
|
||||||
memset(packet+2, 0, 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO merge this function
|
|
||||||
void writePacket(uint8_t * packet)
|
|
||||||
{
|
|
||||||
uint8_t * ptr = outputTelemetryBuffer;
|
|
||||||
*ptr++ = 0x7E;
|
|
||||||
*ptr++ = 0xFF;
|
|
||||||
packet[7] = crc16(packet, 7);
|
|
||||||
for (int i=0; i<8; i++) {
|
|
||||||
if (packet[i] == 0x7E || packet[i] == 0x7D) {
|
|
||||||
*ptr++ = 0x7D;
|
|
||||||
*ptr++ = 0x20 ^ packet[i];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*ptr++ = packet[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sportSendBuffer(outputTelemetryBuffer, ptr-outputTelemetryBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sportUpdatePowerOn(ModuleIndex module)
|
|
||||||
{
|
|
||||||
uint8_t packet[8];
|
|
||||||
|
|
||||||
sportUpdateState = SPORT_POWERUP_REQ;
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
|
||||||
intPwr = IS_INTERNAL_MODULE_ON();
|
|
||||||
extPwr = IS_EXTERNAL_MODULE_ON();
|
|
||||||
INTERNAL_MODULE_OFF();
|
|
||||||
EXTERNAL_MODULE_OFF();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sportWaitState(SPORT_IDLE, 500);
|
|
||||||
|
|
||||||
telemetryPortInit(FRSKY_SPORT_BAUDRATE, TELEMETRY_SERIAL_8N1);
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
|
||||||
if (module == INTERNAL_MODULE)
|
|
||||||
INTERNAL_MODULE_ON();
|
|
||||||
else
|
|
||||||
EXTERNAL_MODULE_ON();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sportWaitState(SPORT_IDLE, 50);
|
|
||||||
|
|
||||||
for (int i=0; i<10; i++) {
|
|
||||||
// max 10 attempts
|
|
||||||
blankPacket(packet);
|
|
||||||
packet[0] = 0x50 ;
|
|
||||||
packet[1] = PRIM_REQ_POWERUP;
|
|
||||||
writePacket(packet);
|
|
||||||
if (sportWaitState(SPORT_POWERUP_ACK, 100))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sportUpdateReqVersion()
|
|
||||||
{
|
|
||||||
uint8_t packet[8];
|
|
||||||
sportWaitState(SPORT_IDLE, 20);
|
|
||||||
sportUpdateState = SPORT_VERSION_REQ;
|
|
||||||
for (int i=0; i<10; i++) {
|
|
||||||
// max 10 attempts
|
|
||||||
blankPacket(packet) ;
|
|
||||||
packet[0] = 0x50 ;
|
|
||||||
packet[1] = PRIM_REQ_VERSION ;
|
|
||||||
writePacket(packet);
|
|
||||||
if (sportWaitState(SPORT_VERSION_ACK, 200))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sportUpdateUploadFile(const char *filename)
|
|
||||||
{
|
|
||||||
FIL file;
|
|
||||||
uint32_t buffer[1024/4];
|
|
||||||
UINT count;
|
|
||||||
uint8_t packet[8];
|
|
||||||
|
|
||||||
if (f_open(&file, filename, FA_READ) != FR_OK) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
sportWaitState(SPORT_IDLE, 200);
|
|
||||||
sportUpdateState = SPORT_DATA_TRANSFER;
|
|
||||||
blankPacket(packet) ;
|
|
||||||
packet[0] = 0x50 ;
|
|
||||||
packet[1] = PRIM_CMD_DOWNLOAD ;
|
|
||||||
// Stop here for testing
|
|
||||||
writePacket(packet);
|
|
||||||
|
|
||||||
while(1) {
|
|
||||||
if (f_read(&file, buffer, 1024, &count) != FR_OK) {
|
|
||||||
f_close(&file);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
count >>= 2;
|
|
||||||
|
|
||||||
for (UINT i=0; i<count; i++) {
|
|
||||||
if (!sportWaitState(SPORT_DATA_REQ, 2000)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
packet[0] = 0x50 ;
|
|
||||||
packet[1] = PRIM_DATA_WORD ;
|
|
||||||
packet[6] = sportUpdateAddr & 0x000000FF;
|
|
||||||
uint32_t offset = ( sportUpdateAddr & 1023 ) >> 2; // 32 bit word offset into buffer
|
|
||||||
uint32_t *data = (uint32_t *)(&packet[2]);
|
|
||||||
*data = buffer[offset];
|
|
||||||
sportUpdateState = SPORT_DATA_TRANSFER,
|
|
||||||
writePacket(packet);
|
|
||||||
if (i==0) {
|
|
||||||
updateProgressBar(file.fptr, file.fsize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count < 256) {
|
|
||||||
f_close(&file);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool sportUpdateEnd()
|
|
||||||
{
|
|
||||||
uint8_t packet[8];
|
|
||||||
if (!sportWaitState(SPORT_DATA_REQ, 2000))
|
|
||||||
return false;
|
|
||||||
blankPacket(packet);
|
|
||||||
packet[0] = 0x50 ;
|
|
||||||
packet[1] = PRIM_DATA_EOF;
|
|
||||||
writePacket(packet);
|
|
||||||
return sportWaitState(SPORT_COMPLETE, 2000);
|
|
||||||
}
|
|
||||||
|
|
||||||
void sportFirmwareUpdate(ModuleIndex module, const char * filename)
|
|
||||||
{
|
|
||||||
bool result = sportUpdatePowerOn(module);
|
|
||||||
if (result)
|
|
||||||
result = sportUpdateReqVersion();
|
|
||||||
if (result)
|
|
||||||
result = sportUpdateUploadFile(filename);
|
|
||||||
if (result)
|
|
||||||
result = sportUpdateEnd();
|
|
||||||
|
|
||||||
if (result == false) {
|
|
||||||
POPUP_WARNING("Firmware Update Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
|
||||||
INTERNAL_MODULE_OFF();
|
|
||||||
EXTERNAL_MODULE_OFF();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sportWaitState(SPORT_IDLE, 1000);
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
|
||||||
if (intPwr)
|
|
||||||
INTERNAL_MODULE_ON();
|
|
||||||
if (extPwr)
|
|
||||||
EXTERNAL_MODULE_ON();
|
|
||||||
#endif
|
|
||||||
sportUpdateState = SPORT_IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ void frskyDProcessPacket(uint8_t *packet);
|
||||||
|
|
||||||
#if defined(TELEMETRY_FRSKY_SPORT)
|
#if defined(TELEMETRY_FRSKY_SPORT)
|
||||||
bool checkSportPacket(uint8_t *packet);
|
bool checkSportPacket(uint8_t *packet);
|
||||||
void processSportPacket(uint8_t * packet);
|
void sportProcessTelemetryPacket(uint8_t * packet);
|
||||||
bool checkSportPacket(uint8_t *packet);
|
bool checkSportPacket(uint8_t *packet);
|
||||||
void frskyCalculateCellStats(void);
|
void frskyCalculateCellStats(void);
|
||||||
void displayVoltagesScreen();
|
void displayVoltagesScreen();
|
||||||
|
@ -221,16 +221,16 @@ TEST(FrSkySPORT, FrSkyDCells)
|
||||||
TELEMETRY_RESET();
|
TELEMETRY_RESET();
|
||||||
uint8_t pkt1[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x07, 0xD0, 0x00, 0x00, 0x12 };
|
uint8_t pkt1[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x07, 0xD0, 0x00, 0x00, 0x12 };
|
||||||
EXPECT_EQ(checkSportPacket(pkt1+1), true);
|
EXPECT_EQ(checkSportPacket(pkt1+1), true);
|
||||||
processSportPacket(pkt1+1);
|
sportProcessTelemetryPacket(pkt1+1);
|
||||||
uint8_t pkt2[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x17, 0xD0, 0x00, 0x00, 0x02 };
|
uint8_t pkt2[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x17, 0xD0, 0x00, 0x00, 0x02 };
|
||||||
EXPECT_EQ(checkSportPacket(pkt2+1), true);
|
EXPECT_EQ(checkSportPacket(pkt2+1), true);
|
||||||
processSportPacket(pkt2+1);
|
sportProcessTelemetryPacket(pkt2+1);
|
||||||
uint8_t pkt3[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x27, 0xD0, 0x00, 0x00, 0xF1 };
|
uint8_t pkt3[] = { 0x7E, 0x98, 0x10, 0x06, 0x00, 0x27, 0xD0, 0x00, 0x00, 0xF1 };
|
||||||
EXPECT_EQ(checkSportPacket(pkt3+1), true);
|
EXPECT_EQ(checkSportPacket(pkt3+1), true);
|
||||||
processSportPacket(pkt3+1);
|
sportProcessTelemetryPacket(pkt3+1);
|
||||||
processSportPacket(pkt1+1);
|
sportProcessTelemetryPacket(pkt1+1);
|
||||||
processSportPacket(pkt2+1);
|
sportProcessTelemetryPacket(pkt2+1);
|
||||||
processSportPacket(pkt3+1);
|
sportProcessTelemetryPacket(pkt3+1);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 1200);
|
EXPECT_EQ(telemetryItems[0].value, 1200);
|
||||||
for (int i=0; i<3; i++) {
|
for (int i=0; i<3; i++) {
|
||||||
|
@ -247,12 +247,12 @@ TEST(FrSkySPORT, frskySetCellVoltage)
|
||||||
TELEMETRY_RESET();
|
TELEMETRY_RESET();
|
||||||
|
|
||||||
// test that simulates 3 cell battery
|
// test that simulates 3 cell battery
|
||||||
generateSportCellPacket(packet, 3, 0, _V(410), _V(420)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 0, _V(410), _V(420)); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(checkSportPacket(packet), true) << "Bad CRC generation in setSportPacketCrc()";
|
EXPECT_EQ(checkSportPacket(packet), true) << "Bad CRC generation in setSportPacketCrc()";
|
||||||
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
generateSportCellPacket(packet, 3, 0, _V(405), _V(300)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 0, _V(405), _V(300)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 405);
|
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 405);
|
||||||
|
@ -263,11 +263,11 @@ TEST(FrSkySPORT, frskySetCellVoltage)
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 1135);
|
EXPECT_EQ(telemetryItems[0].valueMin, 1135);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 1260);
|
EXPECT_EQ(telemetryItems[0].valueMax, 1260);
|
||||||
|
|
||||||
generateSportCellPacket(packet, 3, 0, _V(405), _V(250)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 0, _V(405), _V(250)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
generateSportCellPacket(packet, 3, 0, _V(410), _V(420)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 0, _V(410), _V(420)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 2, _V(430), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 410);
|
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 410);
|
||||||
|
@ -279,9 +279,9 @@ TEST(FrSkySPORT, frskySetCellVoltage)
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 1260);
|
EXPECT_EQ(telemetryItems[0].valueMax, 1260);
|
||||||
|
|
||||||
//add another two cells - 5 cell battery
|
//add another two cells - 5 cell battery
|
||||||
generateSportCellPacket(packet, 5, 0, _V(418), _V(408)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 0, _V(418), _V(408)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 5, 2, _V(415), _V(420)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 2, _V(415), _V(420)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 5);
|
EXPECT_EQ(telemetryItems[0].cells.count, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
||||||
|
@ -295,9 +295,9 @@ TEST(FrSkySPORT, frskySetCellVoltage)
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 2071);
|
EXPECT_EQ(telemetryItems[0].valueMax, 2071);
|
||||||
|
|
||||||
//simulate very low voltage for cell 3
|
//simulate very low voltage for cell 3
|
||||||
generateSportCellPacket(packet, 5, 0, _V(418), _V(408)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 0, _V(418), _V(408)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 5, 2, _V(100), _V(420)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 2, _V(100), _V(420)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 5);
|
EXPECT_EQ(telemetryItems[0].cells.count, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
||||||
|
@ -311,10 +311,10 @@ TEST(FrSkySPORT, frskySetCellVoltage)
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 2071);
|
EXPECT_EQ(telemetryItems[0].valueMax, 2071);
|
||||||
|
|
||||||
//back to normal (but with reversed order of packets)
|
//back to normal (but with reversed order of packets)
|
||||||
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 5, 0, _V(418), _V(408)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 0, _V(418), _V(408)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 5, 2, _V(412), _V(420)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 2, _V(412), _V(420)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 5, 4, _V(410), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 5);
|
EXPECT_EQ(telemetryItems[0].cells.count, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
||||||
|
@ -342,7 +342,7 @@ TEST(FrSkySPORT, StrangeCellsBug)
|
||||||
|
|
||||||
uint8_t pkt[] = { 0x7E, 0x48, 0x10, 0x00, 0x03, 0x30, 0x15, 0x50, 0x81, 0xD5 };
|
uint8_t pkt[] = { 0x7E, 0x48, 0x10, 0x00, 0x03, 0x30, 0x15, 0x50, 0x81, 0xD5 };
|
||||||
EXPECT_EQ(checkSportPacket(pkt+1), true);
|
EXPECT_EQ(checkSportPacket(pkt+1), true);
|
||||||
processSportPacket(pkt+1);
|
sportProcessTelemetryPacket(pkt+1);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 0); // now we ignore such low values
|
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 0); // now we ignore such low values
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[1].value, 413);
|
EXPECT_EQ(telemetryItems[0].cells.values[1].value, 413);
|
||||||
|
@ -356,8 +356,8 @@ TEST(FrSkySPORT, frskySetCellVoltageTwoSensors)
|
||||||
TELEMETRY_RESET();
|
TELEMETRY_RESET();
|
||||||
|
|
||||||
//sensor 1: 3 cell battery
|
//sensor 1: 3 cell battery
|
||||||
generateSportCellPacket(packet, 3, 0, _V(418), _V(416)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 0, _V(418), _V(416)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 3, 2, _V(415), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 2, _V(415), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
EXPECT_EQ(telemetryItems[0].cells.count, 3);
|
||||||
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
EXPECT_EQ(telemetryItems[0].cells.values[0].value, 418);
|
||||||
|
@ -369,8 +369,8 @@ TEST(FrSkySPORT, frskySetCellVoltageTwoSensors)
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 1249);
|
EXPECT_EQ(telemetryItems[0].valueMax, 1249);
|
||||||
|
|
||||||
//sensor 2: 4 cell battery
|
//sensor 2: 4 cell battery
|
||||||
generateSportCellPacket(packet, 4, 0, _V(410), _V(420), DATA_ID_FLVSS+1); processSportPacket(packet);
|
generateSportCellPacket(packet, 4, 0, _V(410), _V(420), DATA_ID_FLVSS+1); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 4, 2, _V(400), _V(405), DATA_ID_FLVSS+1); processSportPacket(packet);
|
generateSportCellPacket(packet, 4, 2, _V(400), _V(405), DATA_ID_FLVSS+1); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
EXPECT_EQ(telemetryItems[1].cells.count, 4);
|
EXPECT_EQ(telemetryItems[1].cells.count, 4);
|
||||||
EXPECT_EQ(telemetryItems[1].cells.values[0].value, 410);
|
EXPECT_EQ(telemetryItems[1].cells.values[0].value, 410);
|
||||||
|
@ -394,10 +394,10 @@ TEST(FrSkySPORT, frskySetCellVoltageTwoSensors)
|
||||||
EXPECT_EQ(telemetryItems[2].valueMax, 287);
|
EXPECT_EQ(telemetryItems[2].valueMax, 287);
|
||||||
|
|
||||||
//now change some voltages
|
//now change some voltages
|
||||||
generateSportCellPacket(packet, 3, 2, _V(415), _V( 0)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 2, _V(415), _V( 0)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 4, 2, _V(390), _V(370), DATA_ID_FLVSS+1); processSportPacket(packet);
|
generateSportCellPacket(packet, 4, 2, _V(390), _V(370), DATA_ID_FLVSS+1); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 3, 0, _V(420), _V(410)); processSportPacket(packet);
|
generateSportCellPacket(packet, 3, 0, _V(420), _V(410)); sportProcessTelemetryPacket(packet);
|
||||||
generateSportCellPacket(packet, 4, 0, _V(410), _V(420), DATA_ID_FLVSS+1); processSportPacket(packet);
|
generateSportCellPacket(packet, 4, 0, _V(410), _V(420), DATA_ID_FLVSS+1); sportProcessTelemetryPacket(packet);
|
||||||
|
|
||||||
telemetryWakeup();
|
telemetryWakeup();
|
||||||
|
|
||||||
|
@ -430,22 +430,22 @@ TEST(FrSkySPORT, frskyVfas)
|
||||||
TELEMETRY_RESET();
|
TELEMETRY_RESET();
|
||||||
|
|
||||||
// tests for Vfas
|
// tests for Vfas
|
||||||
generateSportFasVoltagePacket(packet, 5000); processSportPacket(packet);
|
generateSportFasVoltagePacket(packet, 5000); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 5000);
|
EXPECT_EQ(telemetryItems[0].value, 5000);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 5000);
|
EXPECT_EQ(telemetryItems[0].valueMin, 5000);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 5000);
|
EXPECT_EQ(telemetryItems[0].valueMax, 5000);
|
||||||
|
|
||||||
generateSportFasVoltagePacket(packet, 6524); processSportPacket(packet);
|
generateSportFasVoltagePacket(packet, 6524); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 6524);
|
EXPECT_EQ(telemetryItems[0].value, 6524);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 6524); // the batt was changed (val > old max)
|
EXPECT_EQ(telemetryItems[0].valueMin, 6524); // the batt was changed (val > old max)
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 6524);
|
EXPECT_EQ(telemetryItems[0].valueMax, 6524);
|
||||||
|
|
||||||
generateSportFasVoltagePacket(packet, 1248); processSportPacket(packet);
|
generateSportFasVoltagePacket(packet, 1248); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 1248);
|
EXPECT_EQ(telemetryItems[0].value, 1248);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 1248);
|
EXPECT_EQ(telemetryItems[0].valueMin, 1248);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 6524);
|
EXPECT_EQ(telemetryItems[0].valueMax, 6524);
|
||||||
|
|
||||||
generateSportFasVoltagePacket(packet, 2248); processSportPacket(packet);
|
generateSportFasVoltagePacket(packet, 2248); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 2248);
|
EXPECT_EQ(telemetryItems[0].value, 2248);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 1248);
|
EXPECT_EQ(telemetryItems[0].valueMin, 1248);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 6524);
|
EXPECT_EQ(telemetryItems[0].valueMax, 6524);
|
||||||
|
@ -468,30 +468,30 @@ TEST(FrSkySPORT, frskyCurrent)
|
||||||
TELEMETRY_RESET();
|
TELEMETRY_RESET();
|
||||||
|
|
||||||
// tests for Curr
|
// tests for Curr
|
||||||
generateSportFasCurrentPacket(packet, 0); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 0); sportProcessTelemetryPacket(packet);
|
||||||
g_model.telemetrySensors[0].custom.offset = -5; /* unit: 1/10 amps */
|
g_model.telemetrySensors[0].custom.offset = -5; /* unit: 1/10 amps */
|
||||||
generateSportFasCurrentPacket(packet, 0); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 0); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 0);
|
EXPECT_EQ(telemetryItems[0].value, 0);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 0);
|
EXPECT_EQ(telemetryItems[0].valueMax, 0);
|
||||||
|
|
||||||
// measured current less then offset - value should be zero
|
// measured current less then offset - value should be zero
|
||||||
generateSportFasCurrentPacket(packet, 4); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 4); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 0);
|
EXPECT_EQ(telemetryItems[0].value, 0);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 0);
|
EXPECT_EQ(telemetryItems[0].valueMax, 0);
|
||||||
|
|
||||||
generateSportFasCurrentPacket(packet, 10); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 10); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 5);
|
EXPECT_EQ(telemetryItems[0].value, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 5);
|
EXPECT_EQ(telemetryItems[0].valueMax, 5);
|
||||||
|
|
||||||
generateSportFasCurrentPacket(packet, 500); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 500); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 495);
|
EXPECT_EQ(telemetryItems[0].value, 495);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 495);
|
EXPECT_EQ(telemetryItems[0].valueMax, 495);
|
||||||
|
|
||||||
generateSportFasCurrentPacket(packet, 200); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 200); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 195);
|
EXPECT_EQ(telemetryItems[0].value, 195);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
EXPECT_EQ(telemetryItems[0].valueMin, 0);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 495);
|
EXPECT_EQ(telemetryItems[0].valueMax, 495);
|
||||||
|
@ -500,17 +500,17 @@ TEST(FrSkySPORT, frskyCurrent)
|
||||||
TELEMETRY_RESET();
|
TELEMETRY_RESET();
|
||||||
g_model.telemetrySensors[0].custom.offset = +5; /* unit: 1/10 amps */
|
g_model.telemetrySensors[0].custom.offset = +5; /* unit: 1/10 amps */
|
||||||
|
|
||||||
generateSportFasCurrentPacket(packet, 0); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 0); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 5);
|
EXPECT_EQ(telemetryItems[0].value, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 5);
|
EXPECT_EQ(telemetryItems[0].valueMin, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 5);
|
EXPECT_EQ(telemetryItems[0].valueMax, 5);
|
||||||
|
|
||||||
generateSportFasCurrentPacket(packet, 500); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 500); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 505);
|
EXPECT_EQ(telemetryItems[0].value, 505);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 5);
|
EXPECT_EQ(telemetryItems[0].valueMin, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 505);
|
EXPECT_EQ(telemetryItems[0].valueMax, 505);
|
||||||
|
|
||||||
generateSportFasCurrentPacket(packet, 200); processSportPacket(packet);
|
generateSportFasCurrentPacket(packet, 200); sportProcessTelemetryPacket(packet);
|
||||||
EXPECT_EQ(telemetryItems[0].value, 205);
|
EXPECT_EQ(telemetryItems[0].value, 205);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMin, 5);
|
EXPECT_EQ(telemetryItems[0].valueMin, 5);
|
||||||
EXPECT_EQ(telemetryItems[0].valueMax, 505);
|
EXPECT_EQ(telemetryItems[0].valueMax, 505);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue