Main Page   Compound List   File List   Compound Members   File Members  

osc.c

Go to the documentation of this file.
00001 //  osc.c
00002 //
00003 //  Open Sound Control message sending fn's for avrmini
00004 //  
00005 //  Scott Wilson
00006 //  July 21, 2002
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 //      debug(PSTR("OSC init ok packet"));
00027 }
00028 
00029 
00030 // call oscInit() and uartInit() before using this function
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         // send the packet
00071         if (OSC_isBufferDone(&oscbuf)) {
00072                 // begin packet sync byte
00073                 uartSendByte((u08)0xbe);
00074 
00075                 // send length byte
00076                 uartSendByte((u08)(OSC_BUFFER_LEN - OSC_freeSpaceInBuffer(&oscbuf)));
00077 
00078                 oscDataPtr = OSC_getPacket(&oscbuf);
00079                 oscPacketSize = OSC_packetSize(&oscbuf);
00080 //                      debug(PSTR("packet size: %x"),(unsigned int)oscPacketSize);
00081                 for (j=0; j<oscPacketSize; j++)  {
00082                         data = *(oscDataPtr+j);
00083                         checksum += data;
00084                         uartSendByte(data);
00085                 }
00086                 // send checksum byte
00087                 uartSendByte(checksum);
00088                 OSC_resetBuffer(&oscbuf);
00089         } else {
00090                 debug(PSTR("Error creating OSC packet"));
00091         }
00092 }
00093 
00094 
00095 
00096 

Generated at Fri Oct 25 15:36:38 2002 for avrlib by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001