mercredi 6 mai 2020

C/C++ termios configuration to force system controller response in one line

I'm working on my first app that communicates with a system controller and I'm not familiar at all with how termios works.

The communication with the system controller is made through ttyS1 with telegrams following this pattern:

Start byte, Function Byte, Number of data bytes, N data bytes if needed, Checksum and End byte

For example, to query the firmware version, the query is: 0x01, 0x04(Query firmware byte), 0x00(0 data bytes), 0xXX(Checksum) 0x04 (End byte)

I have managed myself to write to system controller and get a response for it. But for some responses, i get the response divided in two instead of receiving once only. For instance, for query firmware, I receive:

New data read
01FFFFFFC4063735303830
New data read
320004

I'm not sure at all what all that FF are but the rest are the expected bytes: 01(Start) C4(Repsonse firmware) 06(6 data bytes) 37(1) 35(2) 30(3) 38(4) 30(5) 32(6) 00(Checksum) 04(End byte).

It seems that the line is break in the 8 byte.

My termios configuration looks like this:

  struct termios s_termios;
  int rrr = tcgetattr(i32_fd, & s_termios);

  //! Set input baudrate.
  cfsetispeed(& s_termios, B9600);
  //! Set output baudrate.
  cfsetospeed(& s_termios, B9600);

  //! Set other configuration values.
  s_termios.c_cflag &= ~PARENB;   //!< No parity.
  s_termios.c_cflag &= ~CSTOPB;   //!< 1 stop bit.
  s_termios.c_cflag &= ~CSIZE;    //!< Apply mask to set data bits.
  s_termios.c_cflag |= CS8;      //!< Mask to set 8 data bits.
  s_termios.c_cflag |= CLOCAL;   //!< Don't change the owner of the port.
  s_termios.c_cflag |= CREAD;    //!< Enable data reception.
  s_termios.c_cflag &= ~CRTSCTS;  //!< No hardware flow control.
  s_termios.c_oflag &= ~OPOST;    //!< Raw output.
  s_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  s_termios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
                           | INLCR | IGNCR | ICRNL | IXON);

I have added the last two line to get the EOT(04) bytes in the response but additionally I would like to get the response in one line. Is there any flag that could help me to achieve this?

Aucun commentaire:

Enregistrer un commentaire