Перейти к содержанию
    

Ethernet И FreeRTOS

Добрый день!!! Используем в качестве основы веб-сервер от FreeRTOS (контроллер AT91SAM7x256).

В ходе работы возникли следующие вопросы:

1) Как открыть второй порт ethernet?

2) КАк его открыть не на чтение а на запись?

3) Как через этот порт можно отправить уведомление (к примеру) по email'у?

4) Почему-то длина запросов веб-серверу (типа "?\123.txt") ограничивается 18 символами, как можно увеличить длину строки.

 

P.S. Хотя бы подскажите, плз, в каких файлах рыть :unsure:

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

:crying: и неужели никто не может помочь?? ну хыть намекните на решение проблемы, пожалуйстааа

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

А чем собственно второй порт отличается от всех остальных для lwIP?

 

Вот кусок кода с простеньким эзернет клиентом и сервером, когда-то давным давно делали тестовое приложение, которое гоняло данные по кольцу эзернет сервер - радио клиент to радио сервер эзернет клиент на двух устройствах. Модули были в офисной сети.

 

порты правда были

/* The client and the server ports. */

#define TCP_SERVER_PORT (1200)

#define TCP_CLIENT_PORT (1201)

Но я думаю через остальные тоже запахало бы. По крайней мере через HTTP порт(80) прокатывало.

 

К слову это не единственный способ работа с lwIP. Можно через Беркли сокеты, можно помойму ещё как-то. Почитайте их сайт, там маловато, но в принципе достаточно инфы, чтобы начать ковырять исходники.

 

#ifdef ETHERNET_SERVER
/******************************************************************************* 
  Process an incoming connection on port TCP_SERVER_PORT.

  This simply checks to see if the incoming data contains a data, and
  copy data to radio buffer. The connection is then
  closed. A more complete implementation could create a task for each 
  connection. 
  
  Pararmeter:
    pxNetCon - pointer to server netconn structure
********************************************************************************/
static void ethProcessConnection(struct netconn *pxNetCon)
{
  struct netbuf *pxRxBuffer;
  portCHAR *pcRxString;
  unsigned portSHORT usLength;

  /* We expect to immediately get data. */
  pxRxBuffer = netconn_recv(pxNetCon);

  BSP_OnLed(LED_RED);
  if(NULL != pxRxBuffer)
  {
    /* Where is the data? */
    netbuf_data(pxRxBuffer, (void *)&pcRxString, &usLength);       
    
    if (APP_BUFF_SIZE == usLength)
    {
      /* copy data to ethernet buffer */
      memcpy(appBuffers.eth.data, pcRxString, APP_BUFF_SIZE);
      appBuffers.eth.ready = true;
      netbuf_delete(pxRxBuffer);
      BSP_OffLed(LED_RED);
    }
  }
  else
  {
    dbgu_print_ascii("There isn't data in clients request \n\r");    
  }
  //netconn_close(pxNetCon);
}

/******************************************************************************* 
  Task of ethernet server
  Parameter:
     pvParameters - FreeRTOS task parameter
********************************************************************************/
void ethServer(void *pvParameters)
{
    /* waitning connection structure */
    struct netconn *pxWaitConnection;
    /* Getting connection structure */
    struct netconn *pxNewConnection = NULL;
    /* IP addresses */
    struct ip_addr xIpAddr, xNetMast, xGateway;
    extern err_t ethernetif_init( struct netif *netif );
    /* pre-allocated netif structure */ 
    static struct netif EMAC_if;

    /* Parameters are not used - suppress compiler error. */
    (void)pvParameters;

    /* Create and configure the EMAC interface. */
    /* Set IP address of device */
    IP4_ADDR(&xIpAddr,emacIPADDR0,emacIPADDR1,emacIPADDR2,emacIPADDR3);
    /* Set IP address of subnet */
    IP4_ADDR(&xNetMast,emacNET_MASK0,emacNET_MASK1,emacNET_MASK2,emacNET_MASK3);
    /* Set IP address of gateway */
    IP4_ADDR(&xGateway,emacGATEWAY_ADDR0,emacGATEWAY_ADDR1,emacGATEWAY_ADDR2,emacGATEWAY_A
DDR3);
    /**
     * Add a network interface to the list of lwIP netifs.
     *
     * @param netif a pre-allocated netif structure
     * @param ipaddr IP address for the new netif
     * @param netmask network mask for the new netif
     * @param gw default gateway IP address for the new netif
     * @param state opaque data passed to the new netif
     * @param init callback function that initializes the interface
     * @param input callback function that is called to pass
     * ingress packets up in the protocol layer stack.
     *
     * @return netif, or NULL if failed.
     */
    netif_add(&EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input);

    /* make it the default interface */
    netif_set_default(&EMAC_if);

    /* bring it up */
    netif_set_up(&EMAC_if);
    
    /* Create a new tcp connection handle */
    pxWaitConnection = netconn_new(NETCONN_TCP);
    netconn_bind(pxWaitConnection, NULL, TCP_SERVER_PORT);
    netconn_listen(pxWaitConnection);

    /* Wait for connection. */
    for (;;)
    {
      pxNewConnection = netconn_accept(pxWaitConnection);
      if (NULL != pxNewConnection)
        break;
    }
    
    /* Loop forever */
    for(;; )
    {
         /* Service connection. */
        ethProcessConnection(pxNewConnection);
    }
}

