• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ getSn_SR函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中getSn_SR函数的典型用法代码示例。如果您正苦于以下问题:C++ getSn_SR函数的具体用法?C++ getSn_SR怎么用?C++ getSn_SR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getSn_SR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: tcp_socket_init

uint8_t tcp_socket_init(TCP_CONFIG *config)
{

	static bool startup=false;
	if(!startup)
	{
		GPIO_Configuration();
		Reset_W5200();
		WIZ_SPI_Init();
		Set_network(config->Source_IP, config->Gateway, config->MAC, config->Subnet);
		startup=true;
		while (getSn_SR(config->s) != SOCK_CLOSED);
	}

	if(socket(config->s,Sn_MR_TCP,config->Source_Port,0x00)== 0)    /* reinitialize the socket */
	{
		return 0; //TCP socket failed
	}

	while (getSn_SR(config->s) != SOCK_INIT); // Wait for socket to open

	IINCHIP_WRITE(Sn_CR(config->s), Sn_CR_LISTEN); // Start listening on port specified
	while (IINCHIP_READ(Sn_CR(config->s))); // Check status
	while (getSn_SR(config->s) != SOCK_LISTEN); // Wait for listen
	return 1;
}
开发者ID:GerarDZG,项目名称:Embedded-Systems,代码行数:26,代码来源:tcp.c


示例2: WIZCHIP_EXPORT

int32_t WIZCHIP_EXPORT(send)(uint8_t sn, uint8_t * buf, uint16_t len)
{
   uint8_t tmp=0;
   uint16_t freesize=0;
   
   CHECK_SOCKNUM();
   CHECK_SOCKMODE(Sn_MR_TCP);
   CHECK_SOCKDATA();
   tmp = getSn_SR(sn);
   if(tmp != SOCK_ESTABLISHED && tmp != SOCK_CLOSE_WAIT) return SOCKERR_SOCKSTATUS;
   if( sock_is_sending & (1<<sn) )
   {
      tmp = getSn_IR(sn);
      if(tmp & Sn_IR_SENDOK)
      {
         setSn_IR(sn, Sn_IR_SENDOK);
         #if _WZICHIP_ == 5200
            if(getSn_TX_RD(sn) != sock_next_rd[sn])
            {
               setSn_CR(sn,Sn_CR_SEND);
               while(getSn_CR(sn));
               return SOCKERR_BUSY;
            }
         #endif
         sock_is_sending &= ~(1<<sn);         
      }
      else if(tmp & Sn_IR_TIMEOUT)
      {
         WIZCHIP_EXPORT(close)(sn);
         return SOCKERR_TIMEOUT;
      }
      else return SOCK_BUSY;
   }
   freesize = getSn_TxMAX(sn);
   if (len > freesize) len = freesize; // check size not to exceed MAX size.
   while(1)
   {
      freesize = getSn_TX_FSR(sn);
      tmp = getSn_SR(sn);
      if ((tmp != SOCK_ESTABLISHED) && (tmp != SOCK_CLOSE_WAIT))
      {
         WIZCHIP_EXPORT(close)(sn);
         return SOCKERR_SOCKSTATUS;
      }
      if( (sock_io_mode & (1<<sn)) && (len > freesize) ) return SOCK_BUSY;
      if(len <= freesize) break;
      MICROPY_THREAD_YIELD();
   }
   wiz_send_data(sn, buf, len);
   #if _WIZCHIP_ == 5200
      sock_next_rd[sn] = getSn_TX_RD(sn) + len;
   #endif
   setSn_CR(sn,Sn_CR_SEND);
   /* wait to process the command... */
   while(getSn_CR(sn));
   sock_is_sending |= (1 << sn);
   return len;
}
开发者ID:DanielO,项目名称:micropython,代码行数:58,代码来源:socket.c


示例3: ip_task

