Skip to content

Commit

Permalink
Merge pull request #48 from maxiwoj/fix-multiple-targets
Browse files Browse the repository at this point in the history
Fix multiple targets
  • Loading branch information
maxiwoj authored Nov 13, 2018
2 parents 421c7ba + 80e98ad commit b70c877
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Inc/communication/wakaama_client/objects/object_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "target.h"


extern int JTAG_BUSY;
extern int USB_BUSY;
/*
* Multiple instance objects can use userdata to store data that will be shared between the different instances.
* The lwm2m_object_t object structure - which represent every object of the liblwm2m as seen in the single instance
Expand Down
4 changes: 3 additions & 1 deletion Src/communication/binary_download.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static void download_error(target_instance_t *targetP, int err, int socket, char
lwip_close(socket);
}
lwm2m_free(url_str);
USB_BUSY = 0;
vTaskDelete(NULL);
}

Expand Down Expand Up @@ -155,12 +156,13 @@ void startDownload(void *object_target) {
targetP->download_error = NO_ERROR;
lwip_close(socket);
lwm2m_free(url_str);
USB_BUSY = 0;
vTaskDelete(NULL);
}

static uint8_t createFile(target_instance_t *targetP, char *url_str, int socket, FIL *file) {
if (get_usb_ready()) {
int result = usb_open_file(targetP->binary_filename, file, FA_WRITE | FA_CREATE_NEW);
int result = usb_open_file(targetP->binary_filename, file, FA_WRITE | FA_CREATE_ALWAYS);
if (result != 0) {
download_error(targetP, USB_ERROR, socket, url_str);
}
Expand Down
15 changes: 11 additions & 4 deletions Src/communication/wakaama_client/objects/object_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "object_target.h"
#include "binary_download.h"

int USB_BUSY = 0;
int JTAG_BUSY = 0;

static void prv_output_buffer(uint8_t * buffer,
int length)
{
Expand Down Expand Up @@ -210,7 +213,7 @@ static uint8_t target_write(uint16_t instanceId,
return COAP_405_METHOD_NOT_ALLOWED;
case 2:
{
if (targetP->download_state == DOWNLOAD_IN_PROGRESS || targetP->flash_state == FLASH_IN_PROGRESS) {
if (targetP->download_state == DOWNLOAD_IN_PROGRESS || targetP->flash_state == FLASH_IN_PROGRESS || USB_BUSY) {
return COAP_412_PRECONDITION_FAILED;
}
if (!(dataArray[i].type == LWM2M_TYPE_STRING) && !(dataArray[i].type == LWM2M_TYPE_OPAQUE)) {
Expand All @@ -223,9 +226,10 @@ static uint8_t target_write(uint16_t instanceId,
targetP->firmware_url = lwm2m_strdup((char*)dataArray[i].value.asBuffer.buffer);
targetP->firmware_version = lwm2m_gettime();
targetP->download_state = DOWNLOAD_IN_PROGRESS;
sprintf(targetP->binary_filename, "%ld", targetP->firmware_version);
sprintf(targetP->binary_filename, "%x.%d", targetP->firmware_version, targetP->shortID);
targetP->download_progress = 0;

USB_BUSY = 1;
xTaskCreate(startDownload, NULL, 2000, (void*) targetP, 2, NULL);
}
break;
Expand Down Expand Up @@ -298,7 +302,7 @@ static uint8_t target_exec(uint16_t instanceId,
case 4:
return COAP_405_METHOD_NOT_ALLOWED;
case 5:
if (targetP->download_state != DOWNLOAD_COMPLETED || targetP->flash_state == FLASH_IN_PROGRESS) {
if (targetP->download_state != DOWNLOAD_COMPLETED || targetP->flash_state == FLASH_IN_PROGRESS || JTAG_BUSY || USB_BUSY) {
return COAP_412_PRECONDITION_FAILED;
}
fprintf(stdout, "\r\n-----------------\r\n"
Expand All @@ -310,12 +314,14 @@ static uint8_t target_exec(uint16_t instanceId,
fprintf(stdout, "-----------------\r\n\r\n");
targetP->flash_state=FLASH_IN_PROGRESS;
targetP->flash_progress=0;
JTAG_BUSY = 1;
USB_BUSY = 1;
xTaskCreate(flash_target_task, "Flash_Target", 2000, targetP, 1, NULL);
return COAP_204_CHANGED;
case 6:
return COAP_405_METHOD_NOT_ALLOWED;
case 7:
if (targetP->flash_state == FLASH_IN_PROGRESS) {
if (targetP->flash_state == FLASH_IN_PROGRESS || JTAG_BUSY) {
return COAP_412_PRECONDITION_FAILED;
}
fprintf(stdout, "\r\n-----------------\r\n"
Expand All @@ -325,6 +331,7 @@ static uint8_t target_exec(uint16_t instanceId,
objectP->objID, instanceId, resourceId, targetP->target_type, length);
prv_output_buffer((uint8_t*)buffer, length);
fprintf(stdout, "-----------------\r\n\r\n");
JTAG_BUSY = 1;
xTaskCreate(reset_target_task, "ResetTarget", 300, targetP, 1, NULL);
return COAP_204_CHANGED;
case 8:
Expand Down
5 changes: 5 additions & 0 deletions Src/target.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ void flash_target_task(void *object) {
if (result != 0) {
target_object->flash_error = USB_FS_ERROR;
target_object->flash_state = FLASH_ERROR;
JTAG_BUSY = 0;
USB_BUSY = 0;
vTaskDelete(NULL);
}

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

result = usb_close_file(&file);
JTAG_BUSY = 0;
USB_BUSY = 0;
if (result != 0) {
target_object->flash_error = USB_FS_ERROR;
vTaskDelete(NULL);
Expand All @@ -50,5 +54,6 @@ void flash_target_task(void *object) {
void reset_target_task(void *object) {
target_instance_t * target_object = (target_instance_t *) object;
target_object->target->ops->reset_target(target_object->target->priv);
JTAG_BUSY = 0;
vTaskDelete(NULL);
}

0 comments on commit b70c877

Please sign in to comment.