bruzzi | 7 Jun 2012 17:58

stm32: do I have to call tcp_write() even on error?


Hello,

I impelmented modbus over tcp using LwIP library. In case of modbus protocol
error i don't call tcp_write() function, is that correct?

This is my callback function on received packet. 
static void modbusserver_send(struct tcp_pcb *tpcb, struct
modbusserver_struct *es)
{
  struct pbuf *ptr;
  err_t wr_err = ERR_OK;

  while ((wr_err == ERR_OK) &&
         (es->p != NULL) && 
         (es->p->len <= tcp_sndbuf(tpcb)))
    {

      /* get pointer on pbuf from es structure */
      ptr = es->p;

      if (wr_err == ERR_OK)
	{
	  u16_t plen;

	  plen = ptr->len;

	  if (plen > PROTO_TRAMA_LEN) memcpy(ProtoStatus[PROTO_TCP].InBuf,
ptr->payload, PROTO_TRAMA_LEN);
          else memcpy(ProtoStatus[PROTO_TCP].InBuf, ptr->payload, plen);
(Continue reading)

Kieran Mansley | 19 Jun 2012 21:17

Re: stm32: do I have to call tcp_write() even on error?


On 7 Jun 2012, at 18:11, bruzzi wrote:

> I impelmented modbus over tcp using LwIP library. In case of modbus protocol
> error i don't call tcp_write() function, is that correct?

I'm not sure - that's really up to what behavior the modbus protocol dictates (and I know nothing about
modbus), but assuming an error means that you couldn't decode the message then doing nothing in reply
seems reasonable.

Kieran

Gmane