0

I need to implement a specific protocol over a serial device. I have already done the message contructor and have a list of bytes ready to be send. The issue that I am having is that I am not able to verify if I am correctly sending the bytes into the /dev/ttyS2 interface. My serial messages follow the structure PATTERN + MESSAGE

I am able to read from the serial device and filter some received known messages by doing:

cat /dev/ttyS2 | grep PATTERN

In my program (code below), if I send my message I amb not able to see my frames using the previous command:

static FILE * file_stream = NULL;
static int file_des = 0;

static void printSampleMessage(void) {
struct termios SerialPortSettings; /* Create the structure                          */

/* Open linux device */
file_des = open("/dev/ttyS2", O_RDWR | O_NOCTTY);

/*---------- Setting the Attributes of the serial port using termios structure --------- */

tcgetattr(file_des, &SerialPortSettings);   /* Get the current attributes of the Serial port */

/* Setting the Baud rate */
cfsetispeed(&SerialPortSettings,B38400); /* Set Read  Speed as 38400                       */
cfsetospeed(&SerialPortSettings,B38400); /* Set Write Speed as 38400                       */

/* 8N1 Mode */
SerialPortSettings.c_cflag &= ~PARENB;   /* Disables the Parity Enable bit(PARENB),So No Parity   */
SerialPortSettings.c_cflag &= ~CSTOPB;   /* CSTOPB = 2 Stop bits,here it is cleared so 1 Stop bit */
SerialPortSettings.c_cflag &= ~CSIZE;    /* Clears the mask for setting the data size             */
SerialPortSettings.c_cflag |=  CS8;      /* Set the data bits = 8                                 */

SerialPortSettings.c_cflag &= ~CRTSCTS;       /* No Hardware flow Control                         */
SerialPortSettings.c_cflag |= CREAD | CLOCAL; /* Enable receiver,Ignore Modem Control lines       */


SerialPortSettings.c_iflag &= ~(IXON | IXOFF | IXANY);          /* Disable XON/XOFF flow control both i/p and o/p */
SerialPortSettings.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG);  /* Non Cannonical mode                            */

SerialPortSettings.c_oflag &= ~OPOST; /*No Output Processing RAW mode*/


if((tcsetattr(file_des,TCSANOW,&SerialPortSettings)) != 0) {/* Set the attributes to the termios structure*/
} else {
}

/* Obtain file stream descriptor */
file_stream = fdopen(file_des, "r+");
fputs ( "PATTERN+MESSAGE", file_stream);
}

However, I am not able to see my own message when using the cat /dev/ttyS2 | grep PATTERN command. How can I check if I am actually sending my PATTERN+ message in the serial device?

I am quite limited in terms of program options. My setup is an embedded linux communicating with another microcontroller within a board (no test point to connect a physical sniffer) and no minicom available as the linux distribution I am using is very basic, I can not just apt-get install XX

Ricard Molins
  • 408
  • 1
  • 6
  • 20
  • [This Q&A](https://stackoverflow.com/a/57157995/11476836) might help. – Marcos G. Sep 30 '19 at 17:28
  • 1
    "Reliable" protocols do not *"verify if I am correctly sending the bytes"*. The receiver of the message verifies the integrity of the received data (using a checksum or even better CRC), and responds with an ACK or NAK. IOW you *"verify"* that the message has been received, not that it has been sent. – sawdust Sep 30 '19 at 20:12
  • I am developing the protocol, therefore before trying to even implement the receiving part I want to assert that the sender is correct. Trying to read from a prototype device the bytes I am sending from another prototype device is in my opinion a bad aproach to development as there are multiple possibe points of failure – Ricard Molins Oct 01 '19 at 05:40
  • @MarcosG. I am working on an embedded linux platform and interceptty is not aviable. – Ricard Molins Oct 01 '19 at 06:57
  • Your "explanation" about `cat /dev/ttyS2 ...` fails to describe what you are doing. Do you expect to read what was already transmitted? You cannot *"check if I am actually sending my PATTERN+ message **in** the serial device"*. You have to go external to the UART, i.e. actually connect something to the transmit line. You could do a loopback, but it's a half-baked test because TX and RX share configuration in the UART and the line settings aren't tested. BTW `Busybox` can be built with a `picocom`. – sawdust Oct 01 '19 at 08:28
  • *"My setup (has) no test point to connect a physical sniffer"* -- If the SoC and uP are separate chips then you need to look for exposed circuit trace. If the interprocessor link is truly not accessible, then IMO you have a poorly designed board. Making the board testable for both HW and SW should have been a goal. – sawdust Oct 01 '19 at 08:38

0 Answers0