Exemplo n.º 1
0
/*****************************************************************************
** Function name:		void udPSendUnicast (void)
**
** Descriptions:		Envia dados udp para um unico IP 
*****************************************************************************/
void udpSendUnicast(U8 *udp_msg,char *strIp) 
{
	U8 ip[4];
  	U8 *sendbuf;
  	U16 len;

  	len = strlen ((const char*)udp_msg);
  	sendbuf = udp_get_buf (len);
  	str_copy (sendbuf, udp_msg);
	inet_aton((U8*)strIp,ip);
	udp_send (udp_soc, ip, atoi(cfg.tcp.port_udp), sendbuf, len);
}
Exemplo n.º 2
0
/*****************************************************************************
** Function name:		void udPSendBroadcast (void)
**
** Descriptions:		Envia dados udp para todos os IPs
*****************************************************************************/
void udpSendBroadcast(U8 *udp_msg) 
{
	U8 ip[4];
  	U8 *sendbuf;
  	U16 len;

  	len = strlen ((const char*)udp_msg);
  	sendbuf = udp_get_buf (len);
  	str_copy (sendbuf, udp_msg);

	/*O pacote UDP será broadcast quando o ultimo parâmetro do IP for 255*/
	memcpy(ip,MY_IP,4);
	ip[3] = 255;
	udp_send (udp_soc, ip, atoi(cfg.tcp.port_udp), sendbuf, len);
}
Exemplo n.º 3
0
//发送心跳数据
void Send_Heart_Beat(void)
{
    INT8U Temp[20];
	INT16U Len;
    INT8U *sendBuf;

    Len = Make_Frame(Temp + FDATA, 0, (INT8U *)&Screen_Para.COM_Para.Addr, C_HEART_BEAT,  0, 0, 0, (char *)Temp);	
    sendBuf = udp_get_buf (Len);

	if(sendBuf)
	{
	  memcpy(sendBuf, Temp, Len);
	  udp_send (Screen_Status.UDP_Soc, (INT8U *)&Screen_Para.Net_Para.Serv_IP, Screen_Para.Net_Para.Serv_Port, sendBuf, Len);
	}
}
Exemplo n.º 4
0
/**********************************************************************************************************************
** Function name:			SendSnmpCommand
** Descriptions:			��������
** input parameters:		None
** output parameters:		None
** Returned value:			ִ�гɹ�����CErrorValueDefine::uiConstReturnSuccess;
**							���������ָ�����CErrorValueDefine::uiConstReturnInputNULLPointer;
**							����ִ�����񣬲���������ý�����ڴ�����CErrorValueDefine::uiConstReturnProcessing
** 							ִ��ʧ�ܷ���CErrorValueDefine::uiConstReturnFailed;
** Created by:				WangChangRong
** Created date:			2012-03-13
**---------------------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Descriptions:
**
**********************************************************************************************************************/
uint32 CSnmpCommand::SendSnmpCommand()
{
	uint32 uiLength = 0;
	//����
	if( Encode(&uiLength) != CErrorValueDefine::uiConstReturnSuccess ){
		return CErrorValueDefine::uiConstReturnFailed;
	}

	uint8* ucpBuffer = objpSnmpDataInOut->GetResponseBuffer();

	//���������Ӧ
	uint8* sendbuf = udp_get_buf (uiLength);
	memcpy (sendbuf, &ucpBuffer[CSnmpDataInOut::uiConstResponseBufferSize-uiLength], uiLength);
	  /* Send 'Hello World!' to remote peer */
	udp_send (CommunicationModule::getSnmpSocket(), objData.GetSourceIP(), objData.GetSourcePort(), sendbuf, uiLength);

//	term_dat_out_len(sendbuf, uiLength);

	return CErrorValueDefine::uiConstReturnSuccess;

}
Exemplo n.º 5
0
void TrapList::sendaTrapItem() {

    if (endIndex == currentIndex)
        return;
    uint8* beSend = trapBuffer[currentIndex].buffer;
    uint16 sendLen = trapBuffer[currentIndex].buffersize;
    uint8* send_buff = udp_get_buf(sendLen);
    if( send_buff == 0 ) {
#ifdef EZ_DEBUG
        printf("\nTrapList::sendaTrapItem error udp_get_buf\n");
#endif
        return;
    }
    uint8 trapIP[4];
    DeviceComponent::getDeviceAttribute().getTrapDestIP(trapIP);
    memcpy( send_buff, beSend, sendLen );

//    while( arp_cache_ip(trapIP, ARP_FIXED_IP) != __TRUE ) {
//        if( !Protected ) {
//#ifdef EZ_DEBUG
//        strcpy(msg_ack, "Remote loss");
//#endif
//            return;
//        }
//        os_dly_wait(100);
//    };
    if( udp_send(soc_massage, trapIP, 162, send_buff, sendLen) != __TRUE ) {
#ifdef EZ_DEBUG
		printf("\nTrapList::sendaTrapItem error udp_send\n");
#endif
        return;
    }

    trapBuffer[currentIndex].valid = 0;
    currentIndex++;
    if (currentIndex >= TrapMaxNumber) {
        currentIndex = 0;
    }
}
Exemplo n.º 6
0
void UDP_Socket_Send (char udp_msg[], int len, char remip[]) {
	U8 *sendbuf;
	sendbuf = udp_get_buf (len);
	memcpy(sendbuf,udp_msg,len);
	udp_send(UDP_Socket, (U8 *)remip, UDP_PORT, sendbuf, len);
}
Exemplo n.º 7
0
/*****************************************************************************
** Function name:		U16 udp_callback (U8 socket, U8 *remip, U16 port, U8 *buf, U16 len)
**
** Descriptions:		verificamos os eventos do UDP
*****************************************************************************/
U16 udp_callback (U8 socket, U8 *remip, U16 port, U8 *buf, U16 len)
{
	U16 sz;
	U8 *sndbuf;
	char str[50],aux[8][20];
	int i,z,j;

  	/* This function is called when UDP data has been received. */
	if(len >= LEN_UDP_BUF)	/*Erro do tamanho do pacote recebido?*/
	{
		printf("[Overflow error in the UDP packet size]\r");
		printf("\r[buf:%s]\r",buf);
		fflush(stdout);
		return 0;
	}
	memset(udp_buf,0,sizeof(udp_buf));
	strncpy((char*)udp_buf,(const char*)buf,len);
	
	/*Informações do pacote*/
	printf("\r***[IP: %u.%u.%u.%u] Receiver Packet UDP:%s\r",remip[0],remip[1],remip[2],remip[3],udp_buf);
//	printf("\r*** Receiver Packet UDP: %s\r",udp_buf);
//	printf("*** IP: %u.%u.%u.%u\r",remip[0],remip[1],remip[2],remip[3]);	  		
	fflush(stdout);	

	/*Se receber a mensagem 'motel' via udp retorna para o IP do remetente as informações locais, como host name, IP e MAC*/
	if(strstr((const char *)udp_buf,"motel_all") != NULL)
	{
		sprintf(str,"%s : %u.%u.%u.%u : %02X.%02X.%02X.%02X.%02X.%02X\r\n\0",lhost_name,MY_IP[0],MY_IP[1],MY_IP[2],MY_IP[3],
		                                  own_hw_adr[0],own_hw_adr[1],own_hw_adr[2],own_hw_adr[3],own_hw_adr[4],own_hw_adr[5]);
		sz = strlen(str);
		sndbuf = udp_get_buf (sz);
		str_copy(sndbuf, (U8 *)str);
		udp_send (udp_soc, remip, port, sndbuf, sz);

	}else
	if((strstr((const char *)udp_buf,"SET") != NULL))
	{
		if(strlen((const char*)udp_buf) > 20)
		{
			memset(aux,0,sizeof(aux));
			for(i=0,j=0,z=0;i<strlen((const char*)udp_buf);i++)
			{
			    /*Exemplo: 6SET 040045047101:6SET 040045047101:6SET 040045047101*/ 
				if(udp_buf[i] == ':' || udp_buf[i] == '\r')
				{
					z++;
					j=0;
				}else		  
				{
					aux[z][j] = udp_buf[i];	/*Armazena scene z*/
					j++;
				}
			}
			for(i=0;i<NUM_SCENE;i++)
			{
				if((strstr(aux[i], scene[i]) != NULL))
				{ 
					printf("%s já existente na cena %u\r",aux[i],i); 
				}
				else
				{
					cmd_scene(aux[i]); 
					printf("%s...%s\r\n",buf_tx,aux[i]);
				}
				fflush(stdout);
			}
		}else
		{
			if((strstr((const char *)udp_buf,scene[udp_buf[0]]) != NULL))
			{  
				printf("%s já existente na cena %c\r",udp_buf,udp_buf[0]); 
			}
			else
			{
				cmd_scene((char*)udp_buf); 
				printf("%s\r\n",buf_tx);
			}
			fflush(stdout);
			memset(buf_tx,0,sizeof(buf_tx));
		}
	}else
	if(strstr((const char *)udp_buf,"PORT") != NULL)
	{
		for(i=0;i<8;i++)
			memset(aux[i],0,sizeof(aux[i]));
		
		for(i=0,j=0,z=0;i<strlen((const char*)udp_buf);i++)
		{
			/*Exemplo:PORT:5000:7000:6000:192.168.0.15:192.168.0.1<CR>*/
			if(udp_buf[i] == ':' || udp_buf[i] == '\r')
			{
				if(strstr(aux[0],"PORT") != NULL) //Tem "PORT" escrito?
					z=0;
				else
					z++;
				j=0;
				if(udp_buf[i] == '\r')
					break;
			}else		  
			{
				aux[z][j] = udp_buf[i];
				j++;
			}
		}

		j=0;
		if(atoi(cfg.tcp.port_udp) != atoi(aux[0]) && atoi(aux[0]) >= 5000 && atoi(aux[0]) <= 5050)
		{
			j = j + fwrite_line(aux[0], FILE_TCP_CFG, LINE_PORT_UDP);	/*Reinicia*/
			printf("Update Port Udp: %s\r",aux[0]);
			fflush(stdout);	  
		}	 
		
		if(atoi(cfg.tcp.port_serv_loc) != atoi(aux[1]) && atoi(aux[1]) >= 5000 && atoi(aux[1]) <= 5050)
		{
			j = j + fwrite_line(aux[1], FILE_TCP_CFG, LINE_PORT_SERV_LOC);	/*Reinicia*/
			printf("Update Port Tcp Local: %s\r",aux[1]);
			fflush(stdout);
		}
		
		if(atoi(cfg.tcp.port_serv_rem) != atoi(aux[2]) && atoi(aux[2]) >= 5000 && atoi(aux[2]) <= 5050)
		{
			/*j = j +*/  fwrite_line(aux[2], FILE_TCP_CFG, LINE_PORT_SERV_REM);	/*Não precisa reiniciar*/
			strcpy(cfg.tcp.port_serv_rem,aux[2]);
			printf("Update Port Server Remoto: %s\r",cfg.tcp.port_serv_rem);
			fflush(stdout);
		}

		if(strcmp(cfg.tcp.ip_serv_rem,aux[3]) && strlen(aux[3]) > 8)
		{
			/*j = j +*/  fwrite_line(aux[3], FILE_TCP_CFG, LINE_IP_SERV_REM);	/*Não precisa reiniciar*/
			strcpy(cfg.tcp.ip_serv_rem,aux[3]);
			printf("Update IP Server Remoto: %s\r",cfg.tcp.ip_serv_rem);
			fflush(stdout);
		}
		
		if(strcmp(cfg.tcp.ip_app,aux[4]) && strlen(aux[4]) > 8)
		{
			/*j = j +*/  fwrite_line(aux[4], FILE_TCP_CFG, LINE_IP_APP); 	/*Não precisa reiniciar*/
			strcpy(cfg.tcp.ip_app,aux[4]);
			printf("Update IP App: %s\r",cfg.tcp.ip_app);
			fflush(stdout);
		}

		if(j)
		{
			printf ("[TCP Config via UDP..Reiniciando]\r\r");
			fflush(stdout);
			#if USE_TCP_CLIENT	
			for(i=0;i<MAX_NUM_SOC;i++)
				tcp_close (tcp_client_soc[i]);
			#endif
			#if USE_TCP_SERVER	
				tcp_close (tcp_server_soc);
			#endif
			wdt_feed();
			for(i=0;i<5000000;i++)
				for(j=0;j<5000000;j++);
			LPC_WDT->WDTC = 0x3FFFF;	/*0.5s*/
			wdt_feed();
		}

	}else
	if(strstr((const char *)udp_buf,"RST") != NULL)
	{
		printf ("[Reset Solicitado..Reiniciando]\r\r");
		fflush(stdout);
		#if USE_TCP_CLIENT	
		for(i=0;i<MAX_NUM_SOC;i++)
			tcp_close (tcp_client_soc[i]);
		#endif
		#if USE_TCP_SERVER	
			tcp_close (tcp_server_soc);
		#endif
		LPC_WDT->WDTC = 0x003FFFF;	/*0.5s*/
		wdt_feed();
		while(1);
	}

  	return 0;
}