void ip_task(void){
	switch(sock_state){
		case IP_STATE_NO_SOCKET:
		if(socket(0, Sn_MR_TCP, 5000, 0) == 0)
		sock_state = IP_STATE_SOCKET;
		break;
		case IP_STATE_SOCKET:
		switch (listen(0)){
			case SOCK_OK :
			sock_state = IP_STATE_LISTEN;
			break;
			case SOCKERR_SOCKCLOSED :
			sock_state = IP_STATE_CLOSE;
		}
		break;
		case IP_STATE_LISTEN :
		switch(getSn_SR(0)){
			case SOCK_LISTEN :
			_delay_ms(100);
			break;
			case SOCK_ESTABLISHED:
			sock_state = IP_STATE_ECHO;
			break;
			default:
			sock_state = IP_STATE_CLOSE;
		}
		break;
		case IP_STATE_CLOSE:
		disconnect(0);
		close(0);
		sock_state=IP_STATE_NO_SOCKET;
		break;
		case IP_STATE_ECHO:
		if (getSn_SR(0) == SOCK_ESTABLISHED) {
			sock_state = echo();
			} else {
			sock_state = IP_STATE_CLOSE;
		}
		break;
		case IP_STATE_GREETING:
		if (getSn_SR(0) == SOCK_ESTABLISHED) {
			sock_state = greeting();
			} else {
			sock_state = IP_STATE_CLOSE;
		}
		break;
	}
}
开发者ID:oltzen,项目名称:W5500Example,代码行数:48,代码来源:W5500Example.c


示例4: do_udp

void do_udp(void){
	uint16 len = 0;
	uint8 buffer[2048];/*定义一个2KB的缓存*/
//	uint8 pc_ip[4] = { 192, 168, 10, 10 };/*配置服务器的IP地址*/
//	uint16 pc_port = 5000;							/*定义计算机的一个端口并初始化*/
	uint16 local_port = 5000;
	
	if(isGetIP){
		switch (getSn_SR(SOCKET_UDP))/*获取socket 0的状态*/
		{
			case SOCK_UDP:/*socket 的套接字初始化完成*/
			if (getSn_IR(SOCKET_UDP) & Sn_IR_RECV)
			{
				setSn_IR(SOCKET_UDP, Sn_IR_RECV);/*Sn_IR的第0位置1*/
				printf("Sendto Fail\r\n");
			}
			if ((len = getSn_RX_RSR(SOCKET_UDP)) > 0)
			{
				len = recvfrom(SOCKET_UDP, buffer, len, remote_ip, &remote_port);/*W5500接收计算机发送来的数据*/
				printf("%d.%d.%d.%d:%d \r\n", remote_ip[0], remote_ip[1], remote_ip[2], remote_ip[3], remote_port);
				if (len != sendto(SOCKET_UDP, buffer, len, remote_ip, remote_port))
				{
					printf("Sendto Fail\r\n");
				}
			}
			break;
			
			case SOCK_CLOSED:/*socket 关闭*/
			socket(SOCKET_UDP, Sn_MR_UDP, local_port, 0);/*初始化socket 0的套接字*/
			break;
		}
	}
}
开发者ID:InfiniteYuan1,项目名称:STM32,代码行数:33,代码来源:udp_demo.c


示例5: do_udp

/**
*@brief     UDP测试程序
*@param     无
*@return    无
*/
void do_udp(void)
{                                                              
    uint16 len=0;
    uint8 buff[2048];                                                          /*定义一个2KB的缓存*/    
    switch(getSn_SR(SOCK_UDPS))                                                /*获取socket的状态*/
    {
        case SOCK_CLOSED:                                                        /*socket处于关闭状态*/
            socket(SOCK_UDPS,Sn_MR_UDP,local_port,0);                              /*初始化socket*/
          break;
        
        case SOCK_UDP:                                                           /*socket初始化完成*/
            delay_ms(10);
            if(getSn_IR(SOCK_UDPS) & Sn_IR_RECV)
            {
                setSn_IR(SOCK_UDPS, Sn_IR_RECV);                                     /*清接收中断*/
            }
            if((len=getSn_RX_RSR(SOCK_UDPS))>0)                                    /*接收到数据*/
            {
                recvfrom(SOCK_UDPS,buff, len, remote_ip,&remote_port); 
                /*W5500接收计算机发送来的数据*/
                buff[len-8]=0x00;                                                    /*添加字符串结束符*/
                printf("%s\r\n",buff);                                               /*打印接收缓存*/ 
                sendto(SOCK_UDPS,buff,len-8, remote_ip, remote_port);                /*W5500把接收到的数据发送给Remote*/
            }
            break;
    }

}
开发者ID:Dainter,项目名称:STM32-Project,代码行数:33,代码来源:udp_demo.c


