- const DelugeDissemination *delugeDis = call DisseminationValue.get();
- DelugeImgDesc *imgDesc = call DelugeMetadata.getImgDesc(delugeDis->imgNum);
-
- switch (delugeDis->msg_type) {
- case DISSMSG_DISS:
- if (imgDesc->uid == delugeDis->uid && imgDesc->uid != DELUGE_INVALID_UID) {
- if (imgDesc->vNum < delugeDis->vNum) {
- recv_uid = delugeDis->uid;
- recv_size = delugeDis->size;
- recv_imgNum = delugeDis->imgNum;
- call ObjectTransfer.receive(delugeDis->uid, delugeDis->size, delugeDis->imgNum);
- }
- } else {
- recv_uid = delugeDis->uid;
- recv_size = delugeDis->size;
- recv_imgNum = delugeDis->imgNum;
- call ObjectTransfer.receive(delugeDis->uid, delugeDis->size, delugeDis->imgNum);
- }
-
- break;
- case DISSMSG_REPROG:
- if (imgDesc->uid != DELUGE_INVALID_UID) {
- DelugeNodeDesc nodeDesc;
- call IFlash.read((uint8_t*)IFLASH_NODE_DESC_ADDR,
- &nodeDesc,
- sizeof(DelugeNodeDesc)); // Reads which image was just reprogrammed
- if (nodeDesc.uid != imgDesc->uid || nodeDesc.vNum != imgDesc->vNum) {
- call NetProg.programImgAndReboot(delugeDis->imgNum);
- }
- }
-
- break;
+ const DelugeCmd *cmd = call DisseminationValue.get();
+// printf("cmd: %d uidhash: 0x%lx imgNum: %d size: %u\n", cmd->type, cmd->uidhash, cmd->imgNum, cmd->size);
+ switch (cmd->type) {
+ case DELUGE_CMD_STOP:
+ call stop();
+ break;
+ case DELUGE_CMD_ONLY_DISSEMINATE:
+ case DELUGE_CMD_DISSEMINATE_AND_REPROGRAM:
+ if (state == S_RECV) {
+ if (cmd->uidhash == lastCmd.uidhash) {
+ if (cmd->imgNum == lastCmd.imgNum) {
+ // Same uidhash, same imgNum, only cmd should be
+ // different. That will be properly updated by the last
+ // statement from this function.
+ break;
+ }
+ }
+ call stop();
+ }
+ if (cmd->uidhash != IDENT_UIDHASH) {
+ call DelugeMetadata.read(cmd->imgNum);
+ } else {
+ state = S_PUB;
+ request();
+ }
+ break;