From 382c7d4184a797fd608fda99fca3ae66eb6ee47e Mon Sep 17 00:00:00 2001 From: anicic Date: Tue, 6 Mar 2012 10:53:08 +0000 Subject: [PATCH] 1. New EPICS version 3.14.12 2. Get rid of warnings because new EPICS version and new targets --- devS7plcFW.c | 110 ++++++++++++++++++++++++++++----------------------- drvS7plcFW.c | 24 ++++++----- 2 files changed, 75 insertions(+), 59 deletions(-) diff --git a/devS7plcFW.c b/devS7plcFW.c index 900e1c7..7631269 100644 --- a/devS7plcFW.c +++ b/devS7plcFW.c @@ -1,8 +1,8 @@ /* $Author: anicic $ */ -/* $Date: 2010/09/22 13:44:37 $ */ -/* $Id: devS7plcFW.c,v 1.1 2010/09/22 13:44:37 anicic Exp $ */ +/* $Date: 2012/03/06 10:53:08 $ */ +/* $Id: devS7plcFW.c,v 1.2 2012/03/06 10:53:08 anicic Exp $ */ /* $Name: $ */ -/* $Revision: 1.1 $ */ +/* $Revision: 1.2 $ */ #include #include @@ -46,10 +46,20 @@ #endif /* suppress compiler warning concerning long long with __extension__ */ -#ifndef __GNUC__ +#if (!defined __GNUC__) || (__GNUC__ < 2) || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) #define __extension__ #endif +#ifndef epicsUInt64 +#if (LONG_MAX > 2147483647L) +#define epicsUInt64 unsigned long +#define CONV64 "%016lx" +#else +#define epicsUInt64 unsigned long long +#define CONV64 "%016llx" +#endif +#endif + #define S7MEM_TIME 100 typedef struct { /* Private structure to save IO arguments */ @@ -63,7 +73,7 @@ typedef struct { /* Private structure to save IO arguments */ } S7memPrivate_t; static char cvsid_devS7plcFW[] = - "$Id: devS7plcFW.c,v 1.1 2010/09/22 13:44:37 anicic Exp $"; + "$Id: devS7plcFW.c,v 1.2 2012/03/06 10:53:08 anicic Exp $"; STATIC long s7plcFWReport(); @@ -1686,8 +1696,8 @@ STATIC long s7plcFWReadAi(aiRecord *record) epicsUInt16 uval16; epicsInt32 sval32; epicsUInt32 uval32; - epicsFloat32 val32; - epicsFloat64 val64; + union {epicsFloat32 f; epicsUInt32 i; } val32; + __extension__ union {epicsFloat64 f; epicsUInt64 i; } val64; if (!priv) { @@ -1744,15 +1754,15 @@ STATIC long s7plcFWReadAi(aiRecord *record) status = s7plcFWRead(priv->station, priv->offs, 4, &val32); s7plcFWDebugLog(3, "ai %s: read 32bit %04x = %g\n", - record->name, *(unsigned int*) &val32, val32); - val64 = val32; + record->name, val32.i, val32.f); + val64.f = val32.f; floatval = TRUE; break; case epicsFloat64T: status = s7plcFWRead(priv->station, priv->offs, 8, &val64); __extension__ s7plcFWDebugLog(3, "ai %s: read 64bit %08Lx = %g\n", - record->name, *(long long*) &val64, val64); + record->name, val64.i, val64.f); floatval = TRUE; break; default: @@ -1777,14 +1787,14 @@ STATIC long s7plcFWReadAi(aiRecord *record) if (floatval) { /* emulate scaling */ - if (record->aslo != 0.0) val64 *= record->aslo; - val64 += record->aoff; + if (record->aslo != 0.0) val64.f *= record->aslo; + val64.f += record->aoff; if (record->udf) - record->val = val64; + record->val = val64.f; else /* emulate smoothing */ record->val = record->val * record->smoo + - val64 * (1.0 - record->smoo); + val64.f * (1.0 - record->smoo); record->udf = FALSE; return 2; } @@ -1858,8 +1868,8 @@ STATIC long s7plcFWWriteAo(aoRecord *record) epicsUInt8 rval8; epicsUInt16 rval16; epicsUInt32 rval32; - epicsFloat32 val32; - epicsFloat64 val64; + union {epicsFloat32 f; epicsUInt32 i; } val32; + __extension__ union {epicsFloat64 f; epicsUInt64 i; } val64; if (!priv) { @@ -1926,21 +1936,21 @@ STATIC long s7plcFWWriteAo(aoRecord *record) break; case epicsFloat32T: /* emulate scaling */ - val32 = record->oval - record->aoff; - if (record->aslo != 0) val32 /= record->aslo; + val32.f = record->oval - record->aoff; + if (record->aslo != 0) val32.f /= record->aslo; - s7plcFWDebugLog(2, "ao %s: write 32bit %08x\n", - record->name, *(epicsInt32*)&val32); + s7plcFWDebugLog(2, "ao %s: write 32bit %08x = %g\n", + record->name, val32.i, val32.f); status = s7plcFWWrite(priv->station, priv->offs, 4, &val32); break; case epicsFloat64T: /* emulate scaling */ - val64 = record->oval - record->aoff; - if (record->aslo != 0) val64 /= record->aslo; + val64.f = record->oval - record->aoff; + if (record->aslo != 0) val64.f /= record->aslo; - __extension__ s7plcFWDebugLog(2, "ao %s: write 64bit %016Lx\n", - record->name, *(long long*)&val64); + __extension__ s7plcFWDebugLog(2, "ao %s: write 64bit " CONV64 " = %g\n", + record->name, val64.i, val64.f); status = s7plcFWWrite(priv->station, priv->offs, 8, &val64); break; @@ -2413,8 +2423,8 @@ STATIC long s7plcFWWriteCalcout(calcoutRecord *record) epicsInt8 sval8; epicsInt16 sval16; epicsInt32 sval32; - epicsFloat32 val32; - epicsFloat64 val64; + union {epicsFloat32 f; epicsUInt32 i; } val32; + __extension__ union {epicsFloat64 f; epicsUInt64 i; } val64; if (!priv) { @@ -2424,73 +2434,73 @@ STATIC long s7plcFWWriteCalcout(calcoutRecord *record) return -1; } assert(priv->station); - val64 = record->oval; + val64.f = record->oval; switch (priv->dtype) { case epicsInt8T: - sval8 = val64; - if (val64 > priv->hwHigh) sval8 = priv->hwHigh; - if (val64 < priv->hwLow) sval8 = priv->hwLow; + sval8 = val64.f; + if (val64.f > priv->hwHigh) sval8 = priv->hwHigh; + if (val64.f < priv->hwLow) sval8 = priv->hwLow; s7plcFWDebugLog(2, "calcout %s: write 8bit %02x\n", record->name, sval8 & 0xff); status = s7plcFWWrite(priv->station, priv->offs, 1, &sval8); break; case epicsUInt8T: - uval8 = val64; - if (val64 > priv->hwHigh) uval8 = priv->hwHigh; - if (val64 < priv->hwLow) uval8 = priv->hwLow; + uval8 = val64.f; + if (val64.f > priv->hwHigh) uval8 = priv->hwHigh; + if (val64.f < priv->hwLow) uval8 = priv->hwLow; s7plcFWDebugLog(2, "calcout %s: write 8bit %02x\n", record->name, uval8 & 0xff); status = s7plcFWWrite(priv->station, priv->offs, 1, &uval8); break; case epicsInt16T: - sval16 = val64; - if (val64 > priv->hwHigh) sval16 = priv->hwHigh; - if (val64 < priv->hwLow) sval16 = priv->hwLow; + sval16 = val64.f; + if (val64.f > priv->hwHigh) sval16 = priv->hwHigh; + if (val64.f < priv->hwLow) sval16 = priv->hwLow; s7plcFWDebugLog(2, "calcout %s: write 16bit %04x\n", record->name, sval16 & 0xffff); status = s7plcFWWrite(priv->station, priv->offs, 2, &sval16); break; case epicsUInt16T: - uval16 = val64; - if (val64 > priv->hwHigh) uval16 = priv->hwHigh; - if (val64 < priv->hwLow) uval16 = priv->hwLow; + uval16 = val64.f; + if (val64.f > priv->hwHigh) uval16 = priv->hwHigh; + if (val64.f < priv->hwLow) uval16 = priv->hwLow; s7plcFWDebugLog(2, "calcout %s: write 16bit %04x\n", record->name, uval16 & 0xffff); status = s7plcFWWrite(priv->station, priv->offs, 2, &uval16); break; case epicsInt32T: - sval32 = val64; - if (val64 > priv->hwHigh) sval32 = priv->hwHigh; - if (val64 < priv->hwLow) sval32 = priv->hwLow; + sval32 = val64.f; + if (val64.f > priv->hwHigh) sval32 = priv->hwHigh; + if (val64.f < priv->hwLow) sval32 = priv->hwLow; s7plcFWDebugLog(2, "calcout %s: write 32bit %08x\n", record->name, sval32); status = s7plcFWWrite(priv->station, priv->offs, 4, &sval32); break; case epicsUInt32T: - uval32 = val64; - if (val64 > priv->hwHigh) uval32 = priv->hwHigh; - if (val64 < priv->hwLow) uval32 = priv->hwLow; + uval32 = val64.f; + if (val64.f > priv->hwHigh) uval32 = priv->hwHigh; + if (val64.f < priv->hwLow) uval32 = priv->hwLow; s7plcFWDebugLog(2, "calcout %s: write 32bit %08x\n", record->name, uval32); status = s7plcFWWrite(priv->station, priv->offs, 4, &uval32); break; case epicsFloat32T: - val32 = val64; - s7plcFWDebugLog(2, "calcout %s: write 32bit %08x\n", - record->name, *(epicsInt32*)&val32); + val32.f = val64.f; + s7plcFWDebugLog(2, "calcout %s: write 32bit %08x = %g\n", + record->name, val32.i, val32.f); status = s7plcFWWrite(priv->station, priv->offs, 4, &val32); break; case epicsFloat64T: - __extension__ s7plcFWDebugLog(2, "calcout %s: write 64bit %016Lx\n", - record->name, *(long long*)&val64); + __extension__ s7plcFWDebugLog(2, "calcout %s: write 64bit " CONV64 " = %g\n", + record->name, val64.i, val64.f); status = s7plcFWWrite(priv->station, priv->offs, 8, &val64); break; diff --git a/drvS7plcFW.c b/drvS7plcFW.c index 119c781..83609b8 100644 --- a/drvS7plcFW.c +++ b/drvS7plcFW.c @@ -1,7 +1,7 @@ -/* $Date: 2010/09/22 13:44:37 $ */ -/* $Id: drvS7plcFW.c,v 1.1 2010/09/22 13:44:37 anicic Exp $ */ +/* $Date: 2012/03/06 10:53:08 $ */ +/* $Id: drvS7plcFW.c,v 1.2 2012/03/06 10:53:08 anicic Exp $ */ /* $Name: $ */ -/* $Revision: 1.1 $ */ +/* $Revision: 1.2 $ */ /* * NOTE: s7plcFWwriteThread -is not used for writting (we write direct), @@ -19,14 +19,20 @@ #include #include -#ifdef __vxworks +#if defined(vxWorks) || defined(__vxworks) #include #include +#include #include +#define in_addr_t unsigned long #else #include #endif +#ifdef __rtems__ +#include +#endif + #include #include #include @@ -62,7 +68,7 @@ #define RECONNECT_DELAY 10.0 /* delay before reconnect [s] */ static char cvsid[] __attribute__((unused)) = -"$Id: drvS7plcFW.c,v 1.1 2010/09/22 13:44:37 anicic Exp $"; +"$Id: drvS7plcFW.c,v 1.2 2012/03/06 10:53:08 anicic Exp $"; STATIC long s7plcFWIoReport(int level); STATIC long s7plcFWInit(); @@ -623,7 +629,7 @@ STATIC int s7plcFWdoFetch(s7plcFWStation *station, int org, int db, int offs, in req[0xd] = s7len % 0x100; epicsMutexMustLock(station->fetchIo); - status = write(station->fetchSocket, req, 16); + status = write(station->fetchSocket, (void *) req, 16); epicsMutexUnlock(station->fetchIo); if (status != 16) { s7plcFWDebugLog(3, "s7plcFWdoFetch: write 16 byte header failed, returned status = %d, errno = %d\n", status, errno); @@ -637,7 +643,7 @@ STATIC int s7plcFWdoFetch(s7plcFWStation *station, int org, int db, int offs, in } epicsMutexMustLock(station->fetchIo); - status = read(station->fetchSocket, ack, 16); + status = read(station->fetchSocket, (void *) ack, 16); epicsMutexUnlock(station->fetchIo); if(status < 16) { s7plcFWDebugLog(3, "s7plcFWdoFetch: Got too few bytes (%d) ACK from PLC!\n", status); @@ -701,7 +707,7 @@ STATIC int s7plcFWdoWrite(s7plcFWStation *station, char *data, int offs, int len req[0xd] = s7len % 0x100; epicsMutexMustLock(station->writeIo); - status = write(station->writeSocket, req, 16); + status = write(station->writeSocket, (void *) req, 16); dstatus = write(station->writeSocket, data, len); epicsMutexUnlock(station->writeIo); @@ -724,7 +730,7 @@ STATIC int s7plcFWdoWrite(s7plcFWStation *station, char *data, int offs, int len } epicsMutexMustLock(station->writeIo); - if((status = read(station->writeSocket, ack, 16)) < 16) { + if((status = read(station->writeSocket, (void *) ack, 16)) < 16) { s7plcFWDebugLog(3, "Got too few bytes (%d) ACK from PLC!\n", status); /* printf("AD84: s7plcFWdoWrite: read too few bytes (%d) ACK from PLC!\n", status); */ epicsMutexUnlock(station->writeIo);