Пример #1
0
/** \brief Initializes SMTP client
 * 	\author 
 *		\li Jari Lahti ([email protected])
 *	\date 12.08.2002
 *
 *	This function should be called once when system starts.
 *	Make sure that system services e.g. timers, TCP are initialized
 *	before initializing applications!
 */
void smtpc_init (void){
	
	if(smtpc_init_done) {
		DEBUGOUT("smtp client already initialized\r\n");
		return;
	}
	
	
	/* Get timer handle	*/
	
	smtp_client.tmrhandle = get_timer();
	
	/* Get TCP Socket	*/
	
	smtp_client.sochandle = tcp_getsocket(TCP_TYPE_CLIENT, TCP_TOS_NORMAL, TCP_DEF_TOUT, smtpc_eventlistener);
	
	if( smtp_client.sochandle < 0 ) {
		DEBUGOUT("smtpc_init() uncapable of getting socket\r\n");
		RESET_SYSTEM();
	}	
	
	smtpc_changestate(SMTP_CLOSED);
	smtp_client.bufindex = TCP_APP_OFFSET;
	smtp_client.unacked = 0;	
	smtp_client.remip = 0;
	smtp_client.remport = 0;

	smtpc_init_done = 0x01;

}
Пример #2
0
/* Initialize resources needed for the TCP server application */
void tcps_init(void) {
	
	DEBUGOUT("Initializing TCP server application. \r\n");
		
	/* Get socket:
	 * 	TCP_TYPE_SERVER - type of TCP socket is server
	 * 	TCP_TOS_NORMAL  - no other type of service implemented so far
	 *	TCP_DEF_TOUT	- timeout value in seconds. If for this many seconds
	 *		no data is exchanged over the TCP connection the socket will be
	 *		closed.
	 *	tcps_demo_eventlistener - pointer to event listener function for
	 * 		this socket.	
	 */
                                                            //TCP_DEF_TOUT
    int i;
    for (i = 0; i < NO_OF_TCPSOCKETS; ++i)
        socket[i] = tcp_getsocket(TCP_TYPE_SERVER, TCP_TOS_NORMAL, 60*TIMERTIC, tcps_eventlistener);
	
	if( socket[NO_OF_TCPSOCKETS - 1] < 0)
	{
		DEBUGOUT("TCP server unable to get socket. Resetting!!!\r\n");
		RESET_SYSTEM();
	}
	
	/* Put it to listen on some port	*/
    tcp_listen(socket[0], 5001);
    tcp_listen(socket[1], 5001);
    tcp_listen(socket[2], 5001);
    tcp_listen(socket[3], 5001);
}
Пример #3
0
//-----------------------------------------------------------------------------------------
// TCP_Init: inicializa todos los sockets
//-----------------------------------------------------------------------------------------
//
void TCP_Init (void)
{

	/* Get socket:
	 * 	TCP_TYPE_SERVER - type of TCP socket is server
	 * 	TCP_TOS_NORMAL  - no other type of service implemented so far
	 *	TCP_DEF_TOUT	- timeout value in seconds. If for this many seconds
	 *		no data is exchanged over the TCP connection the socket will be
	 *		closed.
	 *	tcps_control_panel_eventlistener - pointer to event listener function for
	 * 		this socket.	
	 */
 UINT8   TmpCntr; 	

 #ifdef   DNP_SLAVE_MODE

  UINT8   CliTcpIpAddrTxt[30];
  UINT8   CliTcpIpAddrIdx;
  UINT8   CliTcpIpCharIdx;
  UINT8   CliTcpIpChar[4];

  // el txt tiene address y puerto con formato xxx.xxx.xxx.xxx:ppp
 	eeprom_read_buffer( EE_ADDR_VER_TEXT, CliTcpIpAddrTxt, 30);
 	CliTcpIpAddrIdx=0; 
 	CliTcpIpCharIdx=0; 
 	for ( TmpCntr=0; TmpCntr<30 ; TmpCntr++){
 	  if (CliTcpIpAddrTxt[TmpCntr] == '.'){
 	    CliTcpIpAddrTxt[TmpCntr] = '\0';
 	    CliTcpIpChar[CliTcpIpCharIdx++] = (UINT8)(atoi((INT8*)&(CliTcpIpAddrTxt[CliTcpIpAddrIdx])));
 	    CliTcpIpAddrIdx = TmpCntr+1;
 	  } 
 	  if (CliTcpIpAddrTxt[TmpCntr] == ':'){
 	    CliTcpIpAddrTxt[TmpCntr] = '\0';
 	    CliTcpIpChar[CliTcpIpCharIdx++] = (UINT8)(atoi((INT8*)&(CliTcpIpAddrTxt[CliTcpIpAddrIdx])));
 	    CliTcpIpAddrIdx = TmpCntr+1;
 	    break;
 	  }
// 	  if (CliTcpIpAddrTxt[TmpCntr] == '\0') break;
 	}
  CliTcpIp = *((UINT32 *)CliTcpIpChar); 
  CliTcpSockPort = atoi((INT8*)&(CliTcpIpAddrTxt[CliTcpIpAddrIdx]));
 	
#endif //  DNP_SLAVE_MODE
	
	
	DEBUGOUT("Initializing TCP application. \r\n");
	
	
#ifdef   DNP_MASTER_MODE
// abrir todos los sockets destinados a recibir conexiones de DNP esclavos
for (TmpCntr=0 ; TmpCntr<MAX_SRV_TCPSOCH ; TmpCntr++)
{
	  // Puerto TCP Server recibir mensajes DNP_ETH desde el conversor remoto
	  TcpSockSrv[TmpCntr].TcpSrvTcpSoch = tcp_getsocket(TCP_TYPE_SERVER, TCP_TOS_NORMAL, TCP_SRV_TOUT, TCP_SrvTcpEventlistener);
	  if ( TcpSockSrv[TmpCntr].TcpSrvTcpSoch < 0 ){
		  DEBUGOUT("TCP: Unable to get socket. Resetting!!!\r\n");
		  RESET_SYSTEM();
	  }	 	
	  (void)tcp_listen(TcpSockSrv[TmpCntr].TcpSrvTcpSoch, TCP_DNPSRV_PORT);  // listen on port TCP_DNPSRV_PORT
//	(void)tcp_listen(TcpSrvTcpSoch, (UINT16)(CliTcpSockPort));  // listen on port CliTcpRemotePort
	  TcpSockSrv[TmpCntr].status = STATUS_LISTENING;
		TcpSockSrv[TmpCntr].SlaveIpAddress = 0;
  	TcpSockSrv[TmpCntr].SlaveTcpPort = 0;
  	TcpSockSrv[TmpCntr].SlaveNodeAddress = 0;
    TcpSockSrv[TmpCntr].BufferToken = 0xFF;
  	
}

#endif //  DNP_MASTER_MODE			
					
  // Puerto TCP para Server de mensajes de configuraciзn, recibidos por GWY_Config desde PC
	TcpConfigSoch = tcp_getsocket(TCP_TYPE_SERVER, TCP_TOS_NORMAL, TCP_DEF_TOUT, TCP_ConfigEventlistener);
	if ( TcpConfigSoch < 0 ){
		DEBUGOUT("TCP: Unable to get socket. Resetting!!!\r\n");
		RESET_SYSTEM();
	} 	
	(void)tcp_listen(TcpConfigSoch, TCP_CFG_PORT);  // listen on some port TCP_CFG_PORT


#ifdef   DNP_SLAVE_MODE

  // Puerto TCP  para Cliente DNP, envьa los mensajes recibidos por puerto serie.
 	TcpCliTcpSoch = tcp_getsocket(TCP_TYPE_CLIENT, TCP_TOS_NORMAL, TCP_CLI_TOUT, TCP_CliTcpEventlistener);	

	if ( TcpCliTcpSoch < 0 ){
		DEBUGOUT("TCP: Unable to get socket. Resetting!!!\r\n");
		RESET_SYSTEM();
	}
	
//  if (tcp_getstate(TcpCliTcpSoch) != TCP_STATE_CONNECTED){
//      (void) tcp_connect (TcpCliTcpSoch, CliTcpIp, (UINT16)(CliTcpSockPort), 0);//(UINT16)(DNP_LOCAL_PORT) );
//  }

#endif  // DNP_SLAVE_MODE	

	TcpConfigState =  FALSE;
	
}