Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikekblad committed Mar 26, 2015
1 parent adca8b5 commit c1a9a53
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 8 additions & 1 deletion libraries/MySensors/MyConfig.h
Expand Up @@ -19,9 +19,16 @@
// Note: You can still have OTA FW updates without external flash but it
// requires the MYSBootloader and disabled MY_OTA_FIRMWARE_FEATURE
#define MY_OTA_FIRMWARE_FEATURE

// Slave select pin for external flash
#define MY_OTA_FLASH_SS 8
// Number of times to request a fw block before giving up
#define MY_OTA_RETRY 5
// Number of millisecons before re-request a fw block
#define MY_OTA_RETRY_DELAY 500
// Bootloader version
#define MY_OTA_BOOTLOADER_MAJOR_VERSION 2
#define MY_OTA_BOOTLOADER_MINOR_VERSION 0
#define MY_OTA_BOOTLOADER_VERSION (MY_OTA_BOOTLOADER_MINOR_VERSION * 256 + MY_OTA_BOOTLOADER_MAJOR_VERSION)


/**********************************
Expand Down
29 changes: 28 additions & 1 deletion libraries/MySensors/MySensor.cpp
Expand Up @@ -57,7 +57,7 @@ MySensor::MySensor(MyTransport &_radio, MyHw &_hw

#ifdef MY_OTA_FRIMWARE_FEATURE
// do a crc16 on the whole received firmware
static uint8_t MySensor::isValidFirmware() {
bool MySensor::isValidFirmware() {
void* ptr = 0;
uint16_t crc = ~0;
int j;
Expand Down Expand Up @@ -188,6 +188,33 @@ void MySensor::setupNode() {

// Wait configuration reply.
wait(2000);

#ifdef MY_OTA_FRIMWARE_FEATURE
RequestFirmwareConfig *reqFWConfig = (RequestFirmwareConfig *)msg.data;
mSetLength(msg, sizeof(RequestFirmwareConfig));
mSetCommand(msg, C_STREAM);
mSetPayloadType(msg,P_CUSTOM);
// copy node settings to reqFWConfig
memcpy(reqFWConfig,&fc,sizeof(NodeFirmwareConfig));
// add bootloader information
reqFWConfig->BLVersion = MYSBOOTLOADER_VERSION;

// send node config and request FW config from controller
if (!sendAndWait(ST_FIRMWARE_CONFIG_REQUEST, ST_FIRMWARE_CONFIG_RESPONSE)) {
startup();
}

NodeFirmwareConfig *firmwareConfigResponse = (NodeFirmwareConfig *)inMsg.data;

// compare with current node configuration, if equal startup
if (!memcmp(&fc,firmwareConfigResponse,sizeof(NodeFirmwareConfig))) {
startup();
}


#endif


}
}

Expand Down
6 changes: 6 additions & 0 deletions libraries/MySensors/MySensor.h
Expand Up @@ -309,6 +309,12 @@ class MySensor
void (*timeCallback)(unsigned long); // Callback for requested time messages
void (*msgCallback)(const MyMessage &); // Callback for incoming messages from other nodes and gateway.

#ifdef MY_OTA_FRIMWARE_FEATURE
// do a crc16 on the whole received firmware
bool isValidFirmware();
#endif


void requestNodeId();
void setupNode();
void findParentNode();
Expand Down

0 comments on commit c1a9a53

Please sign in to comment.