I'm doing some programming of a Nanode board (not far removed from Arduino) which has an ethernet interface based on the ENC28J60.
I'm only modifying the existing software rather than building from scratch but would like to tidy things as much as possible.
The ethernet initialisation etc. is standard library code so is cast in stone as it were but I'm puzzling over the higher level ethernet message handling stuff a bit.
The system basically handles incoming requests sent over the ethernet interface and replies with instrument data, this part of the code is pretty straightforward.
However the loop that waits for ethernet packets and deals with them seems a bit odd to me, in psuedo-code it's something like:-
while (not reset) { get a packet from ethernet
handle DHCP message
handle message requesting local display on LCD
handle ARP request
handle DNS request
handle NTP request
if (still something left) { if (ping) { respond to ping } if (UDP message for us) { handle our message } } }
What I'm not clear about is whether one packet can only be one of the above things. Hence, if a DHCP request of some sort has been received and handled can the *same* packet contain other requests? If not then why is the code going through all the other calls?
OK, it makes for simpler looking code, no conditionals and/or switch/case but it somehow seems wrong (and a bit inefficient as each handle function gets called even if the packet has already been handled).
Does "get a packet from ethernet" only ever return one packet at a time or an array of them? Does seem a little odd to me that there is no conditional statements around the "handle X request" maybe in the other function call it returns very quickly if its not the right type of packet?
Thanks, Dennis
On Sun, May 27, 2012 at 11:22 AM, Chris Green cl@isbd.net wrote:
I'm doing some programming of a Nanode board (not far removed from Arduino) which has an ethernet interface based on the ENC28J60.
I'm only modifying the existing software rather than building from scratch but would like to tidy things as much as possible.
The ethernet initialisation etc. is standard library code so is cast in stone as it were but I'm puzzling over the higher level ethernet message handling stuff a bit.
The system basically handles incoming requests sent over the ethernet interface and replies with instrument data, this part of the code is pretty straightforward.
However the loop that waits for ethernet packets and deals with them seems a bit odd to me, in psuedo-code it's something like:-
while (not reset) { get a packet from ethernet
handle DHCP message
handle message requesting local display on LCD
handle ARP request
handle DNS request
handle NTP request
if (still something left) { if (ping) { respond to ping } if (UDP message for us) { handle our message } } }
What I'm not clear about is whether one packet can only be one of the above things. Hence, if a DHCP request of some sort has been received and handled can the *same* packet contain other requests? If not then why is the code going through all the other calls?
OK, it makes for simpler looking code, no conditionals and/or switch/case but it somehow seems wrong (and a bit inefficient as each handle function gets called even if the packet has already been handled).
-- Chris Green
main@lists.alug.org.uk http://www.alug.org.uk/ http://lists.alug.org.uk/mailman/listinfo/main Unsubscribe? See message headers or the web site above!