打印
[STM32F1]

急求:STM32F107服务器程序 ,可以给充话费,DP83848CVV

[复制链接]
1376|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
luojing268|  楼主 | 2016-8-26 12:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
最近搞个STM32F107,做服务器程序,遇到点问题,请大家帮忙看看,现在其他地方考个程序,可以收 ,在初始化的时候可以发,或者客户端断开连接 在连上的时候可以发一下数据 。以后就不知道怎么发数据了、、这主程序
int main(void)
{
   struct tcp_pcb *pcb;
  /* Setup STM32 system (clocks, Ethernet, GPIO, NVIC) and STM3210C-EVAL resources */
  System_Setup();//            
  /* Initilaize the LwIP satck */
  LwIP_Init(); //到这里可以ping通
  /* Initilaize the HelloWorld module */
  HelloWorld_init();//这个函数后面有说明,里面有发送数据的函数,可以发送
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
  GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);// 改变指定管脚的映射 GPIO_Remap_SWJ_Disable SWJ 完全禁用(JTAG+SW-DP)
  GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);// 改变指定管脚的映射 GPIO_Remap_SWJ_JTAGDisable ,JTAG-DP 禁用 + SW-DP 使能
  while (1)
  {   
        /* Periodic tasks */
        System_Periodic_Handle();
  }
}

这个函数有发送数据的代码可以发送,初始化的时候有调用可以发送
void HelloWorld_init(void)
{
  struct tcp_pcb *pcb;                                   

  /* Create a new TCP control block  */
  pcb = tcp_new();                                                

  /* Assign to the new pcb a local IP address and a port number */
  /* Using IP_ADDR_ANY allow the pcb to be used by any local interface */
  tcp_bind(pcb, IP_ADDR_ANY, 23);      


  /* Set the connection to the LISTEN state */
  pcb = tcp_listen(pcb);                               

  /* Specify the function to be called when a connection is established */       
  tcp_accept(pcb, HelloWorld_accept1);  //具体是这个发送                                                               
}

看下这个函数HelloWorld_accept1,这是1个回调函数,这个在HelloWorld_init(void)调用了一下 ,有个问题不明白,就是客户端断开连接在连接 也会进入这个函数(不知道怎么进入的),这个函数可以发送数据 ,客户端也可以收到,但是以后单独调用这个的时候 就不可以了 单片机会跑飞。死机。
static err_t HelloWorld_accept1(void *arg, struct tcp_pcb *pcb, err_t err)//发送数据进这个
{     
  
  /* Tell LwIP to associate this structure with this connection. */
  tcp_arg(pcb, mem_calloc(sizeof(struct name), 1));        //告诉他们 已经建立连接
  
  /* Configure LwIP to use our call back functions. */
   tcp_err(pcb, HelloWorld_conn_err); //错误回调函数
   tcp_write(pcb, GREETING, strlen(GREETING), 0); //输出hello
   tcp_recv(pcb, HelloWorld_recv);//指定接收到数据后的回调函数
  
  /* Send out the first message */  




  return ERR_OK;
}

这接收数据的函数 服务器发来的数据可以收到里面,但是也搞不清是怎么进入的
static err_t HelloWorld_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)//收到数据会进这个函数
{
  struct pbuf *q;
  struct name *name = (struct name *)arg;
  int done;
  char *c;
  int i;


  /* We perform here any necessary processing on the pbuf */
  if (p != NULL)
  {        
        /* We call this function to tell the LwIp that we have processed the data */
        /* This lets the stack advertise a larger window, so more data can be received*/
        tcp_recved(pcb, p->tot_len);

    /* Check the name if NULL, no data passed, return withh illegal argument error */
        if(!name)
    {
      pbuf_free(p);
      return ERR_ARG;
    }

    done = 0;
    for(q=p; q != NULL; q = q->next)
    {
      c = q->payload;
      if(c[0]=='1')
      tcp_write(pcb, "aaaa", 4, 1);
      for(i=0; i<q->len && !done; i++)
          {
        done = ((c == '\r') || (c == '\n'));
        if(name->length < MAX_NAME_SIZE)
            {
          name->bytes[name->length++] = c;
                  infalg=1;
                  inbuf=        c;
        }
      }
    }
    if(done)
    {
      if(name->bytes[name->length-2] != '\r' || name->bytes[name->length-1] != '\n')
          {
        if((name->bytes[name->length-1] == '\r' || name->bytes[name->length-1] == '\n') && (name->length+1 <= MAX_NAME_SIZE))
            {
              name->length += 1;
        }
            else if(name->length+2 <= MAX_NAME_SIZE)
            {
          name->length += 2;
        }
            else
            {
          name->length = MAX_NAME_SIZE;
        }

        name->bytes[name->length-2] = '\r';
        name->bytes[name->length-1] = '\n';
      }
      tcp_write(pcb, HELLO, strlen(HELLO), 1);
      tcp_write(pcb, name->bytes, name->length, TCP_WRITE_FLAG_COPY);
      tcp_write(pcb, GREETING, strlen(GREETING), 0);
      name->length = 0;
    }
       
        /* End of processing, we free the pbuf */
    pbuf_free(p);
  }  
  else if (err == ERR_OK)
  {
    /* When the pbuf is NULL and the err is ERR_OK, the remote end is closing the connection. */
    /* We free the allocated memory and we close the connection */
    mem_free(name);
    return tcp_close(pcb);
  }
  return ERR_OK;
}
想知道的问题就是 做为服务器端 我怎么给客户端发数据???????????
那俩个函数是怎么调用的,为什么会进入那2个函数?????????????

中断里面可能有调用下面是中断部分
void ETH_IRQHandler(void)
{
  /* Handles all the received frames */
  while(ETH_GetRxPktSize() != 0)
  {               
    LwIP_Pkt_Handle();
  }

  /* Clear the Eth DMA Rx IT pending bits */
  ETH_DMAClearITPendingBit(ETH_DMA_IT_R);
  ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS);
}
中断里面的函数
void LwIP_Pkt_Handle(void)
{
  /* Read a received packet from the Ethernet buffers and send it to the lwIP for handling */
  ethernetif_input(&netif);
}

上面函数里面的函数
err_t
ethernetif_input(struct netif *netif)
{
  err_t err;
  struct pbuf *p;

  /* move received packet into a new pbuf */
  p = low_level_input(netif);

  /* no packet could be read, silently ignore this */
  if (p == NULL) return ERR_MEM;

  err = netif->input(p, netif);//ethernet_input
  if (err != ERR_OK)
  {
    LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
    pbuf_free(p);
    p = NULL;
  }

  return err;
}

这都没看到调用 不太明白那个收发函数是哪里怎么调用的

沙发
luojing268|  楼主 | 2016-8-26 12:54 | 只看该作者
工程文件上传到网盘大家可以下载,给解决问题的可以给充话费,就等于请吃个饭 谢谢
这个工程文件可以ping通 客户端可以给发数据 收到以后在那个接收函数里 但是不知道怎么发送数据到客户端
http://pan.baidu.com/s/1geGSjzt

使用特权

评论回复
板凳
shuangbang| | 2016-8-26 15:43 | 只看该作者
楼主,我给你解决吧,这么简单的问题;用rl-tcp非常容易额

使用特权

评论回复
地板
shuangbang| | 2016-8-26 16:15 | 只看该作者
告诉,打错了,不是高手

使用特权

评论回复
5
低八度的声线| | 2016-8-27 09:48 | 只看该作者
连个详细的注释也没有,工程包还得网盘找,好麻烦

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:51 msp430 stm32 学习中 求关注

14

主题

104

帖子

1

粉丝