From c034a35d2c32a1fe66a8b21f8ed97dbe8c5cfe66 Mon Sep 17 00:00:00 2001 From: zedamota Date: Wed, 15 Dec 2010 19:06:28 +0000 Subject: [PATCH] OP-21/Bootloader - Changes to the IAPObject. Implements MB and AHRS user mode IAPObject. Added user mode reset command to the CLI. To many changes to bootloading system to write here, a Wiki page will have to be writen. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2238 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/AHRS/Makefile | 3 +- flight/AHRS/ahrs.c | 54 +++++++- flight/Bootloaders/AHRS/Makefile | 1 + flight/Bootloaders/AHRS/main.c | 9 +- flight/Bootloaders/OpenPilot/Makefile | 2 +- flight/Bootloaders/OpenPilot/main.c | 20 ++- flight/Bootloaders/OpenPilot/op_dfu.c | 1 + .../Modules/FirmwareIAP/firmwareiap.c | 75 +++++++++-- .../OpenPilot/UAVObjects/inc/firmwareiapobj.h | 20 +-- flight/PiOS/Boards/STM32103CB_AHRS.h | 1 + flight/PiOS/Boards/STM3210E_OP.h | 1 + flight/PiOS/Common/pios_iap.c | 1 + .../src/experimental/USB_UPLOAD_TOOL/main.cpp | 12 +- .../experimental/USB_UPLOAD_TOOL/op_dfu.cpp | 61 +++++++-- .../src/experimental/USB_UPLOAD_TOOL/op_dfu.h | 2 +- .../src/plugins/uavobjects/firmwareiapobj.cpp | 122 +++++++++++++++-- .../src/plugins/uavobjects/firmwareiapobj.h | 20 +-- .../src/plugins/uavobjects/firmwareiapobj.py | 125 ++++++++++++++++-- .../uavobjectdefinition/firmwareiap.xml | 30 +++-- 19 files changed, 477 insertions(+), 83 deletions(-) diff --git a/flight/AHRS/Makefile b/flight/AHRS/Makefile index e9f5e6523..ced50818b 100644 --- a/flight/AHRS/Makefile +++ b/flight/AHRS/Makefile @@ -25,7 +25,7 @@ # Set developer code and compile options # Set to YES for debugging -DEBUG ?= NO +DEBUG ?= YES USE_BOOTLOADER ?= NO # Set to YES when using Code Sourcery toolchain @@ -121,6 +121,7 @@ SRC += $(PIOSSTM32F10X)/pios_exti.c SRC += $(PIOSCOMMON)/pios_com.c SRC += $(PIOSCOMMON)/pios_hmc5843.c SRC += $(PIOSCOMMON)/printf-stdarg.c +SRC += $(PIOSCOMMON)/pios_iap.c ## CMSIS for STM32 SRC += $(CMSISDIR)/core_cm3.c diff --git a/flight/AHRS/ahrs.c b/flight/AHRS/ahrs.c index 4ff83d09c..77469e178 100644 --- a/flight/AHRS/ahrs.c +++ b/flight/AHRS/ahrs.c @@ -76,7 +76,12 @@ void altitude_callback(AhrsObjHandle obj); void calibration_callback(AhrsObjHandle obj); void gps_callback(AhrsObjHandle obj); void settings_callback(AhrsObjHandle obj); + +/* Bootloader related functions and var*/ +static uint32_t iap_calc_crc(void); +static void read_description(uint8_t *); void firmwareiapobj_callback(AhrsObjHandle obj); +volatile uint8_t reset_count=0; /** * @addtogroup AHRS_Global_Data AHRS Global Data @@ -459,6 +464,8 @@ int main() /* Communication system */ PIOS_COM_Init(); + /* IAP System Setup */ + PIOS_IAP_Init(); /* ADC system */ AHRS_ADC_Config(adc_oversampling); AHRS_ADC_SetCallback(adc_callback); @@ -1014,11 +1021,52 @@ void homelocation_callback(AhrsObjHandle obj) void firmwareiapobj_callback(AhrsObjHandle obj) { FirmwareIAPObjData firmwareIAPObj; - FirmwareIAPObjGet(&firmwareIAPObj); - - // float time = timer_counter() / timer_rate(); + FirmwareIAPObjGet(&firmwareIAPObj); + if(firmwareIAPObj.ArmReset==0) + reset_count=0; + if(firmwareIAPObj.ArmReset==1) + { + + if((firmwareIAPObj.Target==FUNC_ID) || (firmwareIAPObj.Target==0xFF)) + { + + ++reset_count; + if(reset_count>2) + { + PIOS_IAP_SetRequest1(); + PIOS_IAP_SetRequest2(); + PIOS_SYS_Reset(); + } + } + } + else if(firmwareIAPObj.Target==FUNC_ID && firmwareIAPObj.crc!=iap_calc_crc()) + { + read_description(firmwareIAPObj.Description); + firmwareIAPObj.crc=iap_calc_crc(); + firmwareIAPObj.HWVersion=HW_VERSION; + FirmwareIAPObjSet(&firmwareIAPObj); + } } +static uint32_t iap_calc_crc(void) +{ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE); + CRC_ResetDR(); + CRC_CalcBlockCRC((uint32_t *) START_OF_USER_CODE, (SIZE_OF_CODE) >> 2); + return CRC_GetCRC(); +} +static uint8_t *FLASH_If_Read(uint32_t SectorAddress) +{ + return (uint8_t *) (SectorAddress); +} +static void read_description(uint8_t * array) +{ + uint8_t x = 0; + for (uint32_t i = START_OF_USER_CODE + SIZE_OF_CODE; i < START_OF_USER_CODE + SIZE_OF_CODE + SIZE_OF_DESCRIPTION; ++i) { + array[x] = *FLASH_If_Read(i); + ++x; + } +} /** diff --git a/flight/Bootloaders/AHRS/Makefile b/flight/Bootloaders/AHRS/Makefile index 3c1cc93a5..7a6ce8db1 100644 --- a/flight/Bootloaders/AHRS/Makefile +++ b/flight/Bootloaders/AHRS/Makefile @@ -108,6 +108,7 @@ SRC += $(PIOSSTM32F10X)/pios_spi.c SRC += $(PIOSCOMMON)/pios_opahrs_proto.c SRC += $(PIOSCOMMON)/printf-stdarg.c SRC += $(PIOSCOMMON)/pios_bl_helper.c +SRC += $(PIOSCOMMON)/pios_iap.c ## CMSIS for STM32 SRC += $(CMSISDIR)/core_cm3.c diff --git a/flight/Bootloaders/AHRS/main.c b/flight/Bootloaders/AHRS/main.c index 50faf5ee6..401c2762f 100644 --- a/flight/Bootloaders/AHRS/main.c +++ b/flight/Bootloaders/AHRS/main.c @@ -82,15 +82,22 @@ int main() { // PIOS_DELAY_WaitmS(1000); // } //GO_dfu = TRUE; - GO_dfu = GO_dfu;// OR with app boot request + PIOS_IAP_Init(); + GO_dfu = GO_dfu | PIOS_IAP_CheckRequest();// OR with app boot request if (GO_dfu == FALSE) { jump_to_app(); } + if(PIOS_IAP_CheckRequest()) + { + PIOS_DELAY_WaitmS(1000); + PIOS_IAP_ClearRequest(); + } /* SPI link to master */ PIOS_SPI_Init(); lfsm_init(); boot_status = idle; Fw_crc = crc_memory_calc(); + PIOS_LED_On(LED1); while (1) { process_spi_request(); } diff --git a/flight/Bootloaders/OpenPilot/Makefile b/flight/Bootloaders/OpenPilot/Makefile index 27c91cdce..d3a601b97 100644 --- a/flight/Bootloaders/OpenPilot/Makefile +++ b/flight/Bootloaders/OpenPilot/Makefile @@ -182,7 +182,7 @@ SRC += $(STMSPDSRCDIR)/stm32f10x_rtc.c SRC += $(STMSPDSRCDIR)/stm32f10x_spi.c SRC += $(STMSPDSRCDIR)/stm32f10x_tim.c SRC += $(STMSPDSRCDIR)/stm32f10x_usart.c -SRC += $(STMSPDSRCDIR)/stm32f10x_iwdg.c +#SRC += $(STMSPDSRCDIR)/stm32f10x_iwdg.c SRC += $(STMSPDSRCDIR)/stm32f10x_dbgmcu.c SRC += $(STMSPDSRCDIR)/misc.c diff --git a/flight/Bootloaders/OpenPilot/main.c b/flight/Bootloaders/OpenPilot/main.c index 9853ce828..bb7270613 100644 --- a/flight/Bootloaders/OpenPilot/main.c +++ b/flight/Bootloaders/OpenPilot/main.c @@ -109,11 +109,27 @@ int main() { USB_connected = TRUE; PIOS_IAP_Init(); - if (PIOS_IAP_CheckRequest() == TRUE) { + + if (PIOS_IAP_CheckRequest() == TRUE) { + PIOS_Board_Init(); + PIOS_DELAY_WaitmS(1000); User_DFU_request = TRUE; PIOS_IAP_ClearRequest(); - } + /* + else + { + PIOS_Board_Init(); + for(uint8_t x=0;x<10;++x) + { + PIOS_LED_Toggle(LED1); + PIOS_LED_Toggle(LED2); + PIOS_DELAY_WaitmS(1000); + } + PIOS_IAP_SetRequest1(); + PIOS_IAP_SetRequest2(); + PIOS_SYS_Reset(); + }*/ GO_dfu = (USB_connected == TRUE) || (User_DFU_request == TRUE); if (GO_dfu == TRUE) { diff --git a/flight/Bootloaders/OpenPilot/op_dfu.c b/flight/Bootloaders/OpenPilot/op_dfu.c index 725f1f6af..97fa59386 100644 --- a/flight/Bootloaders/OpenPilot/op_dfu.c +++ b/flight/Bootloaders/OpenPilot/op_dfu.c @@ -573,6 +573,7 @@ uint32_t CalcFirmCRC() { void sendData(uint8_t * buf,uint16_t size) { if (ProgPort == Usb) { + PIOS_COM_SendBuffer(PIOS_COM_TELEM_USB, buf, size);//FIX+1 } else if (ProgPort == Serial) { ssp_SendData(&ssp_port, buf, size); diff --git a/flight/OpenPilot/Modules/FirmwareIAP/firmwareiap.c b/flight/OpenPilot/Modules/FirmwareIAP/firmwareiap.c index 97ba2ed57..d9946d969 100644 --- a/flight/OpenPilot/Modules/FirmwareIAP/firmwareiap.c +++ b/flight/OpenPilot/Modules/FirmwareIAP/firmwareiap.c @@ -66,9 +66,24 @@ static void FirmwareIAPCallback(UAVObjEvent* ev); static uint32_t iap_calc_crc(void); +static void read_description(uint8_t *); + FirmwareIAPObjData data; static uint32_t get_time(void); + +// Private constants +#define STACK_SIZE configMINIMAL_STACK_SIZE +#define TASK_PRIORITY (tskIDLE_PRIORITY+1) + +// Private types + +// Private variables +static xTaskHandle taskHandle; + +// Private functions +static void resetTask(void *parameters); + /** * Initialise the module, called on startup. * \returns 0 on success or -1 if initialisation failed @@ -85,11 +100,11 @@ static uint32_t get_time(void); int32_t FirmwareIAPInitialize() { - data.Version[0] = version[0]; - data.Version[1] = version[1]; - data.Version[2] = version[2]; - data.SVN = SVN; - data.crc = iap_calc_crc(); + data.Target=FUNC_ID; + read_description(data.Description); + data.HWVersion=HW_VERSION; + data.ArmReset=0; + data.crc = 0; FirmwareIAPObjSet( &data ); FirmwareIAPObjConnectCallback( &FirmwareIAPCallback ); return 0; @@ -113,10 +128,21 @@ static void FirmwareIAPCallback(UAVObjEvent* ev) if ( ev->obj == FirmwareIAPObjHandle() ) { // Get the input object data FirmwareIAPObjGet(&data); - this_time = get_time(); + this_time = get_time(); delta = this_time - last_time; last_time = this_time; - + if((data.Target==FUNC_ID)&&(data.crc != iap_calc_crc())) + { + read_description(data.Description); + data.HWVersion=HW_VERSION; + data.crc = iap_calc_crc(); + FirmwareIAPObjSet( &data ); + } + if((data.ArmReset==1)&&(taskHandle==0)) + { + data.ArmReset=0; + FirmwareIAPObjSet( &data ); + } switch(iap_state) { case IAP_STATE_READY: if( data.Command == IAP_CMD_STEP_1 ) { @@ -140,8 +166,7 @@ static void FirmwareIAPCallback(UAVObjEvent* ev) // we've met the time requirements. PIOS_IAP_SetRequest1(); PIOS_IAP_SetRequest2(); - // goodbye cruel world... - PIOS_SYS_Reset(); + xTaskCreate(resetTask, (signed char *)"Reset", STACK_SIZE, NULL, TASK_PRIORITY, &taskHandle); } else { iap_state = IAP_STATE_READY; } @@ -200,4 +225,36 @@ static uint32_t iap_calc_crc(void) CRC_CalcBlockCRC((uint32_t *) START_OF_USER_CODE, (SIZE_OF_CODE) >> 2); return CRC_GetCRC(); } +static uint8_t *FLASH_If_Read(uint32_t SectorAddress) +{ + return (uint8_t *) (SectorAddress); +} +static void read_description(uint8_t * array) +{ + uint8_t x = 0; + for (uint32_t i = START_OF_USER_CODE + SIZE_OF_CODE; i < START_OF_USER_CODE + SIZE_OF_CODE + SIZE_OF_DESCRIPTION; ++i) { + array[x] = *FLASH_If_Read(i); + ++x; + } +} +static void resetTask(void *parameters) +{ + + portTickType lastSysTime; + uint8_t count=0; + // Main task loop + lastSysTime = xTaskGetTickCount(); + while (1) { + data.Target=0xFF; + data.ArmReset=1; + data.crc=count; + FirmwareIAPObjSet(&data); + vTaskDelayUntil(&lastSysTime, 500 / portTICK_RATE_MS); + ++count; + if(count>3) + { + PIOS_SYS_Reset(); + } + } +} diff --git a/flight/OpenPilot/UAVObjects/inc/firmwareiapobj.h b/flight/OpenPilot/UAVObjects/inc/firmwareiapobj.h index adc2ad030..bc2501cfd 100644 --- a/flight/OpenPilot/UAVObjects/inc/firmwareiapobj.h +++ b/flight/OpenPilot/UAVObjects/inc/firmwareiapobj.h @@ -41,7 +41,7 @@ #define FIRMWAREIAPOBJ_H // Object constants -#define FIRMWAREIAPOBJ_OBJID 1075803696U +#define FIRMWAREIAPOBJ_OBJID 879185696U #define FIRMWAREIAPOBJ_NAME "FirmwareIAPObj" #define FIRMWAREIAPOBJ_METANAME "FirmwareIAPObjMeta" #define FIRMWAREIAPOBJ_ISSINGLEINST 1 @@ -72,20 +72,22 @@ // Object data typedef struct { uint16_t Command; - uint32_t Port; - uint8_t Version[3]; - uint16_t SVN; + uint8_t Description[100]; + uint8_t HWVersion; + uint8_t Target; + uint8_t ArmReset; uint32_t crc; } __attribute__((packed)) FirmwareIAPObjData; // Field information // Field Command information -// Field Port information -// Field Version information -/* Number of elements for field Version */ -#define FIRMWAREIAPOBJ_VERSION_NUMELEM 3 -// Field SVN information +// Field Description information +/* Number of elements for field Description */ +#define FIRMWAREIAPOBJ_DESCRIPTION_NUMELEM 100 +// Field HWVersion information +// Field Target information +// Field ArmReset information // Field crc information diff --git a/flight/PiOS/Boards/STM32103CB_AHRS.h b/flight/PiOS/Boards/STM32103CB_AHRS.h index c05b278f6..1fd9ee5f4 100644 --- a/flight/PiOS/Boards/STM32103CB_AHRS.h +++ b/flight/PiOS/Boards/STM32103CB_AHRS.h @@ -64,6 +64,7 @@ TIM8 | | | | //------------------------ // BOOTLOADER_SETTINGS //------------------------ +#define FUNC_ID 2 #define HW_VERSION 69 #define BOOTLOADER_VERSION 0 #define MEM_SIZE 0x20000 //128K diff --git a/flight/PiOS/Boards/STM3210E_OP.h b/flight/PiOS/Boards/STM3210E_OP.h index d0fc8932a..8560891b0 100644 --- a/flight/PiOS/Boards/STM3210E_OP.h +++ b/flight/PiOS/Boards/STM3210E_OP.h @@ -69,6 +69,7 @@ TIM8 | Servo 5 | Servo 6 | Servo 7 | Servo 8 // BOOTLOADER_SETTINGS //------------------------ +#define FUNC_ID 1 #define HW_VERSION 01 #define BOOTLOADER_VERSION 0 #define MEM_SIZE 524288 //512K diff --git a/flight/PiOS/Common/pios_iap.c b/flight/PiOS/Common/pios_iap.c index 0ec3a46a6..b9a71a331 100644 --- a/flight/PiOS/Common/pios_iap.c +++ b/flight/PiOS/Common/pios_iap.c @@ -69,6 +69,7 @@ void PIOS_IAP_Init( void ) /* Clear Tamper pin Event(TE) pending flag */ BKP_ClearFlag(); + } /*! diff --git a/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp b/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp index a236f0165..e846cbea6 100644 --- a/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp +++ b/ground/src/experimental/USB_UPLOAD_TOOL/main.cpp @@ -13,8 +13,6 @@ int main(int argc, char *argv[]) ///////////////////////////////////////////// -// OP_DFU dfu(false); -// dfu.test(); QCoreApplication a(argc, argv); // argc=4; // argv[1]="-ls"; @@ -25,6 +23,7 @@ int main(int argc, char *argv[]) bool use_serial=false; bool verify; bool debug=false; + bool umodereset=false; OP_DFU::Actions action; QString file; QString serialport; @@ -37,6 +36,8 @@ int main(int argc, char *argv[]) } if(args.contains("-debug")) debug=true; + if(args.contains("-ur")) + umodereset=true; if(args.contains("-?")||(!PRIVATE && argc==1)) { cout<<"_________________________________________________________________________\n"; @@ -55,12 +56,13 @@ int main(int argc, char *argv[]) cout<<"| -r : resets the device |\n"; cout<<"| -j : exits bootloader and jumps to user FW |\n"; cout<<"| -debug : prints debug information |\n"; - cout<<"| -t : uses serial port* |\n"; + cout<<"| -t : uses serial port(requires:-ur) |\n"; + cout<<"| -ur : user mode reset* |\n"; cout<<"| |\n"; cout<<"| examples: |\n"; cout<<"| |\n"; cout<<"| program and verify device #0 |\n"; - cout<<"| OPUploadTool -p c:/OpenPilot.bin -w \"Openpilot Firmware\" -v -d 0 |\n"; + cout<<"| OPUploadTool -p c:/OpenPilot.bin -w \"Openpilot Firmware\" -v -d 0 |\n"; cout<<"| |\n"; cout<<"| Perform a quick compare of FW in file with FW in device #1 |\n"; cout<<"| OPUploadTool -ch c:/OpenPilot2.bin -d 2 |\n"; @@ -203,7 +205,7 @@ int main(int argc, char *argv[]) } ///////////////////////////////////ACTIONS START/////////////////////////////////////////////////// - OP_DFU dfu(debug,use_serial,serialport); + OP_DFU dfu(debug,use_serial,serialport,umodereset); if(!dfu.ready()) return -1; diff --git a/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.cpp b/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.cpp index bc4ff826e..d1ad76df2 100644 --- a/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.cpp +++ b/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.cpp @@ -3,7 +3,7 @@ #include #include -OP_DFU::OP_DFU(bool _debug,bool _use_serial,QString portname): debug(_debug),use_serial(_use_serial),mready(true) +OP_DFU::OP_DFU(bool _debug,bool _use_serial,QString portname,bool umodereset): debug(_debug),use_serial(_use_serial),mready(true) { if(use_serial) { @@ -30,6 +30,9 @@ OP_DFU::OP_DFU(bool _debug,bool _use_serial,QString portname): debug(_debug),use mready=false; return; } + if(umodereset) + sendReset(); + delay::msleep(5000); serialhandle=new qsspt(info,debug); while(serialhandle->ssp_Synchronise()==false) @@ -64,19 +67,61 @@ OP_DFU::OP_DFU(bool _debug,bool _use_serial,QString portname): debug(_debug),use } if(debug) qDebug() << numDevices << " device(s) opened"; - //sendReset(); + if(umodereset) + { + sendReset(); + + qDebug()<<"before delay"; + delay::msleep(5000); + qDebug()<<"after delay"; + if(hidHandle.open(1,0x20a0,0x4117,0,0)==0) + mready=false; + } } } void OP_DFU::sendReset(void) { - char b[64]={0x02,0x24,0x3C,0x20,0x17,0x00,0x30,0x76,0x1F,0x40,0x62,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6C,0x40,0x2E,0x00,0x00,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - sendData(b,64); + qDebug()<<"Requesting user mode reset"; + char aa[255]= {0x02,0x3E,0x3C,0x20,0x75,0x00,0x20,0x4F,0x67,0x34,0x62,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//63 + char ba[255]= {0x02,0x3E,0x3C,0x20,0x75,0x00,0x20,0x4F,0x67,0x34,0xB9,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + char ca[255]= {0x02,0x3E,0x3C,0x20,0x75,0x00,0x20,0x4F,0x67,0x34,0x10,0x0D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + char bb[255]={0x02,0x3D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x8D,0x19,0x00,0x00,0x13}; + char ab[255]={0x02,0x3D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x47,0x1B,0x19,0x00,0x00,0x76}; + char cb[255]={0x02,0x3D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x66,0x78,0x1C,0x00,0x00,0x25}; + //125 + if(!use_serial) + { + hidHandle.send(0,aa, 64, 5000); + hidHandle.send(0,ab, 64, 5000); delay::msleep(600); - char bb[64]={0x02,0x24,0x3C,0x20,0x17,0x00,0x30,0x76,0x1F,0x40,0xB9,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0xE8,0x30,0x00,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - sendData(bb,64); + hidHandle.send(0,ba, 64, 5000); + hidHandle.send(0,bb, 64, 5000); delay::msleep(600); - char bbb[64]={0x02,0x24,0x3C,0x20,0x17,0x00,0x30,0x76,0x1F,0x40,0x10,0x0D,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF9,0x61,0x34,0x00,0x00,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - sendData(bbb,64); + hidHandle.send(0,ca, 64, 5000); + hidHandle.send(0,cb, 64, 5000); + delay::msleep(100); + hidHandle.close(1); +} + else + { + char a[255]; + char b[255]; + char c[255]; + memcpy (a,aa+2,62); + memcpy (a+62,ab+2,60); + memcpy (b,ba+2,62); + memcpy (b+62,bb+2,60); + memcpy (c,ca+2,62); + memcpy (c+62,cb+2,60); + for(int x=0;x<123;++x) + info->pfSerialWrite(a[x]); + delay::msleep(600); + for(int x=0;x<123;++x) + info->pfSerialWrite(b[x]); + delay::msleep(600); + for(int x=0;x<123;++x) + info->pfSerialWrite(c[x]); + } } bool OP_DFU::SaveByteArrayToFile(QString const & sfile, const QByteArray &array) diff --git a/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.h b/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.h index ca0cb1d66..5700edbbd 100644 --- a/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.h +++ b/ground/src/experimental/USB_UPLOAD_TOOL/op_dfu.h @@ -123,7 +123,7 @@ public: bool SaveByteArrayToFile(QString const & file,QByteArray const &array); void CopyWords(char * source, char* destination, int count); // QByteArray DownloadData(int devNumber,int numberOfPackets); - OP_DFU(bool debug,bool use_serial,QString port); + OP_DFU(bool debug,bool use_serial,QString port,bool umodereset); void sendReset(void); bool findDevices(); QList devices; diff --git a/ground/src/plugins/uavobjects/firmwareiapobj.cpp b/ground/src/plugins/uavobjects/firmwareiapobj.cpp index 62f51cbe1..0d0074645 100644 --- a/ground/src/plugins/uavobjects/firmwareiapobj.cpp +++ b/ground/src/plugins/uavobjects/firmwareiapobj.cpp @@ -45,17 +45,117 @@ FirmwareIAPObj::FirmwareIAPObj(): UAVDataObject(OBJID, ISSINGLEINST, ISSETTINGS, QStringList CommandElemNames; CommandElemNames.append("0"); fields.append( new UAVObjectField(QString("Command"), QString("na"), UAVObjectField::UINT16, CommandElemNames, QStringList()) ); - QStringList PortElemNames; - PortElemNames.append("0"); - fields.append( new UAVObjectField(QString("Port"), QString("na"), UAVObjectField::UINT32, PortElemNames, QStringList()) ); - QStringList VersionElemNames; - VersionElemNames.append("0"); - VersionElemNames.append("1"); - VersionElemNames.append("2"); - fields.append( new UAVObjectField(QString("Version"), QString("na"), UAVObjectField::UINT8, VersionElemNames, QStringList()) ); - QStringList SVNElemNames; - SVNElemNames.append("0"); - fields.append( new UAVObjectField(QString("SVN"), QString("na"), UAVObjectField::UINT16, SVNElemNames, QStringList()) ); + QStringList DescriptionElemNames; + DescriptionElemNames.append("0"); + DescriptionElemNames.append("1"); + DescriptionElemNames.append("2"); + DescriptionElemNames.append("3"); + DescriptionElemNames.append("4"); + DescriptionElemNames.append("5"); + DescriptionElemNames.append("6"); + DescriptionElemNames.append("7"); + DescriptionElemNames.append("8"); + DescriptionElemNames.append("9"); + DescriptionElemNames.append("10"); + DescriptionElemNames.append("11"); + DescriptionElemNames.append("12"); + DescriptionElemNames.append("13"); + DescriptionElemNames.append("14"); + DescriptionElemNames.append("15"); + DescriptionElemNames.append("16"); + DescriptionElemNames.append("17"); + DescriptionElemNames.append("18"); + DescriptionElemNames.append("19"); + DescriptionElemNames.append("20"); + DescriptionElemNames.append("21"); + DescriptionElemNames.append("22"); + DescriptionElemNames.append("23"); + DescriptionElemNames.append("24"); + DescriptionElemNames.append("25"); + DescriptionElemNames.append("26"); + DescriptionElemNames.append("27"); + DescriptionElemNames.append("28"); + DescriptionElemNames.append("29"); + DescriptionElemNames.append("30"); + DescriptionElemNames.append("31"); + DescriptionElemNames.append("32"); + DescriptionElemNames.append("33"); + DescriptionElemNames.append("34"); + DescriptionElemNames.append("35"); + DescriptionElemNames.append("36"); + DescriptionElemNames.append("37"); + DescriptionElemNames.append("38"); + DescriptionElemNames.append("39"); + DescriptionElemNames.append("40"); + DescriptionElemNames.append("41"); + DescriptionElemNames.append("42"); + DescriptionElemNames.append("43"); + DescriptionElemNames.append("44"); + DescriptionElemNames.append("45"); + DescriptionElemNames.append("46"); + DescriptionElemNames.append("47"); + DescriptionElemNames.append("48"); + DescriptionElemNames.append("49"); + DescriptionElemNames.append("50"); + DescriptionElemNames.append("51"); + DescriptionElemNames.append("52"); + DescriptionElemNames.append("53"); + DescriptionElemNames.append("54"); + DescriptionElemNames.append("55"); + DescriptionElemNames.append("56"); + DescriptionElemNames.append("57"); + DescriptionElemNames.append("58"); + DescriptionElemNames.append("59"); + DescriptionElemNames.append("60"); + DescriptionElemNames.append("61"); + DescriptionElemNames.append("62"); + DescriptionElemNames.append("63"); + DescriptionElemNames.append("64"); + DescriptionElemNames.append("65"); + DescriptionElemNames.append("66"); + DescriptionElemNames.append("67"); + DescriptionElemNames.append("68"); + DescriptionElemNames.append("69"); + DescriptionElemNames.append("70"); + DescriptionElemNames.append("71"); + DescriptionElemNames.append("72"); + DescriptionElemNames.append("73"); + DescriptionElemNames.append("74"); + DescriptionElemNames.append("75"); + DescriptionElemNames.append("76"); + DescriptionElemNames.append("77"); + DescriptionElemNames.append("78"); + DescriptionElemNames.append("79"); + DescriptionElemNames.append("80"); + DescriptionElemNames.append("81"); + DescriptionElemNames.append("82"); + DescriptionElemNames.append("83"); + DescriptionElemNames.append("84"); + DescriptionElemNames.append("85"); + DescriptionElemNames.append("86"); + DescriptionElemNames.append("87"); + DescriptionElemNames.append("88"); + DescriptionElemNames.append("89"); + DescriptionElemNames.append("90"); + DescriptionElemNames.append("91"); + DescriptionElemNames.append("92"); + DescriptionElemNames.append("93"); + DescriptionElemNames.append("94"); + DescriptionElemNames.append("95"); + DescriptionElemNames.append("96"); + DescriptionElemNames.append("97"); + DescriptionElemNames.append("98"); + DescriptionElemNames.append("99"); + fields.append( new UAVObjectField(QString("Description"), QString("na"), UAVObjectField::UINT8, DescriptionElemNames, QStringList()) ); + QStringList HWVersionElemNames; + HWVersionElemNames.append("0"); + fields.append( new UAVObjectField(QString("HWVersion"), QString("na"), UAVObjectField::UINT8, HWVersionElemNames, QStringList()) ); + QStringList TargetElemNames; + TargetElemNames.append("0"); + fields.append( new UAVObjectField(QString("Target"), QString("na"), UAVObjectField::UINT8, TargetElemNames, QStringList()) ); + QStringList ArmResetElemNames; + ArmResetElemNames.append("0"); + fields.append( new UAVObjectField(QString("ArmReset"), QString("na"), UAVObjectField::UINT8, ArmResetElemNames, QStringList()) ); QStringList crcElemNames; crcElemNames.append("0"); fields.append( new UAVObjectField(QString("crc"), QString("na"), UAVObjectField::UINT32, crcElemNames, QStringList()) ); diff --git a/ground/src/plugins/uavobjects/firmwareiapobj.h b/ground/src/plugins/uavobjects/firmwareiapobj.h index f8566ed47..2b919a4eb 100644 --- a/ground/src/plugins/uavobjects/firmwareiapobj.h +++ b/ground/src/plugins/uavobjects/firmwareiapobj.h @@ -44,25 +44,27 @@ public: // Field structure typedef struct { quint16 Command; - quint32 Port; - quint8 Version[3]; - quint16 SVN; + quint8 Description[100]; + quint8 HWVersion; + quint8 Target; + quint8 ArmReset; quint32 crc; } __attribute__((packed)) DataFields; // Field information // Field Command information - // Field Port information - // Field Version information - /* Number of elements for field Version */ - static const quint32 VERSION_NUMELEM = 3; - // Field SVN information + // Field Description information + /* Number of elements for field Description */ + static const quint32 DESCRIPTION_NUMELEM = 100; + // Field HWVersion information + // Field Target information + // Field ArmReset information // Field crc information // Constants - static const quint32 OBJID = 1075803696U; + static const quint32 OBJID = 879185696U; static const QString NAME; static const bool ISSINGLEINST = 1; static const bool ISSETTINGS = 0; diff --git a/ground/src/plugins/uavobjects/firmwareiapobj.py b/ground/src/plugins/uavobjects/firmwareiapobj.py index b89c9bfd4..ad22d2461 100644 --- a/ground/src/plugins/uavobjects/firmwareiapobj.py +++ b/ground/src/plugins/uavobjects/firmwareiapobj.py @@ -48,8 +48,117 @@ _fields = [ \ } ), uavobject.UAVObjectField( - 'Port', - 'I', + 'Description', + 'B', + 100, + [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '10', + '11', + '12', + '13', + '14', + '15', + '16', + '17', + '18', + '19', + '20', + '21', + '22', + '23', + '24', + '25', + '26', + '27', + '28', + '29', + '30', + '31', + '32', + '33', + '34', + '35', + '36', + '37', + '38', + '39', + '40', + '41', + '42', + '43', + '44', + '45', + '46', + '47', + '48', + '49', + '50', + '51', + '52', + '53', + '54', + '55', + '56', + '57', + '58', + '59', + '60', + '61', + '62', + '63', + '64', + '65', + '66', + '67', + '68', + '69', + '70', + '71', + '72', + '73', + '74', + '75', + '76', + '77', + '78', + '79', + '80', + '81', + '82', + '83', + '84', + '85', + '86', + '87', + '88', + '89', + '90', + '91', + '92', + '93', + '94', + '95', + '96', + '97', + '98', + '99', + ], + { + } + ), + uavobject.UAVObjectField( + 'HWVersion', + 'B', 1, [ '0', @@ -58,20 +167,18 @@ _fields = [ \ } ), uavobject.UAVObjectField( - 'Version', + 'Target', 'B', - 3, + 1, [ '0', - '1', - '2', ], { } ), uavobject.UAVObjectField( - 'SVN', - 'H', + 'ArmReset', + 'B', 1, [ '0', @@ -94,7 +201,7 @@ _fields = [ \ class FirmwareIAPObj(uavobject.UAVObject): ## Object constants - OBJID = 1075803696 + OBJID = 879185696 NAME = "FirmwareIAPObj" METANAME = "FirmwareIAPObjMeta" ISSINGLEINST = 1 diff --git a/ground/src/shared/uavobjectdefinition/firmwareiap.xml b/ground/src/shared/uavobjectdefinition/firmwareiap.xml index 9e01a3444..32d0f7037 100644 --- a/ground/src/shared/uavobjectdefinition/firmwareiap.xml +++ b/ground/src/shared/uavobjectdefinition/firmwareiap.xml @@ -1,14 +1,16 @@ - - - Firmware IAP - - - - - - - - - - - + + + Firmware IAP + + + + + + + + + + + + +