#include <SPI.h>
#include <Ethernet.h>


#include <ArdOSC.h>

byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte myIp[]  = { 10, 0, 1, 32 };
int  serverPort  = 10000;

int destPort=12000;

char OSCUp[]="/Secondary/Up";
char OSCDown[]="/Secondary/Down";


OSCServer server;
OSCClient client;


void setup(){ 
  
Serial.begin(19200);
 
 Ethernet.begin(myMac ,myIp); 
 
 server.begin(serverPort);
 
 //set callback function
 server.addCallback(OSCUp,&func1);
//  server.addCallback(OSCDown,&func2);
}
  
void loop(){
  if(server.aviableCheck()>0){
//    Serial.println("alive! "); 
  }
}


void func1(OSCMessage *_mes){
  
  //get source ip address
  byte *sourceIp = _mes->getIpAddress();

  //get 1st argument(int32)
  int tmpI=_mes->getArgInt32(2
  );
  
  //get 2nd argument(float)
  float tmpF=_mes->getArgFloat(1);
  
  
  //get 3rd argument(string)
  
  int strSize=_mes->getArgStringSize(1);
  char tmpStr[strSize]; //string memory allocation
  _mes->getArgString(2,tmpStr); 


  Serial.println("Up");
  delay(50);
//  Serial.println(tmpStr);
//  delay(50);
  Serial.println(tmpI);
  delay(50);
  Serial.println(tmpF);
  delay(50);

}
/*
void func2(OSCMessage *_mes){
  
  //get source ip address
  byte *sourceIp = _mes->getIpAddress();

  //get 1st argument(int32)
  int tmpI=_mes->getArgInt32(1);
  
  //get 2nd argument(float)
  float tmpF=_mes->getArgFloat(1);
  
  
  //get 3rd argument(string)
  int strSize=_mes->getArgStringSize(1);
  char tmpStr[strSize]; //string memory allocation
  _mes->getArgString(2,tmpStr); 


 Serial.println("Down");
  delay(50);
  Serial.println(tmpStr);
  delay(50);
  Serial.println(tmpI);
  delay(50);
  Serial.println(tmpF);
  delay(50);

}
*/
