Changeset 1002
- Timestamp:
- 11/17/08 11:41:40 (7 weeks ago)
- Location:
- firmware/branches/cpp
- Files:
-
- 3 modified
-
core/makingthings/osc_cpp.cpp (modified) (3 diffs)
-
core/makingthings/osc_cpp.h (modified) (4 diffs)
-
libraries/appled/appled_.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
firmware/branches/cpp/core/makingthings/osc_cpp.cpp
r971 r1002 7 7 #include <string.h> 8 8 #include <stdlib.h> 9 #include <stdio.h> 10 #include <ctype.h> 9 11 10 12 extern "C" { … … 77 79 } 78 80 79 bool OSCC::receivePacket( int channel, char* packet, int length )81 bool OSCC::receivePacket( OscTransport t, char* packet, int length ) 80 82 { 81 83 // Got a packet. Unpacket. … … 115 117 } 116 118 119 OscRangeHelper::OscRangeHelper( OscMessage* msg, int element, int max, int min ) 120 { 121 remaining = 0; 122 single = -1; 123 if( !msg->address ) 124 return; 125 const char* p = strchr(msg->address, '/'); // should give us the very first char of the OSC message 126 if( !p++ ) // step to the beginning of the address element 127 return; 128 int j; 129 for( j = 0; j < element; j++ ) 130 { 131 p = strchr( p, '/'); 132 if(!p++) 133 return; 134 } 135 136 int n = 0; 137 int digits = 0; 138 // from OSC_NumberMatch() 139 while ( isdigit( *p ) ) 140 { 141 digits++; 142 n = n * 10 + ( *p++ - '0' ); 143 } 144 145 bits = -1; 146 if ( n >= max ) 147 return; // -1; 148 149 switch ( *p ) 150 { 151 case '*': 152 case '?': 153 case '[': 154 case '{': 155 { 156 int i; 157 int b = 0; 158 char s[ 5 ]; 159 for ( i = max - 1; i >= min ; i-- ) 160 { 161 b <<= 1; 162 sprintf( s, "%d", i ); 163 // if ( Osc_PatternMatch( p, s ) ) 164 // { 165 // b |= 1; 166 // remaining++; 167 // } 168 } 169 bits = b; 170 current = max; 171 return; // -1; 172 } 173 default: 174 if ( digits == 0 ) 175 return; // -1; 176 else 177 single = n; 178 return; // n; 179 } 180 } 181 182 bool OscRangeHelper::hasNextIndex( ) 183 { 184 return remaining > 0; 185 } 186 187 int OscRangeHelper::nextIndex( ) 188 { 189 int retval = 0; 190 if( single != -1 ) 191 { 192 remaining = 0; 193 return single; 194 } 195 bool cont = true; 196 while ( bits > 0 && remaining && cont ) 197 { 198 if ( bits & 1 ) 199 { 200 retval = current; 201 remaining--; 202 cont = false; 203 } 204 current--; 205 bits >>= 1; 206 } 207 return retval; 208 } 209 117 210 int OscHandler::propertyLookup( const char* propertyList[], char* property ) 118 211 { -
firmware/branches/cpp/core/makingthings/osc_cpp.h
r971 r1002 8 8 #define OSC_MAX_HANDLERS 56 9 9 #define OSC_MSG_MAX_DATA_ITEMS 20 10 // #define OSC_MSG_MAX_LEN 102411 10 #define OSC_MAX_MESSAGE_IN 400 12 11 #define OSC_MAX_MESSAGE_OUT 600 … … 46 45 }; 47 46 47 class OscRangeHelper 48 { 49 public: 50 OscRangeHelper( OscMessage* msg, int element, int max, int min = 0 ); 51 bool hasNextIndex( ); 52 int nextIndex( ); 53 private: 54 int remaining, bits, current, single; 55 }; 56 48 57 class OscHandler 49 58 { 50 59 public: 60 // mandatory 51 61 virtual int onNewMsg( OscMessage* msg, OscTransport t, int src_addr, int src_port ) = 0; 52 62 virtual int onQuery( int element ) = 0; 53 63 virtual const char* name( ) = 0; 64 // optional 65 bool autoSend( OscTransport t ) { (void)t; return false; } 54 66 protected: 55 67 int propertyLookup( const char* propertyList[], char* property ); … … 81 93 OSCC* instance( ) 82 94 { 83 if( _instance )95 if( !_instance ) 84 96 _instance = new OSCC( ); 85 97 return _instance; … … 89 101 OSCC( ) { } 90 102 OSCC* _instance; 91 bool receivePacket( int channel, char* packet, int length );103 bool receivePacket( OscTransport t, char* packet, int length ); 92 104 char* writePaddedString( char* buffer, int* length, char* string ); 93 105 char* writePaddedBlob( char* buffer, int* length, char* blob, int blen ); -
firmware/branches/cpp/libraries/appled/appled_.cpp
r971 r1002 138 138 (void)src_port; 139 139 int replies = 0; 140 bool ok;141 int index = msg->addressElementAsInt( 1, &ok ); // address element 1 should be our index142 if( !ok )143 return replies;144 140 char* property = msg->addressElementAsString( 2 ); // address element 2 should be the property 145 141 if( !property ) … … 150 146 return replies; 151 147 152 AppLed led(index); 153 if( msg->data_count ) // this is a setter 148 int index; 149 OscRangeHelper rangeHelper(msg, 1, APPLED_COUNT); // element 1 should be our index 150 while( rangeHelper.hasNextIndex() ) 154 151 { 155 int value = msg->dataItemAsInt(0); 156 switch( prop_index ) 152 index = rangeHelper.nextIndex(); 153 if( index < 0 || index >= APPLED_COUNT ) 154 continue; 155 AppLed led(index); 156 if( msg->data_count ) // setter...write the value to the led 157 157 { 158 case 0: // state 159 led.setState(value); 160 break; 158 int value = msg->dataItemAsInt(0); 159 switch( prop_index ) 160 { 161 case 0: // state 162 led.setState(value); 163 break; 164 } 161 165 } 162 } 163 else // this is a getter 164 { 165 int value; 166 switch( prop_index ) 166 else // getter...return a message 167 167 { 168 case 0: // state 169 value = led.getState( ); 170 // create new message to send it back 171 break; 168 int value; 169 switch( prop_index ) 170 { 171 case 0: // state 172 value = led.getState( ); 173 // create new message to send it back 174 replies++; 175 break; 176 } 172 177 } 173 178 } … … 190 195 } 191 196 192 // Need a list of property names193 // MUST end in zero194 // static char* AppLedOsc_Name = "appled";195 // static char* AppLedOsc_PropertyNames[] = { "active", "state", 0 }; // must have a trailing 0196 //197 // int AppLedOsc_PropertySet( int index, int property, int value );198 // int AppLedOsc_PropertyGet( int index, int property );199 //200 // // Returns the name of the subsystem201 // const char* AppLedOsc_GetName( )202 // {203 // return AppLedOsc_Name;204 // }205 //206 // // Now getting a message. This is actually a part message, with the first207 // // part (the subsystem) already parsed off.208 // int AppLedOsc_ReceiveMessage( int channel, char* message, int length )209 // {210 // int status = Osc_IndexIntReceiverHelper( channel, message, length,211 // APPLED_COUNT, AppLedOsc_Name,212 // AppLedOsc_PropertySet, AppLedOsc_PropertyGet,213 // AppLedOsc_PropertyNames );214 //215 // if ( status != CONTROLLER_OK )216 // return Osc_SendError( channel, AppLedOsc_Name, status );217 // return CONTROLLER_OK;218 // }219 //220 // // Set the index LED, property with the value221 // int AppLedOsc_PropertySet( int index, int property, int value )222 // {223 // switch ( property )224 // {225 // case 0:226 // AppLed_SetActive( index, value );227 // break;228 // case 1:229 // AppLed_SetState( index, value );230 // break;231 // }232 // return CONTROLLER_OK;233 // }234 //235 // // Get the index LED, property236 // int AppLedOsc_PropertyGet( int index, int property )237 // {238 // int value = 0;239 // switch ( property )240 // {241 // case 0:242 // value = AppLed_GetActive( index );243 // break;244 // case 1:245 // value = AppLed_GetState( index );246 // break;247 // }248 //249 // return value;250 // }251 252 197 #endif // OSC
