void OSCAcceptPacket(OSCPacketBuffer packet) { if ((packet->n % 4) != 0) { OSCProblem("OSC packet size (%d bytes) not a multiple of 4.", packet->n); DropPacket(packet); return; } #ifdef DEBUG printf("OSCAcceptPacket(OSCPacketBuffer %p, buf %p, size %d)\n", packet, packet->buf, packet->n); #endif /* If the packet came from the user, it's return address is OK. */ packet->returnAddrOK = TRUE; InsertBundleOrMessage(packet->buf, packet->n, packet, OSCTT_Immediately()); #ifdef PARANOID if (packet->refcount == 0) { if (freePackets != packet) { fatal_error("OSCAcceptPacket: packet refcount 0, but it's not the head of the free list!"); } } #endif OSCInvokeAllMessagesThatAreReady(globals.lastTimeTag); }
int8_t MessageIface::dropPacket( void ) { return(DropPacket(&pf)); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if ( nrhs < 1 ) { mexErrMsgTxt( "Need input buffer data\n" ); } if ( !mxIsClass(prhs[0],"uint8") ) { mexErrMsgTxt( "Input buffer must by of type uint8\n" ); } // If the bytequeue and packet finder haven't been initialized then initialize them if ( !initialized ) { InitBQ(&pf_index_queue, pf_index_data, PF_INDEX_DATA_SIZE); InitPacketFinder(&pf, &pf_index_queue); initialized = true; } // Get length of the buffer int buflen = mxGetM(prhs[0]); if (buflen > 255) { mexErrMsgTxt( "Length of input buffer is too long, tell Uriah to fix this code \n" ); } // Get Buffer ... hopefully this is robust uint8_t *buf = (uint8_t*)mxGetPr( prhs[0] ); // Put bytes from buffer into byte queue uint8_t status = PutBytes( &pf, buf, buflen ); #ifdef DEBUG mexPrintf("buflen: %d\n", buflen); for (uint8_t i=0; i<buflen; i++){ mexPrintf("data[%d]: %d\n", i, buf[i]); } mexPrintf("status: %d\n", status); #endif // Peek Packet Finder and see if there is a valid packet to be found // if so, copy and return this data uint8_t *rx_data; uint8_t rx_len; uint8_t msg_type; uint8_t *msg_data; if ( PeekPacket(&pf, &rx_data, &rx_len) ) { #ifdef DEBUG mexPrintf("Packet found\n"); mexPrintf("rx_len: %d\n", rx_len); for (uint8_t i=0; i<rx_len; i++){ mexPrintf("rx_data[%d]: %d\n", i, rx_data[i]); } #endif int dims[2] = {1,rx_len}; plhs[0] = mxCreateNumericArray(2, dims, mxUINT8_CLASS, mxREAL); uint8_t *packet = (uint8_t*)mxGetPr(plhs[0]); memcpy( packet, rx_data, rx_len ); DropPacket(&pf); } else { int dims[2] = {1,0}; plhs[0] = mxCreateNumericArray(2, dims, mxUINT8_CLASS, mxREAL); } }