Esempio n. 1
0
int16_t Z_OSCServer::decodeProcess(){
	
	DBG_LOGLN("decodeProcess");
	message.flush();
	
	
	
	W5100.writeSnIR(socketNo ,SnIR::RECV );
	
	message.allPackSize=recvfrom(socketNo
					 ,rcvData
					 ,1 
					 ,message.ipAddress 
					 ,&message.portNumber );
	
	
	if (message.allPackSize>kMaxRecieveData) {
		DBG_LOGLN("server decode process max rcv data err");
		return 2;
	}
	
	
	
	if(decoder.decode( &message ,rcvData ) > 0){
		
		message.flush();
		return 1;
	}

	
	return 0;
}
Esempio n. 2
0
int16_t Z_OSCMessage::setZ_OSCAddress(const char *_address){

	oscAdrSize=(uint16_t)strlen(_address);
	
	if( oscAdrSize > kMaxZ_OSCAdrCharactor ){
		DBG_LOGLN("set Z_OSC max Z_OSC Adr err");
		flush();
		return 1;
	}
	
	if(oscAddress!=NULL) free(oscAddress);
	
	oscAddress=(char*)calloc(1,oscAdrSize+1);
	strcpy(oscAddress,_address);
		
	oscAdrPacSize=getPackSize(oscAdrSize);
	
	DBG_LOG("set Z_OSC Adr:");
	DBG_LOG(oscAddress);
	DBG_LOG(" size:");
	DBG_LOG(oscAdrSize);
	DBG_LOG(" packsize:");
	DBG_LOGLN(oscAdrPacSize);
	
	return 0;
}
Esempio n. 3
0
int16_t Z_OSCMessage::setTypeTags(const char *_tags ){

	uint8_t maxErr=0;
	
	argsNum=(uint16_t)strlen(_tags);
	
	if(argsNum > kMaxAugument){
		DBG_LOGLN("set tags max arg err");
		flush();
		return 1;
	}
	
	typeTagSize = argsNum+1;
	
	if(typeTag!=NULL) free(typeTag);
	typeTag=(char*)calloc(1,argsNum+1);

	strcpy(typeTag,_tags);
	
	typeTagPacSize=getPackSize(typeTagSize);
	
	argsNum=typeTagSize;
	
	
	DBG_LOG("set TypeTag:");
	DBG_LOG(typeTag);
	DBG_LOG(" size:");
	DBG_LOG(typeTagSize);
	DBG_LOG(" packsize:");
	DBG_LOGLN(typeTagPacSize);
	
	return 0;
}
Esempio n. 4
0
void Z_OSCMessage::flush(){
	
	if(oscAddress!=NULL) free(oscAddress);
	
	oscAddress=NULL;
	oscAdrSize=0;
	oscAdrPacSize=0;
	
	if(typeTag!=NULL) free(typeTag);
	
	typeTag=NULL;
	typeTagSize=0;
	typeTagPacSize=0;
	
	if(arguments!=NULL){
		
		for (uint16_t i=0; i< argsNum; i++) {
			free((void*)arguments[i]);
			arguments[i]=NULL;
		}
		free(arguments);		
	}
	argsNum=0;
	argsPacSize=0;	
	
	arguments=NULL;
	
	setIpAddress(0,0,0,0);
	portNumber=0;
	
	DBG_LOGLN("flush message obj");
	
}
Esempio n. 5
0
void Z_OSCServer::sockOpen(uint16_t _recievePort){
	socketNo=1;
	socket( socketNo ,SnMR::UDP ,_recievePort ,0);
	availableFlush();
	message.flush();
	
	DBG_LOGLN("server open");
	
}
Esempio n. 6
0
Z_OSCMessage::Z_OSCMessage()
{	
	DBG_LOGLN("construct message");

	oscAddress=NULL;
	typeTag=NULL;
	arguments=NULL;
	
	flush();
 
}
Esempio n. 7
0
Z_OSCMessage::Z_OSCMessage(const char *_oscAddress)
{
	DBG_LOGLN("construct message with Adr");
	oscAddress=NULL;
	typeTag=NULL;
	arguments=NULL;
	
	flush();
	
	setZ_OSCAddress(_oscAddress);

}
Esempio n. 8
0
void Z_OSCMessage::setIpAddress( uint8_t _ip1 ,uint8_t _ip2 ,uint8_t _ip3 ,uint8_t _ip4 ){
	
	ipAddress[0] = _ip1;
	ipAddress[1] = _ip2;
	ipAddress[2] = _ip3;
	ipAddress[3] = _ip4;
	
	DBG_LOG("set IP Adr with IP nums:");
	DBG_LOG((int)ipAddress[0]);
	DBG_LOG(".");
	DBG_LOG((int)ipAddress[1]);
	DBG_LOG(".");
	DBG_LOG((int)ipAddress[2]);
	DBG_LOG(".");
	DBG_LOGLN((int)ipAddress[3]);
	
}
Esempio n. 9
0
void Z_OSCMessage::setIpAddress(uint8_t *_ip){
		
	ipAddress[0] = _ip[0];
	ipAddress[1] = _ip[1];
	ipAddress[2] = _ip[2];
	ipAddress[3] = _ip[3];
	
	DBG_LOG("set IP Adr with IParray:");
	DBG_LOG((int)ipAddress[0]);
	DBG_LOG(".");
	DBG_LOG((int)ipAddress[1]);
	DBG_LOG(".");
	DBG_LOG((int)ipAddress[2]);
	DBG_LOG(".");
	DBG_LOGLN((int)ipAddress[3]);

}
int16_t OSCEncoder::encode( OSCMessage::OSCMessage *mes ,uint8_t *sendData ){


	uint8_t *packStartPtr=sendData;

	memset(sendData, 0, mes->getAllPackSize());

//=========== OSC Address(String) -> BIN Encode   ===========

	memcpy( sendData ,mes->oscAddress ,mes->oscAdrSize);
	packStartPtr += mes->oscAdrPacSize;
	mes->allPackSize = mes->oscAdrPacSize;

//=========== TypeTag(String) -> BIN Encode   ===========

	*packStartPtr=',';
	memcpy(packStartPtr+1 ,mes->typeTag ,mes->argsNum);
	packStartPtr += mes->typeTagPacSize;

	mes->allPackSize += mes->typeTagPacSize;


//=========== Auguments -> BIN Encode   ==================


	uint8_t *tmpPtr;

	uint32_t tmpInt;

#ifdef _USE_FLOAT_
	float	tmpFloat;
#endif

#ifdef _USE_STRING_
	uint16_t strSize;
#endif

	for (int i=0; i< mes->argsNum; i++) {

		switch ( mes->typeTag[i] ) {

			case 'i':

				tmpInt = mes->getInteger32(i);
				tmpPtr =(uint8_t*)(&tmpInt);

				*packStartPtr++=*(tmpPtr+3);
				*packStartPtr++=*(tmpPtr+2);
				*packStartPtr++=*(tmpPtr+1);
				*packStartPtr++=*tmpPtr;

				mes->allPackSize += 4;
				break;

#ifdef _USE_FLOAT_
			case 'f':

				tmpFloat = mes->getFloat(i);
				tmpPtr=(uint8_t*)(&tmpFloat);

				*packStartPtr++=*(tmpPtr+3);
				*packStartPtr++=*(tmpPtr+2);
				*packStartPtr++=*(tmpPtr+1);
				*packStartPtr++=*tmpPtr;

				mes->allPackSize += 4;
				break;
#endif

#ifdef _USE_STRING_
			case 's':
				strSize = strlen(mes->getString(i));

				if(strSize > kMaxStringCharactor){

					DBG_LOGLN("encode max str err");
					return 1;
				}

				memcpy( (char*)packStartPtr ,mes->getString(i) ,strSize );
				packStartPtr += mes->getPackSize(strSize);

				mes->allPackSize += mes->getPackSize(strSize);
				break;
#endif

		}
	}
	return 0;
}
Esempio n. 11
0
Z_OSCMessage::~Z_OSCMessage()
{
	DBG_LOGLN("destruct message");
	flush();
}
Esempio n. 12
0
int16_t Z_OSCMessage::setZ_OSCMessage( const char *_address ,char *types , ... ){
	
	va_list argsList;
	
	DBG_LOG("set Z_OSCMessage:");
	
	
	if( setZ_OSCAddress(_address) > 0) return 1;
	if( setTypeTags(types) > 0) return 1;
	
	
	
	
	//-------------------------------------------------	
	
	if (arguments!=NULL) free(arguments);
	arguments=(void**)calloc(argsNum, sizeof(void*));
	
	
	
	argsPacSize=0;
	
	void *tmpPtr;
	char *tmpStr;
	uint16_t strSize;
	
	va_start( argsList, types );	
	
	for(uint8_t i=0 ; i < argsNum ; i++){
		
		typeTag[i]=types[i];
		
		
		switch(types[i]){
				
			case 'i':
				tmpPtr=calloc(1, 4);
				
				memcpy(tmpPtr,(int32_t *)va_arg(argsList, int32_t *),4);
				arguments[i]=(int32_t *)tmpPtr;
				argsPacSize += 4;
				
				DBG_LOG(" int(4byte):");
				DBG_LOG(*(int32_t *)tmpPtr);
				
				break;
				
				
#ifdef _USE_FLOAT_				
			case 'f':
				tmpPtr=calloc(1, 4);
				
				memcpy(tmpPtr,(float *)va_arg(argsList, float *),4);
				arguments[i]=(float *)tmpPtr;
				
				argsPacSize += 4;
				
				DBG_LOG(" float(4byte):");
				DBG_LOG(*(float *)tmpPtr);
				
				break;
#endif	
				
				
#ifdef _USE_STRING_
			case 's':
				tmpStr=(char *)va_arg(argsList, char *);
				strSize=strlen(tmpStr);
				DBG_LOGLN(strSize);
				if(strSize > kMaxStringCharactor){
					
					DBG_LOGLN("set args message max str err");
					return 1;
				}
				
				tmpPtr=calloc(strSize+1, 1);
				strcpy((char*)tmpPtr, tmpStr);
				
				arguments[i]=tmpPtr;
				argsPacSize += getPackSize( strSize );
				
				DBG_LOG(" String,size:");
				DBG_LOG(strSize);
				DBG_LOG(" packsize:");
				DBG_LOG(getPackSize( strSize ));
				DBG_LOG(" :");
				DBG_LOG((char *)tmpPtr);
				
				break;
#endif
				
		}
		
	}
	DBG_LOGLN("");
	DBG_LOGLN("");
	return 0;
}
Esempio n. 13
0
int16_t Z_OSCDecoder::decode( Z_OSCMessage *mes ,const uint8_t *recData ){
	
	
//===========  BIN -> Z_OSC Address(String) Decode   ===========
	
	const uint8_t *packStartPtr=recData;
	
	mes->setZ_OSCAddress((char*)packStartPtr);
			
	packStartPtr += mes->oscAdrPacSize;
	


//===========  BIN -> TypeTag (String) Decode   ===========

	mes->setTypeTags((char*)(packStartPtr+1));

	packStartPtr += mes->typeTagPacSize;


//===========  BIN -> Auguments Decode   ===========
	
	
	if (mes->arguments!=NULL) free(mes->arguments);
	mes->arguments=(void**)calloc(mes->argsNum, sizeof(void*));
	
	mes->argsPacSize=0;
	
	uint8_t *tmpPtr;
	uint16_t tmpSize;


	
	for (uint16_t i=0; i< mes->argsNum ; i++) {

		switch (mes->typeTag[i]) {
				
			case 'i':
				
				tmpPtr=(uint8_t*)calloc(1, 4);

				*(tmpPtr+3)=*(uint8_t*)packStartPtr++;
				*(tmpPtr+2)=*(uint8_t*)packStartPtr++;
				*(tmpPtr+1)=*(uint8_t*)packStartPtr++;
				*tmpPtr=*(uint8_t*)packStartPtr++;

				mes->arguments[i]=(uint32_t*)tmpPtr;
				mes->argsPacSize += 4;
				break;

#ifdef _USE_FLOAT_	
			case 'f':
				
				tmpPtr=(uint8_t*)calloc(1, 4);
				
				*(tmpPtr+3)=*(uint8_t*)packStartPtr++;
				*(tmpPtr+2)=*(uint8_t*)packStartPtr++;
				*(tmpPtr+1)=*(uint8_t*)packStartPtr++;
				*tmpPtr=*(uint8_t*)packStartPtr++;

				mes->arguments[i]=(float*)tmpPtr;
				mes->argsPacSize += 4;
				
				break;
#endif
				
				
#ifdef _USE_STRING_
			case 's':
	
				tmpSize=strlen((char*)packStartPtr);
				
				if(tmpSize > kMaxStringCharactor){
					
					DBG_LOGLN("decode max str err");
					return 1;
				}
				
				
				tmpPtr=(uint8_t*)calloc(tmpSize+1, 1);
				strcpy((char*)tmpPtr,(char*)packStartPtr);
				
				mes->arguments[i]=tmpPtr;
	
				
				tmpSize = mes->getPackSize(tmpSize);
				packStartPtr += tmpSize;
				mes->argsPacSize += tmpSize;
								
				break;
#endif
		}
	}
	
	return 0;
}
Esempio n. 14
0
int16_t OSCDecoder::decode( OSCMessage::OSCMessage *mes ,const uint8_t *recData ){
    
//===========  BIN -> OSC Address(String) Decode   ===========
	
	const uint8_t *packStartPtr=recData;
	
	mes->setOSCAddress((char*)packStartPtr);
	
	packStartPtr += mes->oscAdrPacSize;
	
    
    
//===========  BIN -> TypeTag (String) Decode   ===========
    
	mes->setTypeTags((char*)(packStartPtr+1));
    
	packStartPtr += mes->typeTagPacSize;
    
    
//===========  BIN -> Auguments Decode   ===========
	
	
	if (mes->arguments!=NULL) free(mes->arguments);
	mes->arguments=(void**)calloc(mes->argsNum, sizeof(void*));
	
	mes->argsPacSize=0;
	
	uint8_t *tmpPtr;
	uint16_t tmpSize;
    
    
	
	for (uint16_t i=0; i< mes->argsNum ; i++) {
        
		switch (mes->typeTag[i]) {
            
        case 'i':
            
            tmpPtr=(uint8_t*)calloc(1, 4);
            
            *(tmpPtr+3)=*(uint8_t*)packStartPtr++;
            *(tmpPtr+2)=*(uint8_t*)packStartPtr++;
            *(tmpPtr+1)=*(uint8_t*)packStartPtr++;
            *tmpPtr=*(uint8_t*)packStartPtr++;
            
            mes->arguments[i]=(uint32_t*)tmpPtr;
            mes->argsPacSize += 4;
            break;
            
#ifdef _USE_FLOAT_	
        case 'f':
            
            tmpPtr=(uint8_t*)calloc(1, 4);
			
            *(tmpPtr+3)=*(uint8_t*)packStartPtr++;
            *(tmpPtr+2)=*(uint8_t*)packStartPtr++;
            *(tmpPtr+1)=*(uint8_t*)packStartPtr++;
            *tmpPtr=*(uint8_t*)packStartPtr++;
            
            mes->arguments[i]=(float*)tmpPtr;
            mes->argsPacSize += 4;
			
            break;
#endif
            
			
#ifdef _USE_STRING_
        case 's':
            
            tmpSize=strlen((char*)packStartPtr);
			
            if(tmpSize > kMaxStringCharactor){
					
                DBG_LOGLN("decode max str err");
                return 1;
            }
            
			
            tmpPtr=(uint8_t*)calloc(tmpSize+1, 1);
            strcpy((char*)tmpPtr,(char*)packStartPtr);
			
            mes->arguments[i]=tmpPtr;
            
			
            tmpSize = mes->getPackSize(tmpSize);
            packStartPtr += tmpSize;
            mes->argsPacSize += tmpSize;
			
            break;
#endif
            
#ifdef _USE_BLOB_
        case 'b':
            // Note: To minimize memory usage and maximize speed, we
            // DO NOT COPY THE RECEIVED BLOB. Message data is only
            // good prior to "flushing".

            OSCBlob * p = (OSCBlob *) calloc(sizeof(OSCBlob),1);
            mes->arguments[i]=p;

            tmpPtr=(uint8_t*) &p->len;		// unpack bigendian size

            *(tmpPtr+3)=*(uint8_t*)packStartPtr++;
            *(tmpPtr+2)=*(uint8_t*)packStartPtr++;
            *(tmpPtr+1)=*(uint8_t*)packStartPtr++;
            *tmpPtr=    *(uint8_t*)packStartPtr++;
            p->data = packStartPtr;
            
            packStartPtr += mes->getPackSize(p->len);		// round up to 32bit boundrytmpSize;
            mes->argsPacSize += mes->getPackSize(p->len);

            // Serial.print("BLOBSIZE");
            // Serial.println(tmpSize);
		
        break;
#endif
        
        }
    }
    return 0;
}