#else

/******************************************************************************* 
  Task of ethernet client
  Parameter:
     pvParameters - FreeRTOS task parameter
********************************************************************************/
void ethClient(void *pvParameters)
{
    /* waitning connection structure */
    struct netconn *pxWaitConnection = NULL;
    /* IP addresses */
    struct ip_addr xIpAddr, xNetMast, xGateway;
    /* server IP address */
    struct ip_addr xIpServer;
    /* pre-allocated netif structure */ 
    static struct netif EMAC_if;
    
    /* initialization netif structure and EMAC automat */
    extern err_t ethernetif_init(struct netif *netif);
    
    /* evry step statiion */
    //uint8_t sendError = CONNECTION_ERROR;    

    /* Parameters are not used - suppress compiler error. */
    (void)pvParameters;

    /* Create and configure the EMAC interface. */
    /* Set IP address of device */
    IP4_ADDR(&xIpAddr,emacIPADDR0,emacIPADDR1,emacIPADDR2,emacIPADDR3);
    /* Set IP address of subnet */
    IP4_ADDR(&xNetMast,emacNET_MASK0,emacNET_MASK1,emacNET_MASK2,emacNET_MASK3);
    /* Set IP address of gateway */
    IP4_ADDR(&xGateway,emacGATEWAY_ADDR0,emacGATEWAY_ADDR1,emacGATEWAY_ADDR2,emacGATEWAY_A
DDR3);
    /* Set IP address of server */
    IP4_ADDR(&xIpServer,emacServer_ADDR0,emacServer_ADDR1,emacServer_ADDR2,emacServer_ADDR
3);
    /**
     * Add a network interface to the list of lwIP netifs.
     *
     * @param netif a pre-allocated netif structure
     * @param ipaddr IP address for the new netif
     * @param netmask network mask for the new netif
     * @param gw default gateway IP address for the new netif
     * @param state opaque data passed to the new netif
     * @param init callback function that initializes the interface
     * @param input callback function that is called to pass
     * ingress packets up in the protocol layer stack.
     *
     * @return netif, or NULL if failed.
     */
    netif_add(&EMAC_if, &xIpAddr, &xNetMast, &xGateway, NULL, ethernetif_init, tcpip_input);

    /* make it the default interface */
  netif_set_default(&EMAC_if);

    /* bring it up */
  netif_set_up(&EMAC_if);
    
newTcpConnection:
  pxWaitConnection = netconn_new(NETCONN_TCP);
  if (NULL == pxWaitConnection)
  {
    dbgu_print_ascii("Connection structure doesn't create \n\r");
    for (;;)
      vTaskDelay(SHORT_DELAY);
  }
  
  // Data is ready. Try to establish a connection with server.
  while (1)
  {
    if (true == appBuffers.rf.ready)
    {
      if (ERR_OK == netconn_connect(pxWaitConnection, &xIpServer, TCP_SERVER_PORT))
        break;
      else
        dbgu_print_ascii("TCP connection doesn't set \n\r");
    }
    else
    {
      vTaskDelay(SHORT_DELAY);
    }
  }
  
  for (;;)
  {
    if (true == appBuffers.rf.ready)  // there is data from radio
    {
      BSP_OnLed(LED_RED);
      memcpy(appBuffers.eth.data, appBuffers.rf.data, APP_BUFF_SIZE);
      if (ERR_OK != netconn_write(pxWaitConnection, appBuffers.eth.data, APP_BUFF_SIZE, 0))
      {
        dbgu_print_ascii("Ethernet client data doesn't send \n\r");
        pxWaitConnection = NULL;
        while (ERR_OK != netconn_delete(pxWaitConnection))
        {
          vTaskDelay(SHORT_DELAY);
        }
        goto newTcpConnection;
      }
      // transmission is completed.                       
      appBuffers.rf.ready = false;      
      BSP_OffLed(LED_RED);  
    }
    else
    {
      vTaskDelay(SHORT_DELAY);
    }
  }
}
#endif

 

Приложение как можно видеть было сделано на основе фриртосного апликейшена.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

А чем собственно второй порт отличается от всех остальных для lwIP?

 

Приложение как можно видеть было сделано на основе фриртосного апликейшена.

 

Благодарю, спасибо)) Будем разбираться, правда, у нас не lwip, a uip.

Поделиться сообщением


Ссылка на сообщение
Поделиться на другие сайты

Присоединяйтесь к обсуждению

Вы можете написать сейчас и зарегистрироваться позже. Если у вас есть аккаунт, авторизуйтесь, чтобы опубликовать от имени своего аккаунта.

Гость
Ответить в этой теме...

×   Вставлено с форматированием.   Вставить как обычный текст

  Разрешено использовать не более 75 эмодзи.

×   Ваша ссылка была автоматически встроена.   Отображать как обычную ссылку

×   Ваш предыдущий контент был восстановлен.   Очистить редактор

×   Вы не можете вставлять изображения напрямую. Загружайте или вставляйте изображения по ссылке.

×
×
  • Создать...