// States
enum {
S_ERASE,
+ S_SYNC,
S_INITIALIZING_PUB,
S_INITIALIZING_RECV,
S_STARTED,
resetTimer();
} else {
call DelugePageTransfer.setWorkingPage(DELUGE_INVALID_OBJID, DELUGE_INVALID_PGNUM);
- post signalObjRecvDone();
+ call ObjectTransfer.stop();
+ state = S_SYNC;
+ call BlockWrite.sync[cont_receive_img_num]();
}
}
void sendAdvMsg(uint16_t addr)
{
- DelugeAdvMsg *pMsg = (DelugeAdvMsg *)(call SendAdvMsg.getPayload(&pMsgBuf));
-
+ DelugeAdvMsg *pMsg = (DelugeAdvMsg *)(call SendAdvMsg.getPayload(&pMsgBuf, sizeof(DelugeAdvMsg)));
+ if (pMsg == NULL) {
+ return;
+ }
if (isBusy_pMsgBuf == FALSE) {
pMsg->sourceAddr = TOS_NODE_ID;
pMsg->version = DELUGE_VERSION;
if (call SendAdvMsg.send(addr, &pMsgBuf, sizeof(DelugeAdvMsg)) == SUCCESS) {
//dbg(DBG_USR1, "DELUGE: Sent ADV_MSG(imgNum=%d)\n", imgDesc->imgNum);
//call StatsCollector.msg_bcastReq();
-call Leds.led0Toggle();
isBusy_pMsgBuf = TRUE;
}
}
error_t error;
call ObjectTransfer.stop();
- state = S_STOPPED;
//call StatsCollector.startStatsCollector();
cont_receive_new_objid = new_objid;
cont_receive_new_size = new_size;
cont_receive_img_num = img_num;
- error = call BlockWrite.erase[img_num]();
+ error = call BlockWrite.erase[cont_receive_img_num]();
if (error == SUCCESS) {
state = S_ERASE;
}
{
call Timer.stop();
call DelugePageTransfer.stop();
+ state = S_STOPPED;
//call StatsCollector.stopStatsCollector();
- state = S_STOPPED;
curObjDesc.objid = DELUGE_INVALID_OBJID;
curObjDesc.numPgs = DELUGE_INVALID_PGNUM;
curObjDesc.numPgsComplete = DELUGE_INVALID_PGNUM;
+ advTimers.periodLog2 = 0;
return SUCCESS;
}
setNextPage();
} else {
call DelugePageTransfer.setWorkingPage(curObjDesc.objid, curObjDesc.numPgsComplete);
- post signalObjRecvDone();
+ state = S_SYNC;
+ if (call BlockWrite.sync[cont_receive_img_num]() != SUCCESS) {
+ post signalObjRecvDone();
+ }
}
}
}
+ event void BlockWrite.syncDone[uint8_t img_num](error_t error)
+ {
+ if (state == S_SYNC) {
+ post signalObjRecvDone();
+ }
+ }
+
event void DelugePageTransfer.suppressMsgs(object_id_t new_objid)
{
if (new_objid == curObjDesc.objid) {
}
event void Timer.fired()
- {
+ {
updateTimers();
if (advTimers.overheard == 0) {
}
default command error_t BlockWrite.erase[uint8_t img_num]() { return FAIL; }
+ default command error_t BlockWrite.sync[uint8_t img_num]() { return FAIL; }
+
event void BlockWrite.writeDone[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {}
event void BlockWrite.eraseDone[uint8_t img_num](error_t error)
{
cont_receive();
}
}
- event void BlockWrite.syncDone[uint8_t img_num](error_t error) {}
}