|
|
| | | |
| This function is called by the Rime code before a packet is to be sent by a device driver. This assures that the entire packet is consecutive in memory. | | This function is called by the Rime code before a packet is to be sent by a device driver. This assures that the entire packet is consecutive in memory. |
− | | + | '''Note that, this code assumes the lengths and other variables to be set properly.''' |
| The source code of this function is as follows. | | The source code of this function is as follows. |
| <source lang="c"> | | <source lang="c"> |
|
|
| </source> | | </source> |
| | | |
| + | Here is an example illustrating the above mentioned concept. |
| | | |
| + | [[File:Packetbuf_compact2.jpg|500px|center]] |
| | | |
| If the data is not external, but the data is not compactly stored, this function makes it compact. If bufptr > 0, then there is a gap or offset between the actual beginning location of the data section and the supposed beginning location of the data section i.e the location with id = PACKETBUF_HDR_SIZE. This function shift the data to the supposed location within the buffer. The following code does that. | | If the data is not external, but the data is not compactly stored, this function makes it compact. If bufptr > 0, then there is a gap or offset between the actual beginning location of the data section and the supposed beginning location of the data section i.e the location with id = PACKETBUF_HDR_SIZE. This function shift the data to the supposed location within the buffer. The following code does that. |
|
|
| The external buffer to which the packetbuf is to be copied must be able to accomodate at least PACKETBUF_HDR_SIZE bytes. The number of bytes that was copied to the external buffer is returned. | | The external buffer to which the packetbuf is to be copied must be able to accomodate at least PACKETBUF_HDR_SIZE bytes. The number of bytes that was copied to the external buffer is returned. |
| | | |
| + | The source code this function is as follows. |
| <source lang="c"> | | <source lang="c"> |
| { | | { |
|
|
| } | | } |
| #endif /* DEBUG_LEVEL */ | | #endif /* DEBUG_LEVEL */ |
− | memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr); | + | memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr);//packetbuf points to the beginning of the buffer array. |
| return PACKETBUF_HDR_SIZE - hdrptr; | | return PACKETBUF_HDR_SIZE - hdrptr; |
| } | | } |
|
|
| | | |
| | | |
− | In the above potion of code, the main line is the follwing | + | In the above potion of code, the main line is the following |
| memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr); | | memcpy(to, packetbuf + hdrptr, PACKETBUF_HDR_SIZE - hdrptr); |
Exception encountered, of type "Error"