I All,
Trying to build an OSC controller for software called Qlab, and I’m just in the concept proving phase.
So far I’ve managed to send and receive data to and from Qlab, but in trying to set up serial char commands I get stuck as soon as I declare a second char read case.
Code attached:
//OSC for Qlab Test.
//Sending Workspace methods and checking for replies
#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
#include <OSCBundle.h>
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
#define SER_BUFFER_SIZE 20
char serialBuffer[SER_BUFFER_SIZE];
uint8_t serialBufferPointer = 255;
bool loadSerialCommand() { // Call in loop() to check for commands
if (serialBufferPointer==255) { // Initialization
serialBuffer[0]=0; // Null-terminate empty buffer
serialBufferPointer = 0;
}
if (Serial.available()) { // A line of characters has been sent from the serial monitor - no <lf> termination! Just waiting...
serialBufferPointer=0; // so, we can start over again filling the buffer
delay(10); // Wait for all characters to arrive.
while(Serial.available()) {
char c = Serial.read();
if (serialBufferPointer < SER_BUFFER_SIZE-1) { // one byte for null termination reserved
serialBuffer[serialBufferPointer] = c;
serialBuffer[serialBufferPointer+1] = 0;
serialBufferPointer++;
}
else {
Serial.println(F("ERROR: Buffer overflow."));
}
}
//Serial << F("SERIAL COMMAND: ") << serialBuffer << F("\n");
return true;
}
return false;
}
// you can find this written on the board of some Arduino Ethernets or shields
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// NOTE: Alternatively, you can assign a fixed IP to configure your
// Ethernet shield.
byte ip[] = { 192, 168, 1, 177 };
IPAddress outIp(192, 168, 1, 1);
int serverPort = 53001; //TouchOSC (incoming port)
int destPort = 53000; //TouchOSC (outgoing port)
int ledPin = 13; //pin 13 on Arduino Uno. Pin 6 on a Teensy++2
int ledState = LOW;
//Create UDP message object
EthernetUDP Udp;
void setup(){
Serial.begin(115200);
Serial.println("OSC test");
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// print your local IP address:
Serial.print("Arduino IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
Udp.begin(serverPort);
Serial.print("Remote IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(outIp[thisByte], DEC);
Serial.print(".");
Udp.begin(destPort);
OSCMessage msgOUT("/workspace/test/connect");
Udp.beginPacket(outIp, destPort);
msgOUT.send(Udp); // send the bytes
Udp.endPacket(); // mark the end of the OSC Packet
delay(20);
msgOUT.send(Serial);
Serial.println();
msgOUT.empty(); // free space occupied by message
}
}
void loop(){
if (loadSerialCommand()) {
switch((char)serialBuffer[0]) {
case 't':
Udp.begin(destPort);
OSCMessage msgOUT("/workspace/test/thump");
Udp.beginPacket(outIp, destPort);
msgOUT.send(Udp); // send the bytes
Udp.endPacket(); // mark the end of the OSC Packet
delay(20);
msgOUT.send(Serial);
Serial.println();
msgOUT.empty(); // free space occupied by message
break;
case 'z':
break;
}
}
//process received messages
OSCMessage msgIN;
int size;
if((size = Udp.parsePacket())>0){
while(size--)
//Serial.println(Udp.read());
msgIN.fill(Udp.read());
if(!msgIN.hasError()){
Serial.println("Reply:");
msgIN.send(Serial);
Serial.println();
}
else{
Serial.println("I got something but it wasn't OSC");
}
}
}
Here are the errors I get:
Arduino: 1.6.9 (Mac OS X), Board: “Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)”
/Users/hlk/Documents/Arduino/osc_test_1/osc_test_1.ino: In function ‘void loop()’:
osc_test_1:111: error: jump to case label [-fpermissive]
case ‘z’:
^
osc_test_1:102: error: crosses initialization of ‘OSCMessage msgOUT’
OSCMessage msgOUT("/workspace/test/thump");
^
exit status 1
jump to case label [-fpermissive]
This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.
I’m very new to programming any help is greatly appreciated. :o
Thanks
Henri