diff --git a/ascon.c b/ascon.c index 6943f813..233478d1 100644 --- a/ascon.c +++ b/ascon.c @@ -266,8 +266,7 @@ int AsconReadChar(int fd, char *chr) if (ret <= 0) return ret; ret = recv(fd, chr, 1, 0); - /* PrintChar(*chr); */ - fflush(stdout); + /* PrintChar(*chr); fflush(stdout); */ if (ret > 0) return 1; if (ret == 0) { diff --git a/binprot.c b/binprot.c index f0ce52f8..99261994 100644 --- a/binprot.c +++ b/binprot.c @@ -53,18 +53,19 @@ * modbus-crc: CRC-16-IBM, order: lo,hi * keller-crc: CRC-16-IBM, order: hi,lo * sycon-crc: sort of mod 256 checksum, byte stuffing included (no float allowed) + * chksum-crc: simple 8bit checksum */ typedef enum {intType, hexType, floatType, skipType, codeType, crcType, dumpType, errorType} BinDataType; // dumpType, errorType must be the last items -typedef enum {modbusCrc, kellerCrc, rsportCrc, syconCrc} CrcAlgorithm; +typedef enum {modbusCrc, kellerCrc, rsportCrc, syconCrc, chksumCrc} CrcAlgorithm; typedef struct { CrcAlgorithm crcAlgorithm; pDynString inp; - char *nextFmt; + char *nextFmt; // position of next format token pDynString result; int expectedChars; BinDataType type; @@ -135,6 +136,23 @@ static int calc_crc8(char *inp, int inpLen) } return crc; } +/*----------------------------------------------------------------------------*/ +static int calc_chksum(char *inp, int inpLen) +{ +/** simple 8bit checksum + */ + + unsigned char crc = 0; + unsigned char data; + int n; + + while (inpLen--) { + data = *(unsigned char *) inp; + crc += data; + inp++; + } + return crc; +} /*----------------------------------------------------------------------------*/ int BinReadItem(Ascon *a) { @@ -154,7 +172,11 @@ int BinReadItem(Ascon *a) { if (strcasecmp(item, "crc") == 0) { p->type = crcType; - p->expectedChars = 2; + if (p->crcAlgorithm == chksumCrc) { + p->expectedChars = 1; + } else { + p->expectedChars = 2; + } p->nextFmt += valen; return 1; } else if (strncasecmp(item, "int", 3) == 0) { @@ -281,6 +303,10 @@ int BinHandler(Ascon *a) { DynStringConcatChar(dyn, crc % 256); DynStringConcatChar(dyn, crc / 256); break; + case chksumCrc: + crc = calc_chksum(GetCharArray(dyn), l); + DynStringConcatChar(dyn, crc % 256); + break; case rsportCrc: crc = calc_crc8(GetCharArray(dyn), l); DynStringConcatChar(dyn, crc); @@ -509,6 +535,11 @@ int BinHandler(Ascon *a) { DynStringConcat(p->result, "badCRC "); } break; + case chksumCrc: + if (calc_chksum(str, l-1) != (unsigned char)str[l-1]) { + DynStringConcat(p->result, "badCRC "); + } + break; case kellerCrc: i = str[l-2]; str[l-2] = str[l-1]; @@ -560,6 +591,8 @@ static int BinInit(Ascon * a, SConnection * con, int argc, char *argv[]) p->crcAlgorithm = syconCrc; } else if (strcasecmp(argv[2], "rsport-crc") == 0) { p->crcAlgorithm = rsportCrc; + } else if (strcasecmp(argv[2], "chksum-crc") == 0) { + p->crcAlgorithm = chksumCrc; } else if (strcasecmp(argv[2], "modbus-crc") != 0) { SCPrintf(con, eError, "ERROR: unknown crc-algorithm %s", argv[2]); a->private = NULL; diff --git a/drive.c b/drive.c index e49aef99..d5be804d 100644 --- a/drive.c +++ b/drive.c @@ -517,7 +517,7 @@ int MakeDrive(SConnection * pCon, SicsInterp * pSics, void *pData, } if (argc > 3) { - iRet = AddCommand(pSics, argv[2], MoveWrapper, NULL, NULL); + iRet = AddCommand(pSics, argv[3], MoveWrapper, NULL, NULL); } else { iRet = AddCommand(pSics, "mv", MoveWrapper, NULL, NULL); } diff --git a/task.c b/task.c index 396f782d..6497dd5f 100644 --- a/task.c +++ b/task.c @@ -526,7 +526,7 @@ char *TaskDescription(pTaskHead it) length = strlen(result); tm = localtime((const time_t *)&it->start_time); - strftime(result+length,100,"%F-%k-%m-%S",tm); + strftime(result+length,100,"%F-%H-%M-%S",tm); length = strlen(result); snprintf(result+length,120-20,"|%ld", it->lID); length = strlen(result);