Control of mbed using OSC. Based on code from the Make Controller. Right now you can turn the onboard LEDs on/off and toggle 8 digital out pins. More I/O will be done in the future.

Dependencies:   mbed

Committer:
pehrhovey
Date:
Wed Mar 17 03:17:38 2010 +0000
Revision:
0:439354122597

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pehrhovey 0:439354122597 1 /*
pehrhovey 0:439354122597 2 * osc.h
pehrhovey 0:439354122597 3 *
pehrhovey 0:439354122597 4 * Created on: Mar 8, 2010
pehrhovey 0:439354122597 5 * Author: pehr
pehrhovey 0:439354122597 6 *
pehrhovey 0:439354122597 7 * The functions to receive, parse and delegate OSC commands
pehrhovey 0:439354122597 8 * Based on osc_cpp.h in Make Controller repository
pehrhovey 0:439354122597 9 * This code is trimmed down to be UDP-only, no USB (code never had TCP)
pehrhovey 0:439354122597 10 * http://makingthings.com
pehrhovey 0:439354122597 11 */
pehrhovey 0:439354122597 12 /*********************************************************************************
pehrhovey 0:439354122597 13
pehrhovey 0:439354122597 14 Copyright 2006-2009 MakingThings
pehrhovey 0:439354122597 15
pehrhovey 0:439354122597 16 Licensed under the Apache License,
pehrhovey 0:439354122597 17 Version 2.0 (the "License"); you may not use this file except in compliance
pehrhovey 0:439354122597 18 with the License. You may obtain a copy of the License at
pehrhovey 0:439354122597 19
pehrhovey 0:439354122597 20 http://www.apache.org/licenses/LICENSE-2.0
pehrhovey 0:439354122597 21
pehrhovey 0:439354122597 22 Unless required by applicable law or agreed to in writing, software distributed
pehrhovey 0:439354122597 23 under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
pehrhovey 0:439354122597 24 CONDITIONS OF ANY KIND, either express or implied. See the License for
pehrhovey 0:439354122597 25 the specific language governing permissions and limitations under the License.
pehrhovey 0:439354122597 26
pehrhovey 0:439354122597 27 *********************************************************************************/
pehrhovey 0:439354122597 28 #ifndef OSC_H_
pehrhovey 0:439354122597 29 #define OSC_H_
pehrhovey 0:439354122597 30
pehrhovey 0:439354122597 31 #include "ipv4/lwip/ip_addr.h"
pehrhovey 0:439354122597 32 #include "lwip/udp.h"
pehrhovey 0:439354122597 33
pehrhovey 0:439354122597 34 #ifndef UDP_BROADCAST_PORT
pehrhovey 0:439354122597 35 #define UDP_BROADCAST_PORT 5555
pehrhovey 0:439354122597 36 #endif
pehrhovey 0:439354122597 37
pehrhovey 0:439354122597 38 #include "error.h" //Make Controller error codes
pehrhovey 0:439354122597 39
pehrhovey 0:439354122597 40 #define OSC_SUBSYSTEM_COUNT 18
pehrhovey 0:439354122597 41
pehrhovey 0:439354122597 42 #define OSC_SCRATCH_SIZE 100
pehrhovey 0:439354122597 43
pehrhovey 0:439354122597 44 #define OSC_CHANNEL_COUNT 3
pehrhovey 0:439354122597 45 #define OSC_CHANNEL_UDP 0
pehrhovey 0:439354122597 46 #define OSC_CHANNEL_USB 1 //not implemented yet
pehrhovey 0:439354122597 47 #define OSC_CHANNEL_TCP 2 //not implemented yet
pehrhovey 0:439354122597 48
pehrhovey 0:439354122597 49
pehrhovey 0:439354122597 50 #define OSC_MAX_MESSAGE_IN 200
pehrhovey 0:439354122597 51 #define OSC_MAX_MESSAGE_OUT 600
pehrhovey 0:439354122597 52
pehrhovey 0:439354122597 53
pehrhovey 0:439354122597 54 typedef unsigned char uchar;
pehrhovey 0:439354122597 55
pehrhovey 0:439354122597 56 typedef struct OscChannel_
pehrhovey 0:439354122597 57 {
pehrhovey 0:439354122597 58 char buffer[ OSC_MAX_MESSAGE_OUT ];
pehrhovey 0:439354122597 59 char incoming[ OSC_MAX_MESSAGE_IN ];
pehrhovey 0:439354122597 60 char* bufferPointer;
pehrhovey 0:439354122597 61 int bufferRemaining;
pehrhovey 0:439354122597 62 int messages;
pehrhovey 0:439354122597 63 struct ip_addr * replyAddress; //where to send
pehrhovey 0:439354122597 64 int replyPort;
pehrhovey 0:439354122597 65 //A function pointer to the func used to send using this channel, set up in an init function
pehrhovey 0:439354122597 66 int (*sendMessage)( char* packet, int length, struct ip_addr * replyAddress, int replyPort );
pehrhovey 0:439354122597 67 int running;
pehrhovey 0:439354122597 68 }OscChannel;
pehrhovey 0:439354122597 69
pehrhovey 0:439354122597 70 // Top level functions
pehrhovey 0:439354122597 71 void Osc_SystemInit( struct udp_pcb * pcb );
pehrhovey 0:439354122597 72 void Osc_UdpInit( int channel, struct udp_pcb * pcb); //set up UDP channel
pehrhovey 0:439354122597 73
pehrhovey 0:439354122597 74 OscChannel * Osc_GetChannel(int channel); //get ptr to the channel struct
pehrhovey 0:439354122597 75
pehrhovey 0:439354122597 76 int Osc_CreateMessage( int channel, char* address, char* format, ... );
pehrhovey 0:439354122597 77 int Osc_CreateMessageToBuf( char* bp, int* length, char* address, char* format, ... );
pehrhovey 0:439354122597 78 int Osc_SendPacket( int channel );
pehrhovey 0:439354122597 79 int Osc_ReceivePacket( int channel, char* packet, int length );
pehrhovey 0:439354122597 80 int Osc_RegisterSubsystem( const char *name,
pehrhovey 0:439354122597 81 int (*Subsystem_ReceiveMessage)( int channel, char* buffer, int length ),
pehrhovey 0:439354122597 82 int (*Subsystem_Poll)( int channel ) );
pehrhovey 0:439354122597 83
pehrhovey 0:439354122597 84 // Helpers for processing messages - they return error codes as spec'ed above
pehrhovey 0:439354122597 85 int Osc_IntReceiverHelper( int channel, char* message, int length,
pehrhovey 0:439354122597 86 char* subsystemName,
pehrhovey 0:439354122597 87 int (*propertySet)( int property, int value ),
pehrhovey 0:439354122597 88 int (*propertyGet)( int property ),
pehrhovey 0:439354122597 89 char* propertyNames[] );
pehrhovey 0:439354122597 90
pehrhovey 0:439354122597 91 int Osc_IndexIntReceiverHelper( int channel, char* message, int length,
pehrhovey 0:439354122597 92 int indexCount, bool (*validIndex)( int index ),char* subsystemName,
pehrhovey 0:439354122597 93 int (*propertySet)( int index, int property, int value ),
pehrhovey 0:439354122597 94 int (*propertyGet)( int index, int property ),
pehrhovey 0:439354122597 95 char* propertyNames[] );
pehrhovey 0:439354122597 96
pehrhovey 0:439354122597 97 int Osc_BlobReceiverHelper( int channel, char* message, int length,
pehrhovey 0:439354122597 98 char* subsystemName,
pehrhovey 0:439354122597 99 int (*blobPropertySet)( int property, uchar* buffer, int length ),
pehrhovey 0:439354122597 100 int (*blobPropertyGet)( int property, uchar* buffer, int size ),
pehrhovey 0:439354122597 101 char* blobPropertyNames[] );
pehrhovey 0:439354122597 102
pehrhovey 0:439354122597 103
pehrhovey 0:439354122597 104 int Osc_IndexBlobReceiverHelper( int channel, char* message, int length,
pehrhovey 0:439354122597 105 int indexCount, char* subsystemName,
pehrhovey 0:439354122597 106 int (*blobPropertySet)( int index, int property, uchar* buffer, int length ),
pehrhovey 0:439354122597 107 int (*blobPropertyGet)( int index, int property, uchar* buffer, int size ),
pehrhovey 0:439354122597 108 char* blobPropertyNames[] );
pehrhovey 0:439354122597 109
pehrhovey 0:439354122597 110 int Osc_GeneralReceiverHelper( int channel, char* message, int length,
pehrhovey 0:439354122597 111 char* subsystemName,
pehrhovey 0:439354122597 112 int (*propertySet)( int property, char* typedata, int channel ),
pehrhovey 0:439354122597 113 int (*propertyGet)( int property, int channel ),
pehrhovey 0:439354122597 114 char* propertyNames[] );
pehrhovey 0:439354122597 115
pehrhovey 0:439354122597 116 int Osc_SendError( int channel, char* subsystemName, int error );
pehrhovey 0:439354122597 117
pehrhovey 0:439354122597 118
pehrhovey 0:439354122597 119 // Functions needed to process messages
pehrhovey 0:439354122597 120 int Osc_SubsystemError( int channel, char* subsystem, char* string );
pehrhovey 0:439354122597 121 int Osc_PropertyLookup( char** properties, char* property );
pehrhovey 0:439354122597 122 char *Osc_FindDataTag( char* message, int length );
pehrhovey 0:439354122597 123 int Osc_ExtractData( char* buffer, char* format, ... );
pehrhovey 0:439354122597 124 int Osc_NumberMatch( int max, char* pattern, int* fancy );
pehrhovey 0:439354122597 125 int Osc_SetReplyAddress( int channel, struct ip_addr * replyAddress );
pehrhovey 0:439354122597 126 int Osc_SetReplyPort( int channel, int replyPort );
pehrhovey 0:439354122597 127
pehrhovey 0:439354122597 128 // Pattern Match Stuff
pehrhovey 0:439354122597 129 bool Osc_PatternMatch(const char * pattern, const char * test);
pehrhovey 0:439354122597 130
pehrhovey 0:439354122597 131
pehrhovey 0:439354122597 132 #endif /* OSC_H_ */
pehrhovey 0:439354122597 133