Ejemplo n.º 1
0
/** \brief Obtain a timer from timer pool
 * 	\author 
 *		\li Jari Lahti ([email protected])
 *	\date 18.07.2001
 *	\return Handle to a free timer
 *	\warning
 *		\li Timers are considered to be critical resources, so if there is 
 *		no available timer and get_timer is invoked, system will reset.
 *
 *	Invoke this function to obtain a free timer (it's handle that is) from
 *	the timer pool.
 */
UINT8 get_timer (void)
{
	
	int i;
	UINT8 first_match;
	
	
	for( i=0; i < NUMTIMERS; i++) {
		if( timer_pool[i].free == TRUE ) {
			/* We found a free timer! */
			/* Mark is reserved		  */
			
			timer_pool[i].free = FALSE;
			first_match = i;
			return first_match;		/* Return Handle	*/
		}
	
	}
	
	/* Error Check	*/
	
	TMR_DEBUGOUT("No Timers, Resetting..\n\r");
	RESET_SYSTEM();
	
	return(-1);
}
Ejemplo n.º 2
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;

}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
void UDP_Init (void)
{
	DEBUGOUT("Initializing UDP Echo client\r\n");

	udp_soch = udp_getsocket(0 , UPD_PanelEventlistener , UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS);
	
	if(udp_soch == -1)
	    {
		DEBUGOUT("No free UDP sockets!! \r\n");
		RESET_SYSTEM();
	    }
	
	/* open socket */
	(void)udp_open(udp_soch, UDP_AK_PORT);
}
Ejemplo n.º 5
0
void UDP_Init (void)
{
	DEBUGOUT("Initializing UDP Echo client\r\n");



  eeprom_read_buffer(EE_ADDR_UDPTRACE_IP, (UINT8 *)&udp_ipaddr, 4);
	//udp_ipaddr = localmachine.defgw;
  udp_port= 5001;
  //udp_ipaddr = 0xC0A80105; //192.168.1.5
	udp_soch = udp_getsocket(0 , UPD_PanelEventlistener , UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS);
	
	if(udp_soch == -1)
	    {
		DEBUGOUT("No free UDP sockets!! \r\n");
		RESET_SYSTEM();
	    }
	
	/* open socket */
	(void)udp_open(udp_soch, UDP_AK_PORT);
}
Ejemplo n.º 6
0
/* Initialize resources needed for the UDP socket application */
void udp_demo_init(void){

	DEBUGOUT("Initializing UDP demo client\r\n");
	
	/* Get socket:
	 * 	0 - for now not type of service implemented in UDP
	 * 	udp_echo_eventlistener - pointer to listener function
	 *	UDP_OPT_SEND_CS|UDP_OPT_CHECK_CS - checksum options. Calculate
	 *		checksum for outgoing packets and check checksum for
	 *		received packets.
	 */
	udp_demo_soch=udp_getsocket(0 , udp_demo_eventlistener , UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS);
	
	if(udp_demo_soch == -1){
		DEBUGOUT("No free UDP sockets!! \r\n");
		RESET_SYSTEM();
	}
	
	/* open socket for receiving/sending of the data on defined port*/
	udp_open(udp_demo_soch,UDP_DEMO_PORT);
	
	/* for now no data sending */
	udp_demo_senddata=0;
}
Ejemplo n.º 7
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;
	
}