12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include <Ethernet.h>
- #include <EthernetUdp.h>
- #include <SPI.h>
- #include <OSCBundle.h>
- EthernetUDP Udp;
- IPAddress ip(128, 32, 122, 252);
- const unsigned int inPort = 8888;
- const unsigned int outPort = 9999;
- #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)
- static byte mac[6];
- void read(uint8_t word, uint8_t *mac, uint8_t offset) {
- FTFL_FCCOB0 = 0x41;
- FTFL_FCCOB1 = word;
-
-
- FTFL_FSTAT = FTFL_FSTAT_CCIF;
- while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF));
-
- *(mac+offset) = FTFL_FCCOB5;
- *(mac+offset+1) = FTFL_FCCOB6;
- *(mac+offset+2) = FTFL_FCCOB7;
- }
- void read_mac() {
- read(0xe,mac,0);
- read(0xf,mac,3);
- }
- #else
- void read_mac() {}
- byte mac[] = {
- 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- #endif
- void setup() {
- Ethernet.begin(mac,ip);
- Udp.begin(inPort);
- }
- void loop(){
- OSCBundle bndl;
- int size;
-
-
- if( (size = Udp.parsePacket())>0)
- {
- while(size--)
- bndl.fill(Udp.read());
- if(!bndl.hasError())
- {
-
- if(bndl.size() > 0)
- {
- static int32_t sequencenumber=0;
-
- bndl.add("/micros").add((int32_t)micros());
- bndl.add("/sequencenumber").add(sequencenumber++);
- Udp.beginPacket(Udp.remoteIP(), outPort);
- bndl.send(Udp);
- Udp.endPacket();
- }
- }
- }
- }
|