};
DelugeAdvTimer advTimers;
- //DelugeNodeDesc nodeDesc;
uint8_t state = S_STOPPED;
object_id_t cont_receive_new_objid;
resetTimer();
} else {
call DelugePageTransfer.setWorkingPage(DELUGE_INVALID_OBJID, DELUGE_INVALID_PGNUM);
- state = S_SYNC;
call ObjectTransfer.stop();
+ state = S_SYNC;
call BlockWrite.sync[cont_receive_img_num]();
}
}
-// bool isNodeDescValid(DelugeNodeDesc* tmpNodeDesc)
-// {
-// return (tmpNodeDesc->crc == crc16(tmpNodeDesc, 4 + sizeof(object_id_t) + 1));
-// }
-
bool isObjDescValid(DelugeObjDesc* tmpObjDesc)
{
return (tmpObjDesc->crc == call Crc.crc16(tmpObjDesc, sizeof(object_id_t) + sizeof(page_num_t))
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;
- //pMsg->type = (imagesLoaded) ? DELUGE_ADV_NORMAL : DELUGE_ADV_ERROR;
pMsg->type = DELUGE_ADV_NORMAL;
-
- // make sure node desc is valid
-// if (!isNodeDescValid(&nodeDesc)) {
-// memset(&nodeDesc, 0xff, sizeof(nodeDesc));
-// }
-// memcpy(&pMsg->nodeDesc, &nodeDesc, sizeof(DelugeNodeDesc));
-
- // make sure obj desc is valid
-// if (!isObjDescValid(&curObjDesc)) {
-// //curObjDesc.objid = objid;
-// }
+
memcpy(&(pMsg->objDesc), &curObjDesc, sizeof(DelugeObjDesc));
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();
isBusy_pMsgBuf = TRUE;
}
state = S_INITIALIZING_PUB;
curObjDesc.objid = new_objid;
- curObjDesc.numPgs = ((new_size - 1) / DELUGE_BYTES_PER_PAGE) + 1; // Number of pages to transmit
+ curObjDesc.numPgs = ((new_size - 1) / DELUGET2_BYTES_PER_PAGE) + 1; // Number of pages to transmit
curObjDesc.numPgsComplete = curObjDesc.numPgs; // Publisher doesn't really care about this
curObjDesc.crc = call Crc.crc16(&curObjDesc, sizeof(object_id_t) + sizeof(page_num_t));
void cont_receive() {
state = S_INITIALIZING_RECV;
curObjDesc.objid = cont_receive_new_objid;
- curObjDesc.numPgs = ((cont_receive_new_size - 1) / DELUGE_BYTES_PER_PAGE) + 1; // Number of pages to receive
+ curObjDesc.numPgs = ((cont_receive_new_size - 1) / DELUGET2_BYTES_PER_PAGE) + 1; // Number of pages to receive
curObjDesc.numPgsComplete = 0;
curObjDesc.crc = call Crc.crc16(&curObjDesc, sizeof(object_id_t) + sizeof(page_num_t));
event void DelugePageTransfer.receivedPage(object_id_t new_objid, page_num_t new_pgNum)
{
+// printf("R: %08lx %d\n", new_objid, new_pgNum);
if (new_objid == curObjDesc.objid && new_pgNum == curObjDesc.numPgsComplete) {
curObjDesc.numPgsComplete++;
curObjDesc.crc = call Crc.crc16(&curObjDesc, sizeof(object_id_t) + sizeof(page_num_t));
} else {
call DelugePageTransfer.setWorkingPage(curObjDesc.objid, curObjDesc.numPgsComplete);
state = S_SYNC;
- call ObjectTransfer.stop();
- call BlockWrite.sync[cont_receive_img_num]();
+ if (call BlockWrite.sync[cont_receive_img_num]() != SUCCESS) {
+ post signalObjRecvDone();
+ }
}
}
}
return msg;
}
- if (rxAdvMsg->version != DELUGE_VERSION
- //|| !isNodeDescValid(&rxAdvMsg->nodeDesc)
- || state != S_STARTED) {
+ if (rxAdvMsg->version != DELUGE_VERSION || state != S_STARTED) {
return msg;
}