We are together here. I see where you are going, but it may require more than meets the eye. How would you tell the devices apart before compile? You must select the correct Arduino board in the IDE before compile. It does not even do that automatically.
I thought maybe using a different ethernet library include file for each. I wouldn't want to include all the code for every ethernet device, just the one I am using.
All could include the same functions with the same parameters and return values as the current ethernet library.
Ethernet.begin()
server.available()
client.read()
client.println()
client.stop()
...and the like, don't you think?
I thought maybe using a different ethernet library include file for each. I wouldn't want to include all the code for every ethernet device, just the one I am using.
Code:
#include <Ethernet.h>
// or
#include <Ethernet5200.h>
// or
#include <Ethernet28J60.h>
// or
#include <Ethernet5200.h>
// or
#include <Ethernet28J60.h>
All could include the same functions with the same parameters and return values as the current ethernet library.
Ethernet.begin()
server.available()
client.read()
client.println()
client.stop()
...and the like, don't you think?
That's what I'm looking at too. Actually I found a nice solution where there is one common, device-independent Ethernet class which is never used directly but only as interface. The actual implementation is EthernetW5200 which could easily be replaced with other implementations. What I like about my solution is that there is absolutely no change needed in the library files. The 'include' in the Sketch decides about the implementation. What I don't like about this solution is the amount of work which has to be done before this'll work. TCP and UDP implementation are tightly coupled to the W5x00 module.
W5100 and W5200 are almost identical, so it's possible to do them in the same sourcecode files but I doubt it's the same with ENC28J60 and others. IMHO this is only a short-term solution.
I've already uploaded some stuff to github too. It's not much more than a proof-of-concept but it already shows that it's possible to include different header files to select an implementation. Here's what I did:
* Made EthernetClass an abstract class which'll be the only interface used by all protocol implementations.
* Changed EthernetW5200 class so it inherits methods from the EthernetClass
* The Sketch now has to include one implementation and assign it to the global variable 'Ethernet'
* All protocol implementations are unchanged but won't work until they are freed from the direct calls to W5x00.*
And finally the link: https://github.com/tht/ArduinoEthernetGeneric
I won't be able to spend much time on it for a few weeks but it's a start and shows a possible way to go.
