ots-m2m / sew-lwm2m-reference-design

A reference implementation of the South East Water LWM2M water meter design
Mozilla Public License 2.0
7 stars 0 forks source link

Need to support multiple packets in a slip polling loop #2

Closed mofosyne closed 7 years ago

mofosyne commented 7 years ago

/Users/briankhuu/git/sew-lwm2m-reference-design/thirdparty/lwip/src/netif/slipif.c

within while loop. possible issue with extracting multiple frames in uart stream. Since we only have one slip frame buffer.

Here it is as it currently stands

slipif_poll(struct netif *netif)
{
  u8_t c;
  struct slipif_priv *priv;

  LWIP_ASSERT("netif != NULL", (netif != NULL));
  LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));

  priv = (struct slipif_priv *)netif->state;

  while (sio_tryread(priv->sd, &c, 1) > 0) {
    slipif_rxbyte_input(netif, c);
  }
}

Annotated:

/**
 * Polls the serial device and feeds the IP layer with incoming packets.
 *
 * @param netif The lwip network interface structure for this slipif
 */
void
slipif_poll(struct netif *netif)
{
  u8_t c; /* Byte Buffer */
  struct slipif_priv *priv = 0;

  /* Guards */
  LWIP_ASSERT("netif != NULL", (netif != NULL));
  LWIP_ASSERT("netif->state != NULL", (netif->state != NULL));

  /* serial device handle */
  priv = (struct slipif_priv *)netif->state;

  /* sio_tryread(fd serial device handler, pointer to data buffer, max length) -> byte count received */
  u32_t bytes_count_received = sio_tryread(priv->sd, &c, 1);
  while ( bytes_count_received > 0)
  { /* Push Bytes into */
    slipif_rxbyte_input(netif, c); /* slipif_rxbyte_input(network interface, received character) */
  }
}

In ./network/slip/slip_sio.c it shows that we slip uart has receive buffer of 512b

static uint8_t recv_buffer[512];
static bool wait = false;

static uart_config_t slip_uart = {
  .baud = BAUD_RATE,
  .recv_buffer = { .s_elem = 1, .n_elem = sizeof(recv_buffer), .buffer = recv_buffer }
};

sio_tryread() --> slipif_poll() --> "char" --> slipif_rxbyte_input(,char) --> "char" --> slipif_rxbyte(,char) --> Pointer to full packet (NULL if not yet) --> to netif->input() called by slipif_rxbyte_input()


We can try adding a buffer at slipif_poll(), but the issue is that we still have the delay of the main loop. A combination of:

markjasonanderson commented 7 years ago

The notes here are on the wrong track. This is as simple as adding a packet queue into slip_socket.c

Issue is now fixed.