On Fri, Jun 26, 2009 at 7:08 AM, sofia aparicio<aparicioso...@hotmail.com> wrote: > > > Hello, > > I would like to know what do I need to do to send and receive a message > using the protocols of the Route library. Do I need to asociate every > TOS_Msg with a TOS_MHopMsg? In Surge example they do the following: > > if (pReading = (SurgeMsg *)call Send.getBuffer(&gMsgBuffer,&Len)) { > pReading->type = SURGE_TYPE_SENSORREADING; > pReading->parentaddr = call RouteControl.getParent(); > pReading->reading = gSensorData; > call Send.send(&gMsgBuffer,sizeof(SurgeMsg))); > } > > I have seen the code of these function but I do not understand what are they > doing. > > command void *Send.getBuffer[uint8_t id](TOS_MsgPtr pMsg, uint16_t* length) > { > TOS_MHopMsg *pMHMsg = (TOS_MHopMsg *)pMsg->data; > *length = TOSH_DATA_LENGTH - offsetof(TOS_MHopMsg,data); > return (&pMHMsg->data[0]); > }
getBuffer returns a pointer to an area in the packet buffer where you can put your application payload. > > command result_t Send.send[uint8_t id](TOS_MsgPtr pMsg, uint16_t > PayloadLen) { > uint16_t usMHLength = offsetof(TOS_MHopMsg,data) + PayloadLen; > if (usMHLength > TOSH_DATA_LENGTH) { > return FAIL; > } > //dbg(DBG_ROUTE,"MHop: send\n"); > call RouteSelect.initializeFields(pMsg,id); > if (call RouteSelect.selectRoute(pMsg,id) != SUCCESS) { > return FAIL; > } > //dbg(DBG_ROUTE,"MHop: out pkt 0x%x\n",((TOS_MHopMsg > *)pMsg->data)->seqno); > if (call SendMsg.send[id](pMsg->addr, usMHLength, pMsg) != SUCCESS) { > return FAIL; > } > return SUCCESS; > } When you call this function, the Route library takes the responsibility for sending the packet after making sure that the packet is not too big, etc. - om_p _______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help