00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <progmem.h>
00010 #include <stdarg.h>
00011 #include "OSC-client.h"
00012 #include "osc.h"
00013 #include "debug.h"
00014 #include "uart.h"
00015
00016 #define OSC_BUFFER_LEN 40
00017
00018 void _oscSendPacket();
00019
00020 u08 oscDataBuffer[OSC_BUFFER_LEN];
00021 OSCbuf oscbuf;
00022
00023 void oscInit() {
00024 uartInit();
00025 OSC_initBuffer(&oscbuf, OSC_BUFFER_LEN, oscDataBuffer);
00026
00027 }
00028
00029
00030
00031 void oscSendMessage(const char PROGMEM *address) {
00032 OSC_writeAddress(&oscbuf, address);
00033
00034 _oscSendPacket();
00035 }
00036
00037 void oscSendMessageInt(const char PROGMEM *address, s32 arg) {
00038 OSC_writeAddress(&oscbuf, address);
00039
00040 OSC_writeIntArg(&oscbuf, arg);
00041
00042 _oscSendPacket();
00043 }
00044
00045 void oscSendMessageIntInt(const char PROGMEM *address, s32 arg, s32 arg2) {
00046 OSC_writeAddress(&oscbuf, address);
00047
00048 OSC_writeIntArg(&oscbuf, arg);
00049 OSC_writeIntArg(&oscbuf, arg2);
00050
00051 _oscSendPacket();
00052 }
00053
00054 void oscSendMessageString(const char PROGMEM *address, const char PROGMEM *arg) {
00055 OSC_writeAddress(&oscbuf, address);
00056
00057 OSC_writeStringArg(&oscbuf, arg);
00058
00059 _oscSendPacket();
00060 }
00061
00062
00063 void _oscSendPacket() {
00064 u08 j;
00065 u08 *oscDataPtr;
00066 u08 oscPacketSize;
00067 register u08 checksum=0;
00068 register u08 data;
00069
00070
00071 if (OSC_isBufferDone(&oscbuf)) {
00072
00073 uartSendByte((u08)0xbe);
00074
00075
00076 uartSendByte((u08)(OSC_BUFFER_LEN - OSC_freeSpaceInBuffer(&oscbuf)));
00077
00078 oscDataPtr = OSC_getPacket(&oscbuf);
00079 oscPacketSize = OSC_packetSize(&oscbuf);
00080
00081 for (j=0; j<oscPacketSize; j++) {
00082 data = *(oscDataPtr+j);
00083 checksum += data;
00084 uartSendByte(data);
00085 }
00086
00087 uartSendByte(checksum);
00088 OSC_resetBuffer(&oscbuf);
00089 } else {
00090 debug(PSTR("Error creating OSC packet"));
00091 }
00092 }
00093
00094
00095
00096