3333#include "object_target.h"
3434#include "binary_download.h"
3535
36+ int USB_BUSY = 0 ;
37+ int JTAG_BUSY = 0 ;
38+
3639static void prv_output_buffer (uint8_t * buffer ,
3740 int length )
3841{
@@ -210,7 +213,7 @@ static uint8_t target_write(uint16_t instanceId,
210213 return COAP_405_METHOD_NOT_ALLOWED ;
211214 case 2 :
212215 {
213- if (targetP -> download_state == DOWNLOAD_IN_PROGRESS || targetP -> flash_state == FLASH_IN_PROGRESS ) {
216+ if (targetP -> download_state == DOWNLOAD_IN_PROGRESS || targetP -> flash_state == FLASH_IN_PROGRESS || USB_BUSY ) {
214217 return COAP_412_PRECONDITION_FAILED ;
215218 }
216219 if (!(dataArray [i ].type == LWM2M_TYPE_STRING ) && !(dataArray [i ].type == LWM2M_TYPE_OPAQUE )) {
@@ -223,9 +226,10 @@ static uint8_t target_write(uint16_t instanceId,
223226 targetP -> firmware_url = lwm2m_strdup ((char * )dataArray [i ].value .asBuffer .buffer );
224227 targetP -> firmware_version = lwm2m_gettime ();
225228 targetP -> download_state = DOWNLOAD_IN_PROGRESS ;
226- sprintf (targetP -> binary_filename , "%ld " , targetP -> firmware_version );
229+ sprintf (targetP -> binary_filename , "%x.%d " , targetP -> firmware_version , targetP -> shortID );
227230 targetP -> download_progress = 0 ;
228231
232+ USB_BUSY = 1 ;
229233 xTaskCreate (startDownload , NULL , 2000 , (void * ) targetP , 2 , NULL );
230234 }
231235 break ;
@@ -298,7 +302,7 @@ static uint8_t target_exec(uint16_t instanceId,
298302 case 4 :
299303 return COAP_405_METHOD_NOT_ALLOWED ;
300304 case 5 :
301- if (targetP -> download_state != DOWNLOAD_COMPLETED || targetP -> flash_state == FLASH_IN_PROGRESS ) {
305+ if (targetP -> download_state != DOWNLOAD_COMPLETED || targetP -> flash_state == FLASH_IN_PROGRESS || JTAG_BUSY || USB_BUSY ) {
302306 return COAP_412_PRECONDITION_FAILED ;
303307 }
304308 fprintf (stdout , "\r\n-----------------\r\n"
@@ -310,12 +314,14 @@ static uint8_t target_exec(uint16_t instanceId,
310314 fprintf (stdout , "-----------------\r\n\r\n" );
311315 targetP -> flash_state = FLASH_IN_PROGRESS ;
312316 targetP -> flash_progress = 0 ;
317+ JTAG_BUSY = 1 ;
318+ USB_BUSY = 1 ;
313319 xTaskCreate (flash_target_task , "Flash_Target" , 2000 , targetP , 1 , NULL );
314320 return COAP_204_CHANGED ;
315321 case 6 :
316322 return COAP_405_METHOD_NOT_ALLOWED ;
317323 case 7 :
318- if (targetP -> flash_state == FLASH_IN_PROGRESS ) {
324+ if (targetP -> flash_state == FLASH_IN_PROGRESS || JTAG_BUSY ) {
319325 return COAP_412_PRECONDITION_FAILED ;
320326 }
321327 fprintf (stdout , "\r\n-----------------\r\n"
@@ -325,6 +331,7 @@ static uint8_t target_exec(uint16_t instanceId,
325331 objectP -> objID , instanceId , resourceId , targetP -> target_type , length );
326332 prv_output_buffer ((uint8_t * )buffer , length );
327333 fprintf (stdout , "-----------------\r\n\r\n" );
334+ JTAG_BUSY = 1 ;
328335 xTaskCreate (reset_target_task , "ResetTarget" , 300 , targetP , 1 , NULL );
329336 return COAP_204_CHANGED ;
330337 case 8 :
0 commit comments