From 231a022bb636d2cb3c33a417e46218637b0e8733 Mon Sep 17 00:00:00 2001 From: Bjoern Hartmann Date: Sun, 28 Dec 2008 23:58:00 -0800 Subject: [PATCH] added rcv of UDP packets on Arduino; Udp library; updated PD example --HG-- rename : arduino_osc.pde => arduino_osc_serial.pde --- README.txt | 6 +- arduino_osc.pde => arduino_osc_serial.pde | 0 arduino_osc_udp.pde | 234 +++++++++++++++++-- arduino_osc_udp_send.pde | 261 ++++++++++++++++++++++ examples/pd/arduino_osc_udp.pd | 19 +- examples/pd/arduino_osc_udp_widgets.pd | 240 ++++++++++++++++++++ libraries/Ethernet/SendUdp.cpp | 6 +- libraries/Ethernet/SendUdp.h | 4 +- libraries/Ethernet/Udp.cpp | 49 ++++ libraries/Ethernet/Udp.h | 29 +++ 10 files changed, 814 insertions(+), 34 deletions(-) rename arduino_osc.pde => arduino_osc_serial.pde (100%) create mode 100644 arduino_osc_udp_send.pde create mode 100644 examples/pd/arduino_osc_udp_widgets.pd create mode 100644 libraries/Ethernet/Udp.cpp create mode 100644 libraries/Ethernet/Udp.h diff --git a/README.txt b/README.txt index a21ee39..e5a80f0 100644 --- a/README.txt +++ b/README.txt @@ -1,5 +1,5 @@ -arduino_osc.pde: send and receive OSC messages over the Arduino's Serial port. +arduino_osc_serial.pde: send and receive OSC messages over the Arduino's Serial port. -arduino_osc_udp.pde: send OSC messages over UDP using the Arduino Ethernet Shield. -To compile this file, copy the SendUdp library in /libraries/Ethernet/ into your arduino/hardware/libraries/Ethernet directory. +arduino_osc_udp.pde: send & receive OSC messages over UDP using the Arduino Ethernet Shield. +To compile this file, copy the Udp library in /libraries/Ethernet/ into your arduino/hardware/libraries/Ethernet directory. diff --git a/arduino_osc.pde b/arduino_osc_serial.pde similarity index 100% rename from arduino_osc.pde rename to arduino_osc_serial.pde diff --git a/arduino_osc_udp.pde b/arduino_osc_udp.pde index 50b4ec6..976e7b3 100644 --- a/arduino_osc_udp.pde +++ b/arduino_osc_udp.pde @@ -1,22 +1,23 @@ #include -#include +#include /************************************************************** * ARDUINO_OSC_UDP 0001 * based on ARDUINO_OSC 0005 * - * Firmware to send OSC messages from an Arduino board to a PC - * over UDP using the Ethernet Shield. + * Firmware to send and receive OSC messages from an Arduino board to a PC + * over UDP using the Arduino Shield. * * Right now, only messages with a single integer argument - * are supported, and only sending is supported. + * are supported. * * Uses the standard OSC packet format (no serial wrapping) * * PROTOCOL DETAILS * Digital pins 0..9 and analog inputs 0..5 are supported. - * No output yet. + * Digital pins 8 and 9 are still screwey. + * * Below, the notation [0..9] means: any number from 0 to 9. * The notation [0|1] means: either 0 or 1. * Pin numbers are always part of the OSC address. @@ -42,11 +43,11 @@ * (change variable reportAnalog to 0xFF to enable by default) * * NOTES: - * - Pins 10-13 cannot be used + * - Pins 10-13 cannot be used (needed for SPI communication with ethernet shield) * - Resolution on analog in and out is 8 bit. * * MIT License: - * Copyright (c) 2008 Bjoern Hartmann, Stanford HCI Group + * Copyright (c) 2008 Bjoern Hartmann * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -70,8 +71,8 @@ #define VERSION 1 -#define MIN_A2D_DIFF 4 // threshold for reporting a2d changes -#define MAX_LENGTH 24 // size of buffer for building OSC msgs + +#define MAX_LENGTH 32 // size of buffer for OSC msgs (in and out) #define FIRST_DIGITAL_PIN 0 @@ -83,12 +84,24 @@ #define NUM_ANALOG_PINS 6 +/* ETHERNET CONFIGURATION *************************************/ +/* ARDUINO: set MAC, IP address of Ethernet shield and its gateway */ +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC address to use +byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address +byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address + +/* TARGET: set this to IP/Port of computer that will receive + * UDP messages from Arduino */ +byte targetIp[] = {192,168,11,15}; +int targetPort = 8000; +/***************************************************************/ + + int k = FIRST_ANALOG_PIN; int inputBuffer = 0xFFFF; // holds previous values of PORTB and PORTD (pins 0..7); start all high because of pull-ups int a2dBuffer[6] = {0x00}; // holds previous A2D conversion values char oscBuffer[MAX_LENGTH]={0x00}; // holds outgoing OSC message - unsigned int pinDir = 0x0000; //buffer that saves pin directions 0=input; 1=output; default: all in char prefixReport[] = "/report/"; @@ -100,17 +113,15 @@ char prefixA2d[]="/adc/"; char prefixReset[]="/reset"; //TODO: implement char oscOutAddress[10]={0x00}; //string that holds outgoing osc message address - char* numbers[] = {"0","1","2","3","4","5","6","7","8","9","10","11","12"}; -/* CONFIGURE ETHERNET INTERFACE HERE */ -byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC address to use -byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address -byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address -/* TARGET FOR UDP MESSAGES */ -byte targetIp[] = {192,168,11,15}; -int targetPort = 8000; + +/* Buffers for received messages */ +byte rcvIp[4]; //source ip from which last packet originated +int rcvPort; // source port from which last packet originated +byte rcvBuffer[MAX_LENGTH]; //messagebuf for incoming packet + // which values should be reported? configured in setup() byte reportAnalog; //bitmask - 0=off, 1=on - default:all off @@ -121,22 +132,30 @@ int a2dReportFrequency = 10; //report frequency for analog data in ms unsigned long currentMillis=1; unsigned long nextExecuteTime=0; // for comparison with timer0_overflow_count +byte oscRxMsgSize; // size of incoming msg +byte oscRxReadBytes; //number of bytes read + +unsigned long oscRxIntArg1; //int argument of incoming osc message + /*********************************************** * SETUP - open serial comm and initialize pins ***********************************************/ void setup() { int i; - reportAnalog=0x01; + + reportAnalog=0x00; reportDigital=true; - // set pins 0..9 as inputs + // set all digital pins as inputs for(i=FIRST_DIGITAL_PIN; i<=LAST_DIGITAL_PIN; i++) { pinMode(i,INPUT); digitalWrite(i,HIGH); // use pull-ups } + Ethernet.begin(mac,ip,gw); Udp.begin(targetIp,targetPort); + //DEBUG: Serial.begin(9600); } /*********************************************** @@ -159,6 +178,17 @@ void loop() { } } } + + //if there's data available, read a packet + if(Udp.available()) { + oscRxMsgSize = Udp.readPacket(rcvBuffer,MAX_LENGTH,rcvIp,(uint16_t *)&rcvPort); + if(oscRxMsgSize <= MAX_LENGTH) { + oscHandleRxPacket(); + } else { + //PANIC - we've already clobbered mem past our buffer boundary + //reset? + } + } } /*********************************************** @@ -256,6 +286,168 @@ void oscSendMessageInt(char * address, unsigned long value){ //send message as one packet for(i=0;i=FIRST_DIGITAL_PIN && outPin<=LAST_DIGITAL_PIN) { //sanity check + digitalWrite(outPin,(byte)(value & 0x01)); + } + return; + } + + // check if this is a pwm message, i.e., starts with "/pwm/" + if(strncmp(msg,prefixPwm,strlen(prefixPwm))==0) { + outPin = atoi(msg+strlen(prefixPwm)); + if(outPin>=FIRST_DIGITAL_PIN && outPin<=LAST_DIGITAL_PIN) { //sanity check + pinDir = pinDir | (1<=FIRST_ANALOG_PIN && outPin<=LAST_ANALOG_PIN) { //sanity check + if(value==0) { + reportAnalog = reportAnalog & ~(1<=FIRST_DIGITAL_PIN && outPin<=LAST_DIGITAL_PIN) { //sanity check + if(value==0) { + pinDir = pinDir & ~(1< +#include + + +/************************************************************** + * ARDUINO_OSC_UDP 0001 + * based on ARDUINO_OSC 0005 + * + * Firmware to send OSC messages from an Arduino board to a PC + * over UDP using the Ethernet Shield. + * + * Right now, only messages with a single integer argument + * are supported, and only sending is supported. + * + * Uses the standard OSC packet format (no serial wrapping) + * + * PROTOCOL DETAILS + * Digital pins 0..9 and analog inputs 0..5 are supported. + * No output yet. + * Below, the notation [0..9] means: any number from 0 to 9. + * The notation [0|1] means: either 0 or 1. + * Pin numbers are always part of the OSC address. + * The single integer argument for each OSC message + * represents either HIGH/LOW, or an 8bit analog value. + * + * + * ARDUINO->PC PROTOCOL + * /in/[0..9] [0|1] - a digital input pin changed to [high|low] + * /adc/[0..5] [0..255] - analog input value changed to [0..255] + * NOTE: input pins use pull-up resistors and are HIGH by default. + * Therefore, 0 means HIGH, 1 means LOW (pulled to ground). + * + * + * EXAMPLES: ARDUINO->PC + * /in/4 1 - digital input pin 4 pulled to ground + * /adc/2 128 - analog input pin2 read 128 (=2.5V) + * + * DEFAULT STARTUP CONFIGURATION + * - Pins 0..9 are all set to input, digital reporting enabled + * (change variable reportDigital to False to disable by default) + * - Analog reporting is disabled + * (change variable reportAnalog to 0xFF to enable by default) + * + * NOTES: + * - Pins 10-13 cannot be used + * - Resolution on analog in and out is 8 bit. + * + * MIT License: + * Copyright (c) 2008 Bjoern Hartmann, Stanford HCI Group + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * bjoern@cs.stanford.edu 12/28/2008 + **************************************************************/ + +#define VERSION 1 + +#define MIN_A2D_DIFF 4 // threshold for reporting a2d changes +#define MAX_LENGTH 24 // size of buffer for building OSC msgs + + +#define FIRST_DIGITAL_PIN 0 +#define LAST_DIGITAL_PIN 9 +#define NUM_DIGITAL_PINS 10 + +#define FIRST_ANALOG_PIN 0 +#define LAST_ANALOG_PIN 5 +#define NUM_ANALOG_PINS 6 + + +int k = FIRST_ANALOG_PIN; + +int inputBuffer = 0xFFFF; // holds previous values of PORTB and PORTD (pins 0..7); start all high because of pull-ups +int a2dBuffer[6] = {0x00}; // holds previous A2D conversion values +char oscBuffer[MAX_LENGTH]={0x00}; // holds outgoing OSC message + +unsigned int pinDir = 0x0000; //buffer that saves pin directions 0=input; 1=output; default: all in + +char prefixReport[] = "/report/"; +char prefixPinmode[] = "/pinmode/"; +char prefixOut[] = "/out/"; +char prefixPwm[] = "/pwm/"; +char prefixIn[]="/in/"; +char prefixA2d[]="/adc/"; +char prefixReset[]="/reset"; //TODO: implement + +char oscOutAddress[10]={0x00}; //string that holds outgoing osc message address + +char* numbers[] = {"0","1","2","3","4","5","6","7","8","9","10","11","12"}; + +/* CONFIGURE ETHERNET INTERFACE HERE */ +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //MAC address to use +byte ip[] = { 192, 168, 11, 200 }; // Arduino's IP address +byte gw[] = { 192, 168, 11, 1 }; // Gateway IP address + +/* TARGET FOR UDP MESSAGES */ +byte targetIp[] = {192,168,11,15}; +int targetPort = 8000; + +// which values should be reported? configured in setup() +byte reportAnalog; //bitmask - 0=off, 1=on - default:all off +boolean reportDigital; //no per-pin reporting for analog + +/* timer variables */ +int a2dReportFrequency = 10; //report frequency for analog data in ms +unsigned long currentMillis=1; +unsigned long nextExecuteTime=0; // for comparison with timer0_overflow_count + + +/*********************************************** + * SETUP - open serial comm and initialize pins + ***********************************************/ +void setup() { + int i; + reportAnalog=0x01; + reportDigital=true; + + // set pins 0..9 as inputs + for(i=FIRST_DIGITAL_PIN; i<=LAST_DIGITAL_PIN; i++) { + pinMode(i,INPUT); + digitalWrite(i,HIGH); // use pull-ups + } + Ethernet.begin(mac,ip,gw); + SendUdp.begin(targetIp,targetPort); +} + +/*********************************************** + * LOOP - poll pin values and read incoming + * serial communication + ***********************************************/ +void loop() { + + // check all digital inputs + if(reportDigital) { + checkDiscreteInputs(); + } + // check analog inputs every 10ms + currentMillis = millis(); + if(currentMillis > nextExecuteTime) { + nextExecuteTime = currentMillis + (a2dReportFrequency -1); // run this every 10ms (arbitrary?) + for(k=0;k> 2; //only use 8 MSBs + + // compare to last reading - if delta big enough, + // send message + //diff = result - a2dBuffer[channel]; + //if(diff>MIN_A2D_DIFF || diff<(int)((-1)*MIN_A2D_DIFF)) { + if(result!=a2dBuffer[channel]) { + a2dBuffer[channel]=result; + strcpy(oscOutAddress,prefixA2d); + strcat(oscOutAddress,numbers[channel]); + oscSendMessageInt(oscOutAddress, result); + } +} + + +/*********************************************** + * Send an OSC message with the passed in + * address and a single integer argument + ***********************************************/ +void oscSendMessageInt(char * address, unsigned long value){ + byte offset=0; + byte i=0; + + // clear buffer + for(i=0; iPD:; +#X text 99 -47 Digital input: /in/[2..12] [0|1] e.g. \, /in/4 1; +#X text 461 -59 Message format PD->Arduino; +#X text 460 -47 Set digital pin to input/output: /pinmode/[2..12] [0|1] +; +#X text 461 -22 Write digital output: /out/[2..12] [0|1]; +#X text 460 -35 Write PWM: /pwm/[3 \, 5 \, 6 \, 9 \, 10 \, 11] [0..255] +; +#X text 460 -9 Turn reporting for all digital pins on/off: /report/in +[0|1]; +#X text 461 5 Turn reporting for all analog pins on/off: /report/adc +[0|1]; +#X text 460 18 Turn reporting for one analog pin on/off: /report/adc/[0..5] +[0|1]; +#X text 99 -34 Analog input: /adc/[0..5] [0..255] e.g. \, /adc/4 193 +; +#X msg 449 290 send /out/2 \$1; +#X msg 450 313 send /out/3 \$1; +#X msg 451 336 send /out/4 \$1; +#X msg 569 289 send /report/adc/0 \$1; +#X msg 569 310 send /report/adc/1 \$1; +#X msg 569 329 send /report/adc/2 \$1; +#X msg 570 349 send /report/adc/3 \$1; +#X msg 569 370 send /report/adc/4 \$1; +#X msg 569 391 send /report/adc/5 \$1; +#X obj 267 537 s oscOut; +#X msg 215 303 send /report/adc \$1; +#X msg 216 276 send /report/in \$1; +#X msg 449 357 send /out/5 \$1; +#X msg 449 382 send /out/6 \$1; +#X msg 448 404 send /out/7 \$1; +#X msg 449 428 send /out/8 \$1; +#X msg 450 449 send /out/9 \$1; +#X msg 282 358 send /pwm/9 \$1; +#X obj 218 100 OSCroute /2 /3 /4 /5 /6 /7 /8 /9 /0 /1; +#X msg 452 474 send /out/0 \$1; +#X msg 449 496 send /out/1 \$1; +#X msg 88 452 send /pinmode/0 \$1; +#X msg 89 474 send /pinmode/1 \$1; +#X msg 92 275 send /pinmode/2 \$1; +#X msg 91 296 send /pinmode/3 \$1; +#X msg 91 318 send /pinmode/4 \$1; +#X msg 90 341 send /pinmode/5 \$1; +#X msg 91 366 send /pinmode/6 \$1; +#X msg 90 389 send /pinmode/7 \$1; +#X msg 89 409 send /pinmode/8 \$1; +#X msg 88 429 send /pinmode/9 \$1; +#X connect 1 0 95 0; +#X connect 1 1 8 0; +#X connect 1 2 22 0; +#X connect 8 0 3 0; +#X connect 8 1 7 0; +#X connect 8 2 2 0; +#X connect 8 3 4 0; +#X connect 8 4 5 0; +#X connect 8 5 6 0; +#X connect 20 0 88 0; +#X connect 21 0 87 0; +#X connect 21 0 48 0; +#X connect 23 0 20 0; +#X connect 24 0 23 0; +#X connect 25 0 100 0; +#X connect 28 0 101 0; +#X connect 29 0 102 0; +#X connect 30 0 103 0; +#X connect 31 0 104 0; +#X connect 32 0 105 0; +#X connect 33 0 106 0; +#X connect 34 0 107 0; +#X connect 35 0 98 0; +#X connect 36 0 99 0; +#X connect 38 0 77 0; +#X connect 39 0 78 0; +#X connect 40 0 79 0; +#X connect 41 0 89 0; +#X connect 42 0 90 0; +#X connect 43 0 91 0; +#X connect 44 0 92 0; +#X connect 45 0 93 0; +#X connect 46 0 96 0; +#X connect 47 0 97 0; +#X connect 48 0 49 0; +#X connect 48 0 54 0; +#X connect 48 0 50 0; +#X connect 48 0 51 0; +#X connect 48 0 52 0; +#X connect 48 0 53 0; +#X connect 49 0 81 0; +#X connect 50 0 82 0; +#X connect 51 0 83 0; +#X connect 52 0 84 0; +#X connect 53 0 85 0; +#X connect 54 0 80 0; +#X connect 55 0 56 0; +#X connect 56 0 94 0; +#X connect 58 0 1 0; +#X connect 77 0 86 0; +#X connect 78 0 86 0; +#X connect 79 0 86 0; +#X connect 80 0 86 0; +#X connect 81 0 86 0; +#X connect 82 0 86 0; +#X connect 83 0 86 0; +#X connect 84 0 86 0; +#X connect 85 0 86 0; +#X connect 87 0 86 0; +#X connect 88 0 86 0; +#X connect 89 0 86 0; +#X connect 90 0 86 0; +#X connect 91 0 86 0; +#X connect 92 0 86 0; +#X connect 93 0 86 0; +#X connect 94 0 86 0; +#X connect 95 0 18 0; +#X connect 95 1 9 0; +#X connect 95 2 10 0; +#X connect 95 3 11 0; +#X connect 95 4 12 0; +#X connect 95 5 13 0; +#X connect 95 6 14 0; +#X connect 95 7 15 0; +#X connect 95 8 16 0; +#X connect 95 9 17 0; +#X connect 96 0 86 0; +#X connect 97 0 86 0; +#X connect 98 0 86 0; +#X connect 99 0 86 0; +#X connect 100 0 86 0; +#X connect 101 0 86 0; +#X connect 102 0 86 0; +#X connect 103 0 86 0; +#X connect 104 0 86 0; +#X connect 105 0 86 0; +#X connect 106 0 86 0; +#X connect 107 0 86 0; +#X coords 0 -1 1 1 640 240 2 100 100; diff --git a/libraries/Ethernet/SendUdp.cpp b/libraries/Ethernet/SendUdp.cpp index 4274dd7..4fa9d0d 100644 --- a/libraries/Ethernet/SendUdp.cpp +++ b/libraries/Ethernet/SendUdp.cpp @@ -15,15 +15,15 @@ extern "C" { #include "Ethernet.h" #include "SendUdp.h" -void SendUdp::begin(uint8_t *ip, uint16_t port) { +void SendUdpClass::begin(uint8_t *ip, uint16_t port) { _ip = ip; _port = port; _sock = 0; socket(_sock,Sn_MR_UDP,8888,0); } -uint16_t SendUdp::sendPacket(const uint8_t * buf, uint16_t len){ +uint16_t SendUdpClass::sendPacket(const uint8_t * buf, uint16_t len){ return sendto(_sock,buf,len,_ip,_port); } -SendUdp Udp; +SendUdpClass SendUdp; diff --git a/libraries/Ethernet/SendUdp.h b/libraries/Ethernet/SendUdp.h index 33f1e60..665c987 100644 --- a/libraries/Ethernet/SendUdp.h +++ b/libraries/Ethernet/SendUdp.h @@ -11,7 +11,7 @@ #include "Print.h" -class SendUdp { +class SendUdpClass { private: uint8_t _sock; uint8_t *_ip; @@ -21,6 +21,6 @@ class SendUdp { uint16_t sendPacket(const uint8_t *, uint16_t); }; -extern SendUdp Udp; +extern SendUdpClass SendUdp; #endif diff --git a/libraries/Ethernet/Udp.cpp b/libraries/Ethernet/Udp.cpp new file mode 100644 index 0000000..8c2f718 --- /dev/null +++ b/libraries/Ethernet/Udp.cpp @@ -0,0 +1,49 @@ +/* + * Udp.cpp + * + * + * Created by Bjoern Hartmann on 12/28/08. + * Copyright 2008 Stanford Computer Science. All rights reserved. + * + */ + +extern "C" { +#include "types.h" +#include "w5100.h" +#include "socket.h" +} + +#include "Ethernet.h" +#include "Udp.h" + +void UdpClass::begin(uint8_t *ip, uint16_t port) { + _ip = ip; + _port = port; + _sock = 0; + socket(_sock,Sn_MR_UDP,8888,0); +} + +uint16_t UdpClass::sendPacket(const uint8_t * buf, uint16_t len){ + return sendto(_sock,buf,len,_ip,_port); +} + +/* is data available in rx buffer? 0 if no, non-zero if yes */ +int UdpClass::available() { + return getSn_RX_RSR(_sock); +} + +/* + * read a received packet into buffer buf; store calling ip + */ +uint16_t UdpClass::readPacket(uint8_t * buf, uint16_t len, uint8_t *ip, uint16_t *port) { + return recvfrom(_sock,buf,len,ip,port); +} + +/* read a received packet, throw away peer's ip and port */ +uint16_t UdpClass::readPacket(uint8_t * buf, uint16_t len) { + uint8_t ip[4]; + uint16_t port[1]; + return recvfrom(_sock,buf,len,ip,port); +} + +UdpClass Udp; diff --git a/libraries/Ethernet/Udp.h b/libraries/Ethernet/Udp.h new file mode 100644 index 0000000..53d3605 --- /dev/null +++ b/libraries/Ethernet/Udp.h @@ -0,0 +1,29 @@ +/* + * Udp.h + * + * + * Created by Bjoern Hartmann on 12/28/08. + * Copyright 2008 Stanford Computer Science. All rights reserved. + * + */ + +#ifndef Udp_h +#define Udp_h + +class UdpClass { +private: + uint8_t _sock; // socket ID for Wiz5100 + uint8_t *_ip; // peer's IP address + uint16_t _port; // peer's port + +public: + void begin(uint8_t *, uint16_t); // initialize + uint16_t sendPacket(const uint8_t *, uint16_t); // send a packet + int available(); // has data been received? + uint16_t readPacket(uint8_t *, uint16_t); // read a received packet + uint16_t readPacket(uint8_t *, uint16_t, uint8_t *, uint16_t *); // read a received packet +}; + +extern UdpClass Udp; + +#endif