示例6: connect

int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port)
{
   CHECK_SOCKNUM();
   CHECK_SOCKMODE(Sn_MR_TCP);
   CHECK_SOCKINIT();
	if( *((uint32_t*)addr) == 0xFFFFFFFF || *((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
	if(port == 0) return SOCKERR_PORTZERO;
	setSn_DIPR(sn,addr);
	setSn_DPORT(sn,port);
   #if _WIZCHIP_ == 5200   // for W5200 ARP errata 
      setSUBR(0);
   #endif
	setSn_CR(sn,Sn_CR_CONNECT);
   while(getSn_CR(sn) && !jspIsInterrupted());
   if(sock_io_mode & (1<<sn)) return SOCK_BUSY;
   while(getSn_SR(sn) != SOCK_ESTABLISHED)
   {   
        if (jspIsInterrupted())
          return SOCKERR_TIMEOUT;
		if (getSn_IR(sn) & Sn_IR_TIMEOUT)
		{
			setSn_IR(sn, Sn_IR_TIMEOUT);
         #if _WIZCHIP_ == 5200   // for W5200 ARP errata 
            setSUBR((uint8_t*)"\x00\x00\x00\x00");
         #endif
         return SOCKERR_TIMEOUT;
		}
	}
   #if _WIZCHIP_ == 5200   // for W5200 ARP errata 
      setSUBR((uint8_t*)"\x00\x00\x00\x00");
   #endif
   
   return SOCK_OK;
}
开发者ID:0x00f,项目名称:Espruino,代码行数:34,代码来源:socket.c


示例7: getSn_SR

uint8_t EncClient::status() {
  if (_sock == 255) {
    return SOCK_CLOSED;
  } else {
    return getSn_SR(_sock);
  }
}
开发者ID:ulrichard,项目名称:homeauto,代码行数:7,代码来源:EncClient.cpp


示例8: getSn_SR

uint8_t Client::connect() {
  if (_sock != 255)
    return 0;
  
  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    uint8_t s = getSn_SR(i);
    if (s == SOCK_CLOSED || s == SOCK_FIN_WAIT) {
      _sock = i;
      break;
    }
  }
  
  if (_sock == 255)
    return 0;
    
  _srcport++;
  if (_srcport + 1024 == 0) _srcport = 0;
  socket(_sock, Sn_MR_TCP, _srcport + 1024, 0);
  
  if (!::connect(_sock, _ip, _port)) {
    _sock = 255;
    return 0;
  }
    
  while (status() != SOCK_ESTABLISHED) {
    delay(1);
    if (status() == SOCK_CLOSED) {
      _sock = 255;
      return 0;
    }
  }
  
  return 1;
}
开发者ID:cldeotti,项目名称:arduino-rtnet,代码行数:34,代码来源:Client.cpp


示例9: net_wiznet_accept

/// If the given server socket can accept a connection, return it (or return < 0)
int net_wiznet_accept(JsNetwork *net, int sckt) {
  NOT_USED(net);

  // On WIZnet the same server socket is reused for clients - keep track so we don't get confused
  // and try and allocate a new HTTP Server Client
  if (wiznetSocketAsServerClient & (1<<sckt))
    return -1;

  /* CC3000/WIZnet works a different way - we set accept as nonblocking,
   * and then we just call it and see if it works or not...
   */

  // we have a client waiting to connect... try to connect and see what happens
  // WIZnet's implementation doesn't use accept, it uses listen
  int status = getSn_SR((uint8_t)sckt);
  if (status == SOCK_ESTABLISHED) {
    wiznetSocketAsServerClient = wiznetSocketAsServerClient | (unsigned char)(1<<sckt); // mark that it's now being used as a client socket

    return ((int)sckt) | WIZNET_SERVER_CLIENT; // we deal with the client on the same socket (we use the flag so we know that it really is different!)
  }

  // WIZnet can get confused (somehow!) when handling repeated requests from the HTTP server
  if (status == SOCK_CLOSED || status == SOCK_CLOSE_WAIT) {
    // make sure we force-close again and re-init as a listener
    net_wiznet_closesocket(net, (uint16_t)(sckt | WIZNET_SERVER_CLIENT));
  }

  return -1;
}
开发者ID:HTH-CODE,项目名称:Espruino,代码行数:30,代码来源:network_wiznet.c


示例10: GetUDPSocketStatus

/**
@brief	This function get the UDP socket status.
@return 	UDP socket status.
*/
int8 GetUDPSocketStatus(SOCKET s)
{
    int8 ret=0;

    switch(getSn_SR(s)) {
    case SOCK_CLOSED:		/**< closed */
        ret = (int8)STATUS_CLOSED;
        break;
    case SOCK_UDP:			/**< udp socket */
        ret = STATUS_UDP;
        break;
#if 0
    case SOCK_IPRAW:		/**< ip raw mode socket */
        ret = 11;
        break;
    case SOCK_MACRAW:		/**< mac raw mode socket */
        ret = 12;
        break;
    case SOCK_PPPOE:		/**< pppoe socket */
        ret = 13;
        break;
#endif
    default:
        if((IINCHIP_READ(Sn_MR(s))&0x0F) != Sn_MR_UDP)	ret = (int8)ERROR_NOT_UDP_SOCKET;
        break;
    }

    return ret;
}
开发者ID:Wiznet,项目名称:W7200,代码行数:33,代码来源:socket.c


示例11: loopback_udps

int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port)
{
    int32_t  ret;
    uint16_t size, sentsize;
    uint8_t  destip[4];
    uint16_t destport;

    switch(getSn_SR(sn))
    {
    case SOCK_UDP :
        if((size = getSn_RX_RSR(sn)) > 0)
        {
            if(size > DATA_BUF_SIZE)
                size = DATA_BUF_SIZE;
            ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
            if(ret <= 0)
            {

#ifdef _LOOPBACK_DEBUG_
                printk("%d: recvfrom error. %ld\r\n",sn,ret);
#endif
                return ret;
            }
            size = (uint16_t) ret;
            sentsize = 0;
            while(sentsize != size)
            {
                ret = sendto(sn, buf+sentsize, size-sentsize, destip, destport);
                if(ret < 0)
                {
#ifdef _LOOPBACK_DEBUG_
                    printk("%d: sendto error. %ld\r\n",sn,ret);
#endif
                    return ret;
                }
                sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
            }
        }
        break;

    case SOCK_CLOSED:
#ifdef _LOOPBACK_DEBUG_
        //printk("%d:UDP loopback start\r\n",sn);
#endif
        if((ret = socket(sn, Sn_MR_UDP, port, 0x00)) != sn)
            return ret;
#ifdef _LOOPBACK_DEBUG_
        printk("%d:Opened, UDP loopback, port [%d]\r\n", sn, port);
#endif
        break;

    default :

        break;
    }
    return 1;
}
开发者ID:35408EF66CCE4377B1E3C2495CA1C18A,项目名称:stm32f407_oled,代码行数:57,代码来源:loopback.c


示例12: init_httpd_ch

/**
 * @brief		Initialise the socket & buffer for HTTP server
 */
uint8_t init_httpd_ch(SOCKET s)
{
	uint8_t ret;
	ret = 0;

	if( getSn_SR(s) != SOCK_CLOSED )	// Check the preferred socket is available,
	{
		s = getSocket(SOCK_CLOSED, 0);	// otherwise find free socket,
		if(s == MAX_SOCK_NUM )        	// If there is no free socket?
			ret = 0;
	}
	else
	{
		ret = 1;
	}

	if(!socket(s, Sn_MR_TCP, IP_PORT_HTTP, 0x00)) // initialise the socket for DHCP service
	{
		xSerialPrintf_P(PSTR("HTTPD socket: %d, initialise fail..!\r\n"),s);
		ret = 0;
	}
#ifdef HTTP_DEBUG
	else
		xSerialPrintf_P(PSTR("HTTPD socket: %d, initialise success..!\r\n"),s);
#endif

	if(pHTTPRequest == NULL) // if there is no buffer allocated (pointer is NULL), then allocate request buffer for all HTTP functions.
	{
		if( !(pHTTPRequest = (HTTP_REQUEST *) pvPortMalloc( sizeof(HTTP_REQUEST) )))
		{
			xSerialPrint_P(PSTR("HTTP Request Buffer: malloc fail..!\r\n"));
			ret = 0;
		}
#ifdef HTTP_DEBUG
		else
			xSerialPrint_P(PSTR("HTTP Request Buffer: malloc success..!\r\n"));
#endif
	}

	if(pHTTPResponse == NULL) // if there is no buffer allocated (pointer is NULL), then allocate response buffer for all HTTP functions.
	{
		if( !(pHTTPResponse = (uint8_t *) pvPortMalloc( sizeof(uint8_t) * (FILE_BUFFER_SIZE + 1) )))
		{
			xSerialPrint_P(PSTR("HTTP Response Buffer: malloc fail..!\r\n"));
			vPortFree(pHTTPRequest);
			ret = 0;
		}
#ifdef HTTP_DEBUG
		else
			xSerialPrint_P(PSTR("HTTP Response Buffer: malloc success..!\r\n"));
#endif
	}

	HTTPD_SOCK = s;

	return ret;
}
开发者ID:eddiecastropineda,项目名称:CollegeBound,代码行数:60,代码来源:http.c


示例13: check_for_connections

uint8_t check_for_connections(TCP_CONFIG *config)
{
	if(!(getSn_SR(config->s) != SOCK_ESTABLISHED))
	{
	while ((bytesReceived = getSn_RX_RSR(config->s)) == 0); // wait for connection
	return 1;
	}
	return 0;
}
开发者ID:GerarDZG,项目名称:Embedded-Systems,代码行数:9,代码来源:tcp.c


示例14: getsockopt

int8_t  getsockopt(uint8_t sn, sockopt_type sotype, void* arg)
{
   CHECK_SOCKNUM();
   switch(sotype)
   {
      case SO_FLAG:
         *(uint8_t*)arg = getSn_MR(sn) & 0xF0;
         break;
      case SO_TTL:
         *(uint8_t*) arg = getSn_TTL(sn);
         break;
      case SO_TOS:
         *(uint8_t*) arg = getSn_TOS(sn);
         break;
      case SO_MSS:   
         *(uint16_t*) arg = getSn_MSSR(sn);
         break;
      case SO_DESTIP:
         getSn_DIPR(sn, (uint8_t*)arg);
         break;
      case SO_DESTPORT:  
         *(uint16_t*) arg = getSn_DPORT(sn);
         break;
   #if _WIZCHIP_ > 5200   
      case SO_KEEPALIVEAUTO:
         CHECK_SOCKMODE(Sn_MR_TCP);
         *(uint16_t*) arg = getSn_KPALVTR(sn);
         break;
   #endif      
      case SO_SENDBUF:
         *(uint16_t*) arg = getSn_TX_FSR(sn);
         break;
      case SO_RECVBUF:
         *(uint16_t*) arg = getSn_RX_RSR(sn);
         break;
      case SO_STATUS:
         *(uint8_t*) arg = getSn_SR(sn);
         break;
      case SO_REMAINSIZE:
         if(getSn_MR(sn) & Sn_MR_TCP)
            *(uint16_t*)arg = getSn_RX_RSR(sn);
         else
            *(uint16_t*)arg = sock_remained_size[sn];
         break;
      case SO_PACKINFO:
         //CHECK_SOCKMODE(Sn_MR_TCP);
#if _WIZCHIP_ != 5300
         if((getSn_MR(sn) == Sn_MR_TCP))
             return SOCKERR_SOCKMODE;
#endif
         *(uint8_t*)arg = sock_pack_info[sn];
         break;
      default:
         return SOCKERR_SOCKOPT;
   }
   return SOCK_OK;
}
开发者ID:Wiznet,项目名称:ioLibrary_Driver,代码行数:57,代码来源:socket.c


示例15: loopback_tcpc

int32_t loopback_tcpc(uint8_t sn, uint8_t* destip, uint16_t destport){
	
	int32_t ret; // return value for SOCK_ERRORs

	// Destination (TCP Server) IP info (will be connected)
	// >> loopback_tcpc() function parameter
	// >> Ex)
	//	uint8_t destip[4] = 	{192, 168, 34, 131};
	//	uint16_t destport = 	5000;

	// Port number for TCP client (will be increased)
	uint16_t any_port = 	2;

	// Socket Status Transitions
	// Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status)
	switch(getSn_SR(sn))
	{
		case SOCK_ESTABLISHED :
		if(getSn_IR(sn) & Sn_IR_CON)	// Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful
		{
			sprintf(gPtrintBuff, "%d:Connected to - %d.%d.%d.%d : %u\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
			uartPuts(gPtrintBuff);
			setSn_IR(sn, Sn_IR_CON);  // this interrupt should be write the bit cleared to '1'
		}

		break;

		case SOCK_CLOSE_WAIT :
		if((ret=disconnect(sn)) != SOCK_OK) return ret;
		
			sprintf(gPtrintBuff, "%d:Socket Closed\r\n", sn);
			uartPuts(gPtrintBuff);
		break;

		case SOCK_INIT :
		
		sprintf(gPtrintBuff, "%d:Try to connect to the %d.%d.%d.%d : %u\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
		uartPuts(gPtrintBuff);
		
		if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret;	//	Try to TCP connect to the TCP server (destination)
		break;

		case SOCK_CLOSED:
		close(sn);
		if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn) return ret; // TCP socket open with 'any_port' port number
		
		sprintf(gPtrintBuff, "%d:TCP client loopback start\r\n",sn);
		uartPuts(gPtrintBuff);
		sprintf(gPtrintBuff, "%d:Socket opened\r\n",sn);
		uartPuts(gPtrintBuff);
		break;
		default:
		break;
	}
	return 1;
}
开发者ID:keeepcool,项目名称:Backup,代码行数:56,代码来源:main.c


示例16: net_wiznet_getFreeSocket

uint8_t net_wiznet_getFreeSocket() {
  unsigned int i;
  for (i=0;i<8;i++)
    if (getSn_SR(i) == SOCK_CLOSED) // it's free!
      return (uint8_t)i;

  jsError("No free sockets found\n");
  // out of range will probably just make it error out
  return 8;
}
开发者ID:HTH-CODE,项目名称:Espruino,代码行数:10,代码来源:network_wiznet.c


示例17: close

int8_t close(uint8_t sn)
{
	CHECK_SOCKNUM();
//A20160426 : Applied the erratum 1 of W5300
#if   (_WIZCHIP_ == 5300) 
   //M20160503 : Wrong socket parameter. s -> sn 
   //if( ((getSn_MR(s)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(s) != getSn_TxMAX(s)) ) 
   if( ((getSn_MR(sn)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(sn) != getSn_TxMAX(sn)) ) 
   { 
      uint8_t destip[4] = {0, 0, 0, 1};
      // TODO
      // You can wait for completing to sending data;
      // wait about 1 second;
      // if you have completed to send data, skip the code of erratum 1
      // ex> wait_1s();
      //     if (getSn_TX_FSR(s) == getSn_TxMAX(s)) continue;
      // 
      //M20160503 : The socket() of close() calls close() itself again. It occures a infinite loop - close()->socket()->close()->socket()-> ~
      //socket(s,Sn_MR_UDP,0x3000,0);
      //sendto(s,destip,1,destip,0x3000); // send the dummy data to an unknown destination(0.0.0.1).
      setSn_MR(sn,Sn_MR_UDP);
      setSn_PORTR(sn, 0x3000);
      setSn_CR(sn,Sn_CR_OPEN);
      while(getSn_CR(sn) != 0);
      while(getSn_SR(sn) != SOCK_UDP);
      sendto(sn,destip,1,destip,0x3000); // send the dummy data to an unknown destination(0.0.0.1).
   };   
#endif 
	setSn_CR(sn,Sn_CR_CLOSE);
   /* wait to process the command... */
	while( getSn_CR(sn) );
	/* clear all interrupt of the socket. */
	setSn_IR(sn, 0xFF);
	//A20150401 : Release the sock_io_mode of socket n.
	sock_io_mode &= ~(1<<sn);
	//
	sock_is_sending &= ~(1<<sn);
	sock_remained_size[sn] = 0;
	sock_pack_info[sn] = 0;
	while(getSn_SR(sn) != SOCK_CLOSED);
	return SOCK_OK;
}
开发者ID:Wiznet,项目名称:ioLibrary_Driver,代码行数:42,代码来源:socket.c


示例18: net_wiznet_recv

/// Receive data if possible. returns nBytes on success, 0 on no data, or -1 on failure
int net_wiznet_recv(JsNetwork *net, int sckt, void *buf, size_t len) {
  NOT_USED(net);
  int num = 0;
  if (getSn_SR(sckt)!=SOCK_LISTEN) {
    // receive data - if none available it'll just return SOCK_BUSY
    num = (int)recv((uint8_t)sckt,buf,(uint16_t)len,0);
    if (num==SOCK_BUSY) num=0;
  }
  if (jspIsInterrupted()) return -1;
  return num;
}
开发者ID:aalhakim,项目名称:Espruino,代码行数:12,代码来源:network_wiznet.c


示例19: lock

// Send the data, returning the length buffered
size_t W5500Socket::Send(const uint8_t *data, size_t length)
{
	MutexLocker lock(interface->interfaceMutex);

	if (CanSend() && length != 0 && getSn_SR(socketNum) == SOCK_ESTABLISHED)
	{
		// Check for previous send complete
		if (isSending)									// are we already sending?
		{
			const uint8_t tmp = getSn_IR(socketNum);
			if (tmp & Sn_IR_SENDOK)						// did the previous send complete?
			{
				setSn_IR(socketNum, Sn_IR_SENDOK);		// if yes
				isSending = false;
			}
			else if (tmp & Sn_IR_TIMEOUT)				// did it time out?
			{
				isSending = false;
				disconnectNoWait(socketNum);			// if so, close the socket
				state = SocketState::aborted;
				return 0;								// and release buffers etc.
			}
			else
			{
				return 0;								// last send is still in progress
			}
		}

		if (!sendOutstanding)
		{
			wizTxBufferLeft = getSn_TX_FSR(socketNum);	// get free buffer space
			if (wizTxBufferLeft == 0)
			{
				return 0;
			}
			wizTxBufferPtr = getSn_TX_WR(socketNum);
		}

		if (length > wizTxBufferLeft)
		{
			length = wizTxBufferLeft;
		}
		wiz_send_data_at(socketNum, data, length, wizTxBufferPtr);
		wizTxBufferLeft -= length;
		wizTxBufferPtr += length;
		sendOutstanding = true;
		if (wizTxBufferLeft == 0)
		{
			Send();
		}
		return length;
	}
	return 0;
}
开发者ID:dc42,项目名称:RepRapFirmware,代码行数:55,代码来源:W5500Socket.cpp


示例20: sprintf

uint8_t EncClient::connect() {
  if (_sock != 255)
    return 0;
#ifdef ETHERSHIELD_DEBUG
    sprintf(_DEBUG, "EncClient::connect() DEBUG A. _sock = %d",
            _sock);
#endif

  for (int i = 0; i < MAX_SOCK_NUM; i++) {
    uint8_t s = getSn_SR(i);
    if (s == SOCK_CLOSED || s == SOCK_FIN_WAIT) {
      _sock = i;
      break;
    }
  }

#ifdef ETHERSHIELD_DEBUG
    sprintf(_DEBUG, "EncClient::connect() DEBUG B. _sock = %d",
            _sock);
#endif
  if (_sock == 255)
    return 0;

  _srcport++;
  if (_srcport + 1024 == 0) _srcport = 0;
  socket(_sock, Sn_MR_TCP, _srcport + 1024, 0);

#ifdef ETHERSHIELD_DEBUG
    sprintf(_DEBUG, "Client::connect() DEBUG C. _sock = %d",
            _sock);
#endif
  if (!::connect(_sock, _ip, _port)) {
    _sock = 255;
    return 0;
  }

#ifdef ETHERSHIELD_DEBUG
    sprintf(_DEBUG, "Client::connect() DEBUG D. _sock = %d", _sock);
#endif
  while (status() != SOCK_ESTABLISHED) {
    delay(1);
    if (status() == SOCK_CLOSED) {
      _sock = 255;
      return 0;
    }
  }

#ifdef ETHERSHIELD_DEBUG
    sprintf(_DEBUG, "EncClient::connect() DEBUG E. _sock = %d", _sock);
#endif
  return 1;
}
开发者ID:ulrichard,项目名称:homeauto,代码行数:52,代码来源:EncClient.cpp



注:本文中的getSn_SR函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ getSource函数代码示例发布时间:2022-05-28
下一篇:
C++ getSize函数代码示例发布时间:2022-05-28
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap