From: b Date: Mon, 14 Dec 2020 23:20:08 +0000 (+0100) Subject: more checks and other X-Git-Tag: v1.0 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=6b4101c9ce9e6b0a07dd62168082edc631161661;p=staf%2Flibstaf more checks and other --- diff --git a/libstaf.c b/libstaf.c index c848abb..fe24457 100644 --- a/libstaf.c +++ b/libstaf.c @@ -1,7 +1,7 @@ -// SilentTimer Action Figure communication library +// SilentTimer Action Figure communication library, v1.0 // libstaf.c // -// 03.07.2020 +// 14.12.2020 // Copyright (C) 2020 Balthasar Szczepański // // This program is free software: you can redistribute it and/or modify @@ -342,7 +342,7 @@ int stafExecuteCommand (int fd, uint8_t *event, uint8_t command, uint8_t *dataOu return status; } - tcflush(fd,TCIOFLUSH); + tcflush(fd,TCIFLUSH); status = stafSendFrame(fd, command, dataOut, lengthOut); if(status != 0) @@ -543,6 +543,9 @@ int stafGetDisplay (int fd, uint8_t *event, uint8_t *pinout, uint32_t *display) if (display != NULL) { + if (pinout==NULL) + return ERR_MISSING_POINTER; + *display = 0; for(i=0; i<4; ++i) { @@ -563,6 +566,9 @@ int stafSetDisplay (int fd, uint8_t *event, uint8_t *pinout, uint32_t display) uint8_t outdata[4]; int i,j; + if (pinout==NULL) + return ERR_MISSING_POINTER; + for(i=0; i<4; ++i) { outdata[i]=0xff; @@ -1030,7 +1036,8 @@ int stafGetDebugValue (int fd, uint8_t *event, uint8_t address, uint8_t *value, if (status != 0) return status; - *value = indata[0]; + if (value != NULL) + *value = indata[0]; if (restoreState) { @@ -1265,7 +1272,7 @@ int stafCalculate (int fd, uint8_t *event, float a, float b, uint8_t operation, return status; } - outdata[4] |= operation & calc_mask; + outdata[4] = operation & calc_mask; status=stafEncodeCalculationArgument (b, outdata, &flags); if (status != 0) diff --git a/libstaf.h b/libstaf.h index 5531cbb..e094ea0 100644 --- a/libstaf.h +++ b/libstaf.h @@ -1,5 +1,5 @@ // SilentTimer Action Figure communication library -// libstaf.h +// libstaf.h, v1.0 // // 03.07.2020 // Copyright (C) 2020 Balthasar Szczepański diff --git a/test.c b/test.c index 08964fb..dea4719 100644 --- a/test.c +++ b/test.c @@ -4,7 +4,7 @@ #include "libstaf.h" -//just a test... +//just a test of all functions... int main (int argc, char *argv[]) { @@ -30,7 +30,7 @@ int main (int argc, char *argv[]) struct tm *now; - fd = stafConnect("/dev/ttyUSB0"); + fd = stafConnect("/dev/ttyS0"); printf("Connect: %d\n",fd); if(fd<0) @@ -249,6 +249,8 @@ int main (int argc, char *argv[]) stafSetYear(fd, NULL, now->tm_year+1900, 0); stafClearAlarm(fd, NULL, 0); + // usleep(3000000); + a = stafSetMode(fd, NULL, mode_reset); printf("Reset: %d\n",a);