From 5b742d783e7b4ba919e278044960e477da19434d Mon Sep 17 00:00:00 2001 From: ChrisPHL Date: Thu, 16 Dec 2021 15:38:22 +0100 Subject: [PATCH 1/2] Unconventional patch for sorting out empty output lines (produced by commented and empty lines) when reading script files. --- cocomm/cocomm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cocomm/cocomm.c b/cocomm/cocomm.c index 3b8e5e8..182cfbe 100644 --- a/cocomm/cocomm.c +++ b/cocomm/cocomm.c @@ -427,7 +427,8 @@ int main (int argc, char *argv[]) { while(fgets(commBuf, BUF_SIZE, fp) != NULL) { size_t len = strlen(commBuf); - if (len < 1) continue; + if (len < 2) continue; // Sort out lines like "\n". + if (commBuf[0] == '#') continue; // Sort out lines starting with '#'. // send command if (write(fd_gtw, commBuf, len) != len) { /* blocking function */ From b47560caf02d53b1a2c1605773b3c6f7006bce60 Mon Sep 17 00:00:00 2001 From: ChrisPHL Date: Wed, 22 Dec 2021 12:14:37 +0100 Subject: [PATCH 2/2] Simple pause command logic for cocomm script files added. --- cocomm/cocomm.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cocomm/cocomm.c b/cocomm/cocomm.c index 182cfbe..cb45265 100644 --- a/cocomm/cocomm.c +++ b/cocomm/cocomm.c @@ -429,6 +429,22 @@ int main (int argc, char *argv[]) { size_t len = strlen(commBuf); if (len < 2) continue; // Sort out lines like "\n". if (commBuf[0] == '#') continue; // Sort out lines starting with '#'. + if (commBuf[0] == 'P') { + // Pause script execution for given time [ms] in case line starts with 'P' followed by an unsigned integer. + uint32_t millis = 1; + uint8_t p = '\0'; + uint32_t result = sscanf(commBuf, "%c %u", &p, &millis); + fprintf(errStream, "result = %u\n", result); + if (2 != result) { + fprintf(errStream, "syntax error on 'P'ause command\n"); + fflush(errStream); + exit(EXIT_FAILURE); + } + fprintf(stdout, "pause %u msec...\n", millis); + fflush(stdout); + usleep(millis * 1000); + continue; + } // send command if (write(fd_gtw, commBuf, len) != len) { /* blocking function */