/* return cmd.*/
int Connect::_connect_asyncReceive(Daemon_cmd_T *p_cmd,int *p_error)
{


	char *buffer = NULL;
	int len = 0,receiveLen = 0;

	if( (receiveLen = _p.available()) > 0)
	{
		//_print(" receive data: \n");
		receiveLen +=128;
		buffer = (char*)malloc(receiveLen);
		if(buffer == NULL)
			return 0;

		memset(buffer,0,receiveLen);
		for(len = 0;_p.available() > 0;len++)
		{
		
			if(len  < receiveLen)
			{
				//char c;
				buffer[len]=_p.read();
				//c = buffer[len];
				//Serial.print(c);
 			}
		}
		
		*p_cmd = (Daemon_cmd_T)manage_handleReceive(buffer,&index,p_error,&_l_port);
#if 0		
		_print("\n receive buf : \n");
		_printArray(buffer,strlen(buffer));

		_print(" \n _connect_asyncReceive cmd :\n");
		Serial.print(*p_cmd,DEC);
		_print(" \n _connect_asyncReceive index :\n");
		Serial.print(index,DEC);
		_print(" \n _connect_asyncReceive error :\n");
		Serial.print(*p_error,DEC);
		_print("\tend \n");
#endif		
		if(buffer)
			free(buffer);

		return receiveLen;
	}

	return 0;
}
示例#2
0
int main(int argc, int* argv[])
{
	int nums[SIZE];
	int i, loc, sizeNow=0;
	
	printf ("请输入%d个整数(空格或回车间隔):", N);
	for (i=0; i<N; i++){
		scanf ("%d", &nums[i]);
		loc = _findPosition(nums, N, i, nums[i]);//调用函数计算插入位置 
		_insertElement(nums, N, sizeNow,loc, nums[i]);//插入当前数字到合适位置 
 		sizeNow ++;//当前数组大小+! 
	}

      printf ("升序排列结果:");
	_printArray(nums, N);//调用打印函数 
	
	system ("pause");
	return 0;
}
long int Connect::_connect_send(Daemon_cmd_T cmd,Wilddog_EventType_T event,unsigned long index,
					const char *src,const char *p_host)
{
	int res,len = 0,src_len = 0; 
	char *p_buf = NULL;
	if(src)
	{
		src_len = strlen((char*)src);
	}
	if(p_host)
	{
		len += strlen((char*)p_host);
	}
	len += 100 + src_len;
	p_buf = (char*)malloc(len);
	if(p_buf == NULL)
		return -1;

	memset(p_buf,0,len);
	/* get send packet..*/
	res = manage_getSendPacket(p_buf,&len,cmd,index,event,src,p_host,_l_port);	

	/** sending out.*/
	if( res > 0 && strlen(p_buf) > 0 )
	{
		_p.asyncSend(p_buf);	
#if 0	
		if(cmd != _CMD_NOTIFY)
		{
			/* DEBUGing....*/
			_print("\n cmd :");
			Serial.print(cmd);
			_print("\n event :");
			Serial.print(event);
			_print("\n index :");
			Serial.print(index);

			if(p_host)
			{
				_print("\n p_host :");
				Serial.print(p_host);
			}
			if(src)
			{
				_print("\n data :");
				Serial.print(src);
			}


			_print("\n src_len  :");
			Serial.print(src_len);
			
			_print("\n malloc len :");
			Serial.print(len);
			_print("\n shell cmd 3 :");
			_printArray(p_buf,strlen(p_buf));
			_print("\n shell cmd len :");
			Serial.print(strlen(p_buf));
		}
#endif
	}
	
	free(p_buf);
	return res;
}