Skip to content

Commit b70c877

Browse files
authored
Merge pull request #48 from maxiwoj/fix-multiple-targets
Fix multiple targets
2 parents 421c7ba + 80e98ad commit b70c877

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

Inc/communication/wakaama_client/objects/object_target.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
#include "target.h"
66

7+
8+
extern int JTAG_BUSY;
9+
extern int USB_BUSY;
710
/*
811
* Multiple instance objects can use userdata to store data that will be shared between the different instances.
912
* The lwm2m_object_t object structure - which represent every object of the liblwm2m as seen in the single instance

Src/communication/binary_download.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ static void download_error(target_instance_t *targetP, int err, int socket, char
3030
lwip_close(socket);
3131
}
3232
lwm2m_free(url_str);
33+
USB_BUSY = 0;
3334
vTaskDelete(NULL);
3435
}
3536

@@ -155,12 +156,13 @@ void startDownload(void *object_target) {
155156
targetP->download_error = NO_ERROR;
156157
lwip_close(socket);
157158
lwm2m_free(url_str);
159+
USB_BUSY = 0;
158160
vTaskDelete(NULL);
159161
}
160162

161163
static uint8_t createFile(target_instance_t *targetP, char *url_str, int socket, FIL *file) {
162164
if (get_usb_ready()) {
163-
int result = usb_open_file(targetP->binary_filename, file, FA_WRITE | FA_CREATE_NEW);
165+
int result = usb_open_file(targetP->binary_filename, file, FA_WRITE | FA_CREATE_ALWAYS);
164166
if (result != 0) {
165167
download_error(targetP, USB_ERROR, socket, url_str);
166168
}

Src/communication/wakaama_client/objects/object_target.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include "object_target.h"
3434
#include "binary_download.h"
3535

36+
int USB_BUSY = 0;
37+
int JTAG_BUSY = 0;
38+
3639
static 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:

Src/target.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void flash_target_task(void *object) {
2727
if (result != 0) {
2828
target_object->flash_error = USB_FS_ERROR;
2929
target_object->flash_state = FLASH_ERROR;
30+
JTAG_BUSY = 0;
31+
USB_BUSY = 0;
3032
vTaskDelete(NULL);
3133
}
3234

@@ -40,6 +42,8 @@ void flash_target_task(void *object) {
4042
}
4143

4244
result = usb_close_file(&file);
45+
JTAG_BUSY = 0;
46+
USB_BUSY = 0;
4347
if (result != 0) {
4448
target_object->flash_error = USB_FS_ERROR;
4549
vTaskDelete(NULL);
@@ -50,5 +54,6 @@ void flash_target_task(void *object) {
5054
void reset_target_task(void *object) {
5155
target_instance_t * target_object = (target_instance_t *) object;
5256
target_object->target->ops->reset_target(target_object->target->priv);
57+
JTAG_BUSY = 0;
5358
vTaskDelete(NULL);
5459
}

0 commit comments

Comments
 (0)