Compare commits

..

42 Commits

Author SHA1 Message Date
56ef0651f2 fix for BSD Linux 2014-04-07 11:55:36 +00:00
9b9726b800 patchlevel fixed 2013-11-06 13:29:42 +00:00
b139221f0b error messages improved 2013-11-06 10:22:51 +00:00
b0ab8a7a8b write error message on write timeout 2013-11-06 09:52:39 +00:00
ddac589676 newline in report output fixed 2013-11-06 09:44:18 +00:00
5b380cdaad No connection checking before locking device. Multi-devices (GPIB) behave strangely. Get an error when device is disconnected. 2013-11-05 14:48:53 +00:00
cc9adc77fa patchlevel updated 2013-10-23 14:38:28 +00:00
2b38f7bcfa . 2013-10-23 14:36:35 +00:00
0ceada70b5 status information added 2013-10-23 14:35:08 +00:00
7bf91b403d status information added
error messages improved
dont mark device as BusOwner when locking fails
2013-10-23 14:34:53 +00:00
bf5c359649 status information added
use class for status strings to make array overrun impossible
2013-10-23 14:33:15 +00:00
c41ac44bd1 typo in comment 2013-10-23 14:31:35 +00:00
e36013d64e error messages improved
Do not queue lock request when not connected
Do not call lock callback when unlock fails
2013-10-23 14:31:00 +00:00
9e48ad3e61 typo 2013-10-02 13:09:17 +00:00
054e74d04a Do not connect unrequested.
Do not register for int/uint interrupts without need.
2013-09-20 12:06:56 +00:00
5f6319ed3d stay at version 2.6 2013-09-20 09:52:43 +00:00
2f39622a57 Error Message improved 2013-09-20 09:44:26 +00:00
7801119215 fix for cygwin 2013-06-13 15:21:12 +00:00
a6696cae49 fixes for windows 2013-06-13 15:13:53 +00:00
40b52167aa lock timeout error message added 2013-06-13 15:12:06 +00:00
814e3d53a3 version update 2013-05-16 08:49:30 +00:00
6bd46e0470 *** empty log message *** 2013-05-16 08:47:16 +00:00
d5cda13f6f version updated 2013-05-16 08:45:49 +00:00
bfc8e6a9cd Handle inverted and negative checksums generically.
Get rid of ulong and uchar typedefs. use unsigned int unstead of ulolg for return types.
2013-05-16 08:31:33 +00:00
73cba130c3 use ssize_t for signed index types. Win has no ssize_t, use ptrdiff_t instead.
use P instead of S as shortcut for PRINTF_SIZE_T_PREFIX because some OK already use S.
2013-05-16 08:28:34 +00:00
c09bc44aa4 use ssize_t for signed index types. Win has no ssize_t, use ptrdiff_t instead. 2013-05-16 08:27:24 +00:00
b907e3f469 changed shortcut for PRINTF_SIZE_T_PREFIX from S to P. Some OS use S already. 2013-05-16 08:26:01 +00:00
8c3bed09e4 more debug
init I/O Intr scanning only if init_record did not fail
2013-05-16 08:24:40 +00:00
4c99b82bb7 make name() public 2013-05-16 08:22:56 +00:00
a6d72761b9 more debug 2013-05-16 08:22:13 +00:00
6c504d30cf use size_t and ssize_t in streamBuffer 2013-04-26 12:21:51 +00:00
1c814a451b new format: %-<> prints "poor man's hex": 0x30 - 0x3f characters 2013-04-26 09:56:39 +00:00
daafc125c3 bug in debug output fixed 2013-04-26 09:56:04 +00:00
63f680bdc1 allow selecting asyn version 2013-04-24 14:27:39 +00:00
e88a327957 *** empty log message *** 2013-04-24 14:27:09 +00:00
223c71bc68 fix the fake flush: break early when no bytes are left 2013-04-24 14:25:52 +00:00
14a04fd200 handle errors in flushing read correctly 2013-04-15 07:03:49 +00:00
dc85511fe9 missing space ckeck in event command 2013-01-21 10:03:27 +00:00
d0b8d3f585 problems with 3.13 solved 2012-11-20 10:51:40 +00:00
97652917c9 Can't poll GPIB. 2012-11-08 09:27:21 +00:00
c171a62f93 Fixes for 3.15 2012-11-08 09:26:57 +00:00
c7c28e7fa2 compiler warning removed 2012-10-08 12:32:44 +00:00
19 changed files with 1259 additions and 350 deletions

View File

@ -261,7 +261,7 @@ number in the range of <code>-128</code> to <code>255</code>,
or <code>-0200</code> to <code>0377</code>, respectively. or <code>-0200</code> to <code>0377</code>, respectively.
</p> </p>
<p> <p>
<em>StreamDevice</em> also recordgnizes the ASCII symbolic names <em>StreamDevice</em> also recognizes the ASCII symbolic names
(not case sensitive) for several byte codes:<br> (not case sensitive) for several byte codes:<br>
<code>NUL </code>(= <code>0x00</code>) <em>null</em><br> <code>NUL </code>(= <code>0x00</code>) <em>null</em><br>
<code>SOH </code>(= <code>0x01</code>) <em>start of heading</em><br> <code>SOH </code>(= <code>0x01</code>) <em>start of heading</em><br>

View File

@ -22,11 +22,6 @@
#include "StreamError.h" #include "StreamError.h"
#include "StreamBuffer.h" #include "StreamBuffer.h"
#include <epicsVersion.h>
#ifdef BASE_VERSION
#define EPICS_3_13
#endif
#ifdef EPICS_3_13 #ifdef EPICS_3_13
#include <assert.h> #include <assert.h>
#include <wdLib.h> #include <wdLib.h>
@ -203,7 +198,7 @@ class AsynDriverInterface : StreamBusInterface
// local methods // local methods
void timerExpired(); void timerExpired();
bool connectToBus(const char* busname, int addr); bool connectToBus(const char* portname, int addr);
void lockHandler(); void lockHandler();
void writeHandler(); void writeHandler();
void readHandler(); void readHandler();
@ -247,7 +242,7 @@ class AsynDriverInterface : StreamBusInterface
public: public:
// static creator method // static creator method
static StreamBusInterface* getBusInterface(Client* client, static StreamBusInterface* getBusInterface(Client* client,
const char* busname, int addr, const char* param); const char* portname, int addr, const char* param);
}; };
RegisterStreamBusInterface(AsynDriverInterface); RegisterStreamBusInterface(AsynDriverInterface);
@ -255,6 +250,7 @@ RegisterStreamBusInterface(AsynDriverInterface);
AsynDriverInterface:: AsynDriverInterface::
AsynDriverInterface(Client* client) : StreamBusInterface(client) AsynDriverInterface(Client* client) : StreamBusInterface(client)
{ {
debug ("AsynDriverInterface(%s)\n", client->name());
pasynCommon = NULL; pasynCommon = NULL;
pasynOctet = NULL; pasynOctet = NULL;
intrPvtOctet = NULL; intrPvtOctet = NULL;
@ -266,20 +262,25 @@ AsynDriverInterface(Client* client) : StreamBusInterface(client)
eventMask = 0; eventMask = 0;
receivedEvent = 0; receivedEvent = 0;
peeksize = 1; peeksize = 1;
debug ("AsynDriverInterface(%s) createAsynUser\n", client->name());
pasynUser = pasynManager->createAsynUser(handleRequest, pasynUser = pasynManager->createAsynUser(handleRequest,
handleTimeout); handleTimeout);
assert(pasynUser); assert(pasynUser);
pasynUser->userPvt = this; pasynUser->userPvt = this;
#ifdef EPICS_3_13 #ifdef EPICS_3_13
debug ("AsynDriverInterface(%s) wdCreate()\n", client->name());
timer = wdCreate(); timer = wdCreate();
callbackSetCallback(expire, &timeoutCallback); callbackSetCallback(expire, &timeoutCallback);
callbackSetUser(this, &timeoutCallback); callbackSetUser(this, &timeoutCallback);
#else #else
debug ("AsynDriverInterface(%s) epicsTimerQueueActive::allocate(true)\n", client->name());
timerQueue = &epicsTimerQueueActive::allocate(true); timerQueue = &epicsTimerQueueActive::allocate(true);
assert(timerQueue); assert(timerQueue);
debug ("AsynDriverInterface(%s) timerQueue->createTimer()\n", client->name());
timer = &timerQueue->createTimer(); timer = &timerQueue->createTimer();
assert(timer); assert(timer);
#endif #endif
debug ("AsynDriverInterface(%s) done\n", client->name());
} }
AsynDriverInterface:: AsynDriverInterface::
@ -325,17 +326,19 @@ AsynDriverInterface::
} }
// interface function getBusInterface(): // interface function getBusInterface():
// do we have this bus/addr ? // do we have this port/addr ?
StreamBusInterface* AsynDriverInterface:: StreamBusInterface* AsynDriverInterface::
getBusInterface(Client* client, getBusInterface(Client* client,
const char* busname, int addr, const char*) const char* portname, int addr, const char*)
{ {
debug ("AsynDriverInterface::getBusInterface(%s, %s, %d)\n",
client->name(), portname, addr);
AsynDriverInterface* interface = new AsynDriverInterface(client); AsynDriverInterface* interface = new AsynDriverInterface(client);
if (interface->connectToBus(busname, addr)) if (interface->connectToBus(portname, addr))
{ {
debug ("AsynDriverInterface::getBusInterface(%s, %d): " debug ("AsynDriverInterface::getBusInterface(%s, %d): "
"new Interface allocated\n", "new interface allocated\n",
busname, addr); portname, addr);
return interface; return interface;
} }
delete interface; delete interface;
@ -347,7 +350,66 @@ getBusInterface(Client* client,
bool AsynDriverInterface:: bool AsynDriverInterface::
supportsEvent() supportsEvent()
{ {
return (pasynInt32 != NULL) || (pasynUInt32 != NULL); if (intrPvtInt32 || intrPvtUInt32) return true;
// look for interfaces for events
asynInterface* pasynInterface;
pasynInterface = pasynManager->findInterface(pasynUser,
asynInt32Type, true);
if (pasynInterface)
{
pasynInt32 = static_cast<asynInt32*>(pasynInterface->pinterface);
pvtInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL; // required for GPIB
if (pasynInt32->registerInterruptUser(pvtInt32, pasynUser,
intrCallbackInt32, this, &intrPvtInt32) == asynSuccess)
{
printf ("%s: AsynDriverInterface::supportsEvent: "
"pasynInt32->registerInterruptUser(%p, %p, %p, %p, %p)\n",
clientName(), pvtInt32, pasynUser,
intrCallbackInt32, this, &intrPvtInt32);
return true;
}
const char *portname;
pasynManager->getPortName(pasynUser, &portname);
error("%s: port %s does not allow to register for "
"Int32 interrupts: %s\n",
clientName(), portname, pasynUser->errorMessage);
pasynInt32 = NULL;
intrPvtInt32 = NULL;
}
// no asynInt32 available, thus try asynUInt32
pasynInterface = pasynManager->findInterface(pasynUser,
asynUInt32DigitalType, true);
if (pasynInterface)
{
pasynUInt32 =
static_cast<asynUInt32Digital*>(pasynInterface->pinterface);
pvtUInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL;
if (pasynUInt32->registerInterruptUser(pvtUInt32,
pasynUser, intrCallbackUInt32, this, 0xFFFFFFFF,
&intrPvtUInt32) == asynSuccess)
{
printf ("%s: AsynDriverInterface::supportsEvent: "
"pasynUInt32->registerInterruptUser(%p, %p, %p, %p, %#X, %p)\n",
clientName(), pvtUInt32, pasynUser,
intrCallbackUInt32, this, 0xFFFFFFFF, &intrPvtInt32);
return true;
}
const char *portname;
pasynManager->getPortName(pasynUser, &portname);
error("%s: port %s does not allow to register for "
"UInt32 interrupts: %s\n",
clientName(), portname, pasynUser->errorMessage);
pasynUInt32 = NULL;
intrPvtUInt32 = NULL;
}
// no event interface available
return false;
} }
bool AsynDriverInterface:: bool AsynDriverInterface::
@ -359,20 +421,32 @@ supportsAsyncRead()
if (pasynOctet->registerInterruptUser(pvtOctet, pasynUser, if (pasynOctet->registerInterruptUser(pvtOctet, pasynUser,
intrCallbackOctet, this, &intrPvtOctet) != asynSuccess) intrCallbackOctet, this, &intrPvtOctet) != asynSuccess)
{ {
error("%s: bus does not support asynchronous input: %s\n", const char *portname;
clientName(), pasynUser->errorMessage); int addr;
pasynManager->getPortName(pasynUser, &portname);
pasynManager->getAddr(pasynUser, &addr);
if (addr >= 0)
error("%s: asyn port %s addr %d does not support asynchronous input: %s\n",
clientName(), portname, addr, pasynUser->errorMessage);
else
error("%s: asyn port %s does not support asynchronous input: %s\n",
clientName(), portname, pasynUser->errorMessage);
return false; return false;
} }
return true; return true;
} }
bool AsynDriverInterface:: bool AsynDriverInterface::
connectToBus(const char* busname, int addr) connectToBus(const char* portname, int addr)
{ {
if (pasynManager->connectDevice(pasynUser, busname, addr) != asynStatus status = pasynManager->connectDevice(pasynUser, portname, addr);
asynSuccess) debug("%s: AsynDriverInterface::connectToBus(%s, %d): "
"pasynManager->connectDevice(%p, %s, %d) = %s\n",
clientName(), portname, addr, pasynUser,portname, addr,
asynStatusStr[status]);
if (status != asynSuccess)
{ {
// asynDriver does not know this busname/address // asynDriver does not know this portname/address
return false; return false;
} }
@ -381,10 +455,10 @@ connectToBus(const char* busname, int addr)
// find the asynCommon interface // find the asynCommon interface
pasynInterface = pasynManager->findInterface(pasynUser, pasynInterface = pasynManager->findInterface(pasynUser,
asynCommonType, true); asynCommonType, true);
if(!pasynInterface) if (!pasynInterface)
{ {
error("%s: bus %s does not support asynCommon interface\n", error("%s: asyn port %s does not support asynCommon interface\n",
clientName(), busname); clientName(), portname);
return false; return false;
} }
pasynCommon = static_cast<asynCommon*>(pasynInterface->pinterface); pasynCommon = static_cast<asynCommon*>(pasynInterface->pinterface);
@ -393,10 +467,10 @@ connectToBus(const char* busname, int addr)
// find the asynOctet interface // find the asynOctet interface
pasynInterface = pasynManager->findInterface(pasynUser, pasynInterface = pasynManager->findInterface(pasynUser,
asynOctetType, true); asynOctetType, true);
if(!pasynInterface) if (!pasynInterface)
{ {
error("%s: bus %s does not support asynOctet interface\n", error("%s: asyn port %s does not support asynOctet interface\n",
clientName(), busname); clientName(), portname);
return false; return false;
} }
pasynOctet = static_cast<asynOctet*>(pasynInterface->pinterface); pasynOctet = static_cast<asynOctet*>(pasynInterface->pinterface);
@ -405,7 +479,7 @@ connectToBus(const char* busname, int addr)
// is it a GPIB interface ? // is it a GPIB interface ?
pasynInterface = pasynManager->findInterface(pasynUser, pasynInterface = pasynManager->findInterface(pasynUser,
asynGpibType, true); asynGpibType, true);
if(pasynInterface) if (pasynInterface)
{ {
pasynGpib = static_cast<asynGpib*>(pasynInterface->pinterface); pasynGpib = static_cast<asynGpib*>(pasynInterface->pinterface);
pvtGpib = pasynInterface->drvPvt; pvtGpib = pasynInterface->drvPvt;
@ -413,50 +487,6 @@ connectToBus(const char* busname, int addr)
// (read only one byte first). // (read only one byte first).
peeksize = inputBuffer.capacity(); peeksize = inputBuffer.capacity();
} }
// look for interfaces for events
pasynInterface = pasynManager->findInterface(pasynUser,
asynInt32Type, true);
if(pasynInterface)
{
pasynInt32 = static_cast<asynInt32*>(pasynInterface->pinterface);
pvtInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL; // required for GPIB
if (pasynInt32->registerInterruptUser(pvtInt32, pasynUser,
intrCallbackInt32, this, &intrPvtInt32) == asynSuccess)
{
return true;
}
error("%s: bus %s does not allow to register for "
"Int32 interrupts: %s\n",
clientName(), busname, pasynUser->errorMessage);
pasynInt32 = NULL;
intrPvtInt32 = NULL;
}
// no asynInt32 available, thus try asynUInt32
pasynInterface = pasynManager->findInterface(pasynUser,
asynUInt32DigitalType, true);
if(pasynInterface)
{
pasynUInt32 =
static_cast<asynUInt32Digital*>(pasynInterface->pinterface);
pvtUInt32 = pasynInterface->drvPvt;
pasynUser->reason = ASYN_REASON_SIGNAL;
if (pasynUInt32->registerInterruptUser(pvtUInt32,
pasynUser, intrCallbackUInt32, this, 0xFFFFFFFF,
&intrPvtUInt32) == asynSuccess)
{
return true;
}
error("%s: bus %s does not allow to register for "
"UInt32 interrupts: %s\n",
clientName(), busname, pasynUser->errorMessage);
pasynUInt32 = NULL;
intrPvtUInt32 = NULL;
}
// no event interface available, never mind
return true; return true;
} }
@ -465,23 +495,14 @@ connectToBus(const char* busname, int addr)
bool AsynDriverInterface:: bool AsynDriverInterface::
lockRequest(unsigned long lockTimeout_ms) lockRequest(unsigned long lockTimeout_ms)
{ {
int connected;
asynStatus status; asynStatus status;
debug("AsynDriverInterface::lockRequest(%s, %ld msec)\n", debug("AsynDriverInterface::lockRequest(%s, %ld msec)\n",
clientName(), lockTimeout_ms); clientName(), lockTimeout_ms);
lockTimeout = lockTimeout_ms ? lockTimeout_ms*0.001 : -1.0; lockTimeout = lockTimeout_ms ? lockTimeout_ms*0.001 : -1.0;
ioAction = Lock; ioAction = Lock;
status = pasynManager->isConnected(pasynUser, &connected);
if (status != asynSuccess)
{
error("%s: pasynManager->isConnected() failed: %s\n",
clientName(), pasynUser->errorMessage);
return false;
}
status = pasynManager->queueRequest(pasynUser, status = pasynManager->queueRequest(pasynUser,
connected ? priority() : asynQueuePriorityConnect, priority(), lockTimeout);
lockTimeout);
if (status != asynSuccess) if (status != asynSuccess)
{ {
error("%s lockRequest: pasynManager->queueRequest() failed: %s\n", error("%s lockRequest: pasynManager->queueRequest() failed: %s\n",
@ -503,9 +524,13 @@ connectToAsynPort()
debug("AsynDriverInterface::connectToAsynPort(%s)\n", debug("AsynDriverInterface::connectToAsynPort(%s)\n",
clientName()); clientName());
status = pasynManager->isConnected(pasynUser, &connected); status = pasynManager->isConnected(pasynUser, &connected);
debug("%s: AsynDriverInterface::connectToAsynPort: "
"pasynManager->isConnected(%p, %p) = %s => %s\n",
clientName(), pasynUser, &connected, asynStatusStr[status],
connected ? "yes" : "no");
if (status != asynSuccess) if (status != asynSuccess)
{ {
error("%s: pasynManager->isConnected() failed: %s\n", error("%s connectToAsynPort: pasynManager->isConnected() failed: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
return false; return false;
} }
@ -537,13 +562,19 @@ connectToAsynPort()
clientName(), connected ? "already" : "not yet"); clientName(), connected ? "already" : "not yet");
if (!connected) if (!connected)
{ {
printf ("%s: AsynDriverInterface::connectToAsynPort: "
"pasynCommon->connect(%p, %p)\n",
clientName(), pvtCommon, pasynUser);
status = pasynCommon->connect(pvtCommon, pasynUser); status = pasynCommon->connect(pvtCommon, pasynUser);
printf ("%s: AsynDriverInterface::connectToAsynPort: "
"pasynCommon->connect(%p, %p) = %s\n",
clientName(), pvtCommon, pasynUser, asynStatusStr[status]);
debug("AsynDriverInterface::connectToAsynPort(%s): " debug("AsynDriverInterface::connectToAsynPort(%s): "
"status=%s\n", "status=%s\n",
clientName(), asynStatusStr[status]); clientName(), asynStatusStr[status]);
if (status != asynSuccess) if (status != asynSuccess)
{ {
error("%s: pasynCommon->connect() failed: %s\n", error("%s connectToAsynPort: pasynCommon->connect() failed: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
return false; return false;
} }
@ -561,21 +592,37 @@ connectToAsynPort()
void AsynDriverInterface:: void AsynDriverInterface::
lockHandler() lockHandler()
{ {
int connected; asynStatus status;
debug("AsynDriverInterface::lockHandler(%s)\n", debug("AsynDriverInterface::lockHandler(%s)\n",
clientName()); clientName());
pasynManager->blockProcessCallback(pasynUser, false);
connected = connectToAsynPort(); status = pasynManager->blockProcessCallback(pasynUser, false);
lockCallback(connected ? StreamIoSuccess : StreamIoFault); if (status != asynSuccess)
{
error("%s lockHandler: pasynManager->blockProcessCallback() failed: %s\n",
clientName(), pasynUser->errorMessage);
lockCallback(StreamIoFault);
return;
}
lockCallback(StreamIoSuccess);
} }
// interface function: we don't need exclusive access any more // interface function: we don't need exclusive access any more
bool AsynDriverInterface:: bool AsynDriverInterface::
unlock() unlock()
{ {
asynStatus status;
debug("AsynDriverInterface::unlock(%s)\n", debug("AsynDriverInterface::unlock(%s)\n",
clientName()); clientName());
pasynManager->unblockProcessCallback(pasynUser, false); status = pasynManager->unblockProcessCallback(pasynUser, false);
if (status != asynSuccess)
{
error("%s unlock: pasynManager->unblockProcessCallback() failed: %s\n",
clientName(), pasynUser->errorMessage);
return false;
}
return true; return true;
} }
@ -618,20 +665,33 @@ writeHandler()
asynStatus status; asynStatus status;
size_t written = 0; size_t written = 0;
pasynUser->timeout = 0;
if (!pasynGpib)
// discard any early input, but forward it to potential async records // discard any early input, but forward it to potential async records
// thus do not use pasynOctet->flush() // thus do not use pasynOctet->flush()
pasynUser->timeout = 0; // unfortunately we cannot do this with GPIB because addressing a device as talker
// when it has nothing to say is an error. Also timeout=0 does not help here (would need
// a change in asynGPIB), thus use flush() for GPIB.
do { do {
char buffer [256]; char buffer [256];
size_t received = sizeof(buffer); size_t received = 0;
int eomReason = 0; int eomReason = 0;
debug("AsynDriverInterface::writeHandler(%s): reading old input\n",
clientName());
status = pasynOctet->read(pvtOctet, pasynUser, status = pasynOctet->read(pvtOctet, pasynUser,
buffer, received, &received, &eomReason); buffer, sizeof(buffer), &received, &eomReason);
if (received == 0) break;
#ifndef NO_TEMPORARY #ifndef NO_TEMPORARY
if (received) debug("AsynDriverInterface::writeHandler(%s): flushing %ld bytes: \"%s\"\n", if (received) debug("AsynDriverInterface::writeHandler(%s): flushing %ld bytes: \"%s\"\n",
clientName(), (long)received, StreamBuffer(buffer, received).expand()()); clientName(), (long)received, StreamBuffer(buffer, received).expand()());
#endif #endif
} while (status != asynTimeout); } while (status == asynSuccess);
else
{
debug("AsynDriverInterface::writeHandler(%s): flushing old input\n",
clientName());
pasynOctet->flush(pvtOctet, pasynUser);
}
// discard any early events // discard any early events
receivedEvent = 0; receivedEvent = 0;
@ -666,6 +726,12 @@ writeHandler()
clientName(), (long)outputSize, (long)written, clientName(), (long)outputSize, (long)written,
pasynUser->timeout, asynStatusStr[status]); pasynUser->timeout, asynStatusStr[status]);
if (oldeoslen >= 0) // restore asyn terminator
{
pasynOctet->setOutputEos(pvtOctet, pasynUser,
oldeos, oldeoslen);
}
// Up to asyn 4.17 I can't see when the server has disconnected. Why? // Up to asyn 4.17 I can't see when the server has disconnected. Why?
int connected; int connected;
pasynManager->isConnected(pasynUser, &connected); pasynManager->isConnected(pasynUser, &connected);
@ -673,17 +739,12 @@ writeHandler()
"device is %sconnected\n", "device is %sconnected\n",
clientName(),connected?"":"dis"); clientName(),connected?"":"dis");
if (!connected) { if (!connected) {
error("%s: connection closed in write\n", error("%s: write failed because connection was closed by device\n",
clientName()); clientName());
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
} }
if (oldeoslen >= 0) // restore asyn terminator
{
pasynOctet->setOutputEos(pvtOctet, pasynUser,
oldeos, oldeoslen);
}
switch (status) switch (status)
{ {
case asynSuccess: case asynSuccess:
@ -708,32 +769,34 @@ writeHandler()
writeCallback(StreamIoSuccess); writeCallback(StreamIoSuccess);
return; return;
case asynTimeout: case asynTimeout:
error("%s: asynTimeout (%g sec) in write. Asyn says: %s\n",
clientName(), pasynUser->timeout, pasynUser->errorMessage);
writeCallback(StreamIoTimeout); writeCallback(StreamIoTimeout);
return; return;
case asynOverflow: case asynOverflow:
error("%s: asynOverflow in write: %s\n", error("%s: asynOverflow in write. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
case asynError: case asynError:
error("%s: asynError in write: %s\n", error("%s: asynError in write. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
#ifdef ASYN_VERSION // asyn >= 4.14 #ifdef ASYN_VERSION // asyn >= 4.14
case asynDisconnected: case asynDisconnected:
error("%s: asynDisconnected in write: %s\n", error("%s: asynDisconnected in write. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
case asynDisabled: case asynDisabled:
error("%s: asynDisconnected in write: %s\n", error("%s: asynDisconnected in write. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
#endif #endif
default: default:
error("%s: unknown asyn error in write: %s\n", error("%s: unknown asyn error in write. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
writeCallback(StreamIoFault); writeCallback(StreamIoFault);
return; return;
@ -1031,29 +1094,29 @@ readHandler()
} }
peeksize = inputBuffer.capacity(); peeksize = inputBuffer.capacity();
// deliver whatever we could save // deliver whatever we could save
error("%s: asynOverflow in read: %s\n", error("%s: asynOverflow in read. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault, buffer, received); readCallback(StreamIoFault, buffer, received);
break; break;
case asynError: case asynError:
error("%s: asynError in read: %s\n", error("%s: asynError in read. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault, buffer, received); readCallback(StreamIoFault, buffer, received);
break; break;
#ifdef ASYN_VERSION // asyn >= 4.14 #ifdef ASYN_VERSION // asyn >= 4.14
case asynDisconnected: case asynDisconnected:
error("%s: asynDisconnected in read: %s\n", error("%s: asynDisconnected in read. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault); readCallback(StreamIoFault);
return; return;
case asynDisabled: case asynDisabled:
error("%s: asynDisconnected in read: %s\n", error("%s: asynDisconnected in read. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault); readCallback(StreamIoFault);
return; return;
#endif #endif
default: default:
error("%s: unknown asyn error in read: %s\n", error("%s: unknown asyn error in read. Asyn driver says: %s\n",
clientName(), pasynUser->errorMessage); clientName(), pasynUser->errorMessage);
readCallback(StreamIoFault); readCallback(StreamIoFault);
return; return;
@ -1216,7 +1279,7 @@ acceptEvent(unsigned long mask, unsigned long replytimeout_ms)
} }
eventMask = mask; eventMask = mask;
ioAction = ReceiveEvent; ioAction = ReceiveEvent;
startTimer(replytimeout_ms*0.001); if (replytimeout_ms) startTimer(replytimeout_ms*0.001);
return true; return true;
} }

View File

@ -27,12 +27,9 @@
#endif #endif
#include <ctype.h> #include <ctype.h>
typedef unsigned long ulong; typedef unsigned int (*checksumFunc)(const unsigned char* data, unsigned int len, unsigned int init);
typedef unsigned char uchar;
typedef ulong (*checksumFunc)(const uchar* data, ulong len, ulong init); static unsigned int sum(const unsigned char* data, unsigned int len, unsigned int sum)
static ulong sum(const uchar* data, ulong len, ulong sum)
{ {
while (len--) while (len--)
{ {
@ -41,7 +38,7 @@ static ulong sum(const uchar* data, ulong len, ulong sum)
return sum; return sum;
} }
static ulong xor8(const uchar* data, ulong len, ulong sum) static unsigned int xor8(const unsigned char* data, unsigned int len, unsigned int sum)
{ {
while (len--) while (len--)
{ {
@ -50,15 +47,15 @@ static ulong xor8(const uchar* data, ulong len, ulong sum)
return sum; return sum;
} }
static ulong xor7(const uchar* data, ulong len, ulong sum) static unsigned int xor7(const unsigned char* data, unsigned int len, unsigned int sum)
{ {
return xor8(data, len, sum) & 0x7F; return xor8(data, len, sum) & 0x7F;
} }
static ulong crc_0x07(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x07(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^8 + x^2 + x^1 + x^0 (0x07) // x^8 + x^2 + x^1 + x^0 (0x07)
const static uchar table[256] = { const static unsigned char table[256] = {
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
@ -96,10 +93,10 @@ static ulong crc_0x07(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x31(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x31(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^8 + x^5 + x^4 + x^0 (0x31) // x^8 + x^5 + x^4 + x^0 (0x31)
const static uchar table[256] = { const static unsigned char table[256] = {
0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83,
0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41,
0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e,
@ -137,7 +134,7 @@ static ulong crc_0x31(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x8005(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x8005(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^16 + x^15 + x^2 + x^0 (0x8005) // x^16 + x^15 + x^2 + x^0 (0x8005)
const static unsigned short table[256] = { const static unsigned short table[256] = {
@ -178,7 +175,7 @@ static ulong crc_0x8005(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x8005_r(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x8005_r(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^16 + x^15 + x^2 + x^0 (0x8005) // x^16 + x^15 + x^2 + x^0 (0x8005)
// reflected // reflected
@ -220,7 +217,7 @@ static ulong crc_0x8005_r(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x1021(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x1021(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^16 + x^12 + x^5 + x^0 (0x1021) // x^16 + x^12 + x^5 + x^0 (0x1021)
const static unsigned short table[256] = { const static unsigned short table[256] = {
@ -261,7 +258,7 @@ static ulong crc_0x1021(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x04C11DB7(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x04C11DB7(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 +
// x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7) // x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7)
@ -335,7 +332,7 @@ static ulong crc_0x04C11DB7(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong crc_0x04C11DB7_r(const uchar* data, ulong len, ulong crc) static unsigned int crc_0x04C11DB7_r(const unsigned char* data, unsigned int len, unsigned int crc)
{ {
// x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + // x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 +
// x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7) // x^8 + x^7 + x^5 + x^4 + x^2 + x^1 + x^0 (0x04C11DB7)
@ -410,13 +407,13 @@ static ulong crc_0x04C11DB7_r(const uchar* data, ulong len, ulong crc)
return crc; return crc;
} }
static ulong adler32(const uchar* data, ulong len, ulong init) static unsigned int adler32(const unsigned char* data, unsigned int len, unsigned int init)
{ {
ulong a = init & 0xFFFF; unsigned int a = init & 0xFFFF;
ulong b = (init >> 16) & 0xFFFF; unsigned int b = (init >> 16) & 0xFFFF;
while (len) { while (len) {
ulong tlen = len > 5550 ? 5550 : len; unsigned int tlen = len > 5550 ? 5550 : len;
len -= tlen; len -= tlen;
do { do {
a += *data++; a += *data++;
@ -431,10 +428,10 @@ static ulong adler32(const uchar* data, ulong len, ulong init)
return b << 16 | a; return b << 16 | a;
} }
static ulong hexsum(const uchar* data, ulong len, ulong sum) static unsigned int hexsum(const unsigned char* data, unsigned int len, unsigned int sum)
{ {
// Add all hex digits, ignore all other bytes. // Add all hex digits, ignore all other bytes.
ulong d; unsigned int d;
while (len--) while (len--)
{ {
d = toupper(*data++); d = toupper(*data++);
@ -452,8 +449,8 @@ struct checksum
{ {
const char* name; const char* name;
checksumFunc func; checksumFunc func;
ulong init; unsigned int init;
ulong xorout; unsigned int xorout;
signed char bytes; signed char bytes;
}; };
@ -465,20 +462,6 @@ static checksum checksumMap[] =
{"sum8", sum, 0x00, 0x00, 1}, // 0xDD {"sum8", sum, 0x00, 0x00, 1}, // 0xDD
{"sum16", sum, 0x0000, 0x0000, 2}, // 0x01DD {"sum16", sum, 0x0000, 0x0000, 2}, // 0x01DD
{"sum32", sum, 0x00000000, 0x00000000, 4}, // 0x000001DD {"sum32", sum, 0x00000000, 0x00000000, 4}, // 0x000001DD
{"nsum", sum, 0xFF, 0xFF, 1}, // 0x23
{"negsum", sum, 0xFF, 0xFF, 1}, // 0x23
{"-sum", sum, 0xFF, 0xFF, 1}, // 0x23
{"nsum8", sum, 0xFF, 0xFF, 1}, // 0x23
{"negsum8", sum, 0xFF, 0xFF, 1}, // 0x23
{"-sum8", sum, 0xFF, 0xFF, 1}, // 0x23
{"nsum16", sum, 0xFFFF, 0xFFFF, 2}, // 0xFE23
{"negsum16",sum, 0xFFFF, 0xFFFF, 2}, // 0xFE23
{"-sum16", sum, 0xFFFF, 0xFFFF, 2}, // 0xFE23
{"nsum32", sum, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFFFFFE23
{"negsum32",sum, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFFFFFE23
{"-sum32", sum, 0xFFFFFFFF, 0xFFFFFFFF, 4}, // 0xFFFFFE23
{"notsum", sum, 0x00, 0xFF, 1}, // 0x22
{"~sum", sum, 0x00, 0xFF, 1}, // 0x22
{"xor", xor8, 0x00, 0x00, 1}, // 0x31 {"xor", xor8, 0x00, 0x00, 1}, // 0x31
{"xor8", xor8, 0x00, 0x00, 1}, // 0x31 {"xor8", xor8, 0x00, 0x00, 1}, // 0x31
{"xor7", xor7, 0x00, 0x00, 1}, // 0x31 {"xor7", xor7, 0x00, 0x00, 1}, // 0x31
@ -498,7 +481,7 @@ static checksum checksumMap[] =
{"hexsum8", hexsum, 0x00, 0x00, 1} // 0x2D {"hexsum8", hexsum, 0x00, 0x00, 1} // 0x2D
}; };
static ulong mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF}; static unsigned int mask[5] = {0, 0xFF, 0xFFFF, 0xFFFFFF, 0xFFFFFFFF};
class ChecksumConverter : public StreamFormatConverter class ChecksumConverter : public StreamFormatConverter
{ {
@ -517,39 +500,80 @@ parse(const StreamFormat&, StreamBuffer& info, const char*& source, bool)
return false; return false;
} }
size_t fnum; bool negflag=false;
bool notflag=false;
if (*source == '-')
{
source++;
negflag = true;
}
if (strncasecmp(source, "neg", 3) == 0)
{
source+=3;
negflag = true;
}
if (*source == '~')
{
source++;
notflag = true;
}
if (strncasecmp(source, "not", 3) == 0)
{
source+=3;
notflag = true;
}
unsigned fnum;
int len = p-source;
unsigned int init, xorout;
for (fnum = 0; fnum < sizeof(checksumMap)/sizeof(checksum); fnum++) for (fnum = 0; fnum < sizeof(checksumMap)/sizeof(checksum); fnum++)
{ {
if (strncasecmp(source, checksumMap[fnum].name, p-source) == 0) if ((strncasecmp(source, checksumMap[fnum].name, len) == 0) ||
(*source == 'n' && len > 1 && strncasecmp(source+1, checksumMap[fnum].name, len-1) == 0 && (negflag = true)))
{ {
init = checksumMap[fnum].init;
xorout = checksumMap[fnum].xorout;
if (negflag)
{
init = ~init;
xorout = ~xorout;
}
if (notflag)
{
xorout = ~xorout;
}
info.append(&init, sizeof(init));
info.append(&xorout, sizeof(xorout));
info.append(fnum); info.append(fnum);
source = p+1; source = p+1;
return pseudo_format; return pseudo_format;
} }
} }
error ("Unknown checksum algorithm \"%.*s\"\n", error ("Unknown checksum algorithm \"%.*s\"\n", len, source);
static_cast<int>(p-source), source);
return false; return false;
} }
bool ChecksumConverter:: bool ChecksumConverter::
printPseudo(const StreamFormat& format, StreamBuffer& output) printPseudo(const StreamFormat& format, StreamBuffer& output)
{ {
ulong sum; unsigned int sum;
int fnum = format.info[0]; const char* info = format.info;
unsigned int init = extract<unsigned int>(info);
unsigned int xorout = extract<unsigned int>(info);
int fnum = extract<char>(info);
int start = format.width; int start = format.width;
int length = output.length()-format.width; int length = output.length()-format.width;
if (format.prec > 0) length -= format.prec; if (format.prec > 0) length -= format.prec;
debug("ChecksumConverter %s: output to check: \"%s\"\n", debug("ChecksumConverter %s: output to check: \"%s\"\n",
checksumMap[fnum].name, output.expand(start,length)()); checksumMap[fnum].name, output.expand(start,length)());
sum = (xorout ^ checksumMap[fnum].func(
reinterpret_cast<unsigned char*>(output(start)), length, init))
& mask[checksumMap[fnum].bytes];
sum = (checksumMap[fnum].xorout ^ checksumMap[fnum].func( debug("ChecksumConverter %s: output checksum is 0x%X\n",
reinterpret_cast<uchar*>(output(start)), length,
checksumMap[fnum].init)) & mask[checksumMap[fnum].bytes];
debug("ChecksumConverter %s: output checksum is 0x%lX\n",
checksumMap[fnum].name, sum); checksumMap[fnum].name, sum);
int i; int i;
@ -559,13 +583,11 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
{ {
// get number of decimal digits from number of bytes: ceil(xbytes*2.5) // get number of decimal digits from number of bytes: ceil(xbytes*2.5)
i = (checksumMap[fnum].bytes+1)*25/10-2; i = (checksumMap[fnum].bytes+1)*25/10-2;
output.print("%0*ld", i, sum); output.print("%0*d", i, sum);
debug("ChecksumConverter %s: decimal appending %0*ld\n", debug("ChecksumConverter %s: decimal appending %0*d\n",
checksumMap[fnum].name, i, sum); checksumMap[fnum].name, i, sum);
return true; }
} else
if (format.flags & alt_flag) // lsb first (little endian) if (format.flags & alt_flag) // lsb first (little endian)
{ {
for (i = 0; i < checksumMap[fnum].bytes; i++) for (i = 0; i < checksumMap[fnum].bytes; i++)
@ -575,6 +597,10 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
checksumMap[fnum].name, outchar); checksumMap[fnum].name, outchar);
if (format.flags & zero_flag) // ASCII if (format.flags & zero_flag) // ASCII
output.print("%02X", outchar); output.print("%02X", outchar);
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
output.print("%c%c",
((outchar>>4)&0x0f)|0x30, (outchar&0x0f)|0x30);
else // binary else // binary
output.append(outchar); output.append(outchar);
sum >>= 8; sum >>= 8;
@ -590,6 +616,10 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
checksumMap[fnum].name, outchar); checksumMap[fnum].name, outchar);
if (format.flags & zero_flag) // ASCII if (format.flags & zero_flag) // ASCII
output.print("%02X", outchar); output.print("%02X", outchar);
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
output.print("%c%c",
((outchar>>4)&0x0f)|0x30, (outchar&0x0f)|0x30);
else // binary else // binary
output.append(outchar); output.append(outchar);
sum <<= 8; sum <<= 8;
@ -601,57 +631,88 @@ printPseudo(const StreamFormat& format, StreamBuffer& output)
int ChecksumConverter:: int ChecksumConverter::
scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor) scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
{ {
int fnum = format.info[0]; unsigned int sum;
ulong sum; const char* info = format.info;
unsigned int init = extract<unsigned int>(info);
unsigned int xorout = extract<unsigned int>(info);
int start = format.width; int start = format.width;
int fnum = extract<char>(info);
int length = cursor-format.width; int length = cursor-format.width;
if (format.prec > 0) length -= format.prec; if (format.prec > 0) length -= format.prec;
debug("ChecksumConverter %s: input to check: \"%s\n", debug("ChecksumConverter %s: input to check: \"%s\n",
checksumMap[fnum].name, input.expand(start,length)()); checksumMap[fnum].name, input.expand(start,length)());
if (input.length() - cursor < int expectedLength =
(format.flags & zero_flag ? 2 : 1) * checksumMap[fnum].bytes) // get number of decimal digits from number of bytes: ceil(bytes*2.5)
format.flags & sign_flag ? (checksumMap[fnum].bytes + 1) * 25 / 10 - 2 :
format.flags & (zero_flag|left_flag) ? 2 * checksumMap[fnum].bytes :
checksumMap[fnum].bytes;
if (input.length() - cursor < expectedLength)
{ {
error("Input too short for checksum\n"); debug("ChecksumConverter %s: Input '%s' too short for checksum\n",
checksumMap[fnum].name, input.expand(cursor)());
return -1; return -1;
} }
sum = (checksumMap[fnum].xorout ^ checksumMap[fnum].func( sum = (xorout ^ checksumMap[fnum].func(
reinterpret_cast<uchar*>(input(start)), length, reinterpret_cast<unsigned char*>(input(start)), length, init))
checksumMap[fnum].init)) & mask[checksumMap[fnum].bytes]; & mask[checksumMap[fnum].bytes];
debug("ChecksumConverter %s: input checksum is 0x%0*lX\n", debug("ChecksumConverter %s: input checksum is 0x%0*X\n",
checksumMap[fnum].name, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, 2*checksumMap[fnum].bytes, sum);
int i,j; int i, j;
unsigned inchar; unsigned inchar;
if (format.flags & sign_flag) // decimal if (format.flags & sign_flag) // decimal
{ {
ulong sumin = 0; unsigned int sumin = 0;
// get number of decimal digits from number of bytes: ceil(xbytes*2.5) for (i = 0; i < expectedLength; i++)
j = (checksumMap[fnum].bytes+1)*25/10-2;
for (i = 0; i < j; i++)
{ {
inchar = input[cursor+i]; inchar = input[cursor+i];
if (isdigit(inchar)) sumin = sumin*10+inchar-'0'; if (isdigit(inchar)) sumin = sumin*10+inchar-'0';
else break; else break;
} }
if (sumin==sum) return i; if (sumin != sum)
error("Input %0*lu does not match checksum %0*lu\n", {
i, sumin, j, sum); debug("ChecksumConverter %s: Input %0*u does not match checksum %0*u\n",
return -1; checksumMap[fnum].name, i, sumin, expectedLength, sum);
return -1;
}
} }
else
if (format.flags & alt_flag) // lsb first (little endian) if (format.flags & alt_flag) // lsb first (little endian)
{ {
for (i = 0; i < checksumMap[fnum].bytes; i++) for (i = 0; i < checksumMap[fnum].bytes; i++)
{ {
if (format.flags & zero_flag) // ASCII if (format.flags & zero_flag) // ASCII
{ {
sscanf(input(cursor+2*i), "%2X", &inchar); if (sscanf(input(cursor+2*i), "%2X", &inchar) != 1)
{
debug("ChecksumConverter %s: Input byte '%s' is not a hex byte\n",
checksumMap[fnum].name, input.expand(cursor+2*i,2)());
return -1;
}
}
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
{
if ((input[cursor+2*i] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i]);
return -1;
}
if ((input[cursor+2*i+1] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i+1]);
return -1;
}
inchar = ((input[cursor+2*i] & 0x0f) << 4) | (input[cursor+2*i+1] & 0x0f);
} }
else // binary else // binary
{ {
@ -659,8 +720,8 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
} }
if (inchar != ((sum >> 8*i) & 0xff)) if (inchar != ((sum >> 8*i) & 0xff))
{ {
error("Input byte 0x%02X does not match checksum 0x%0*lX\n", debug("ChecksumConverter %s: Input byte 0x%02X does not match checksum 0x%0*X\n",
inchar, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, inchar, 2*checksumMap[fnum].bytes, sum);
return -1; return -1;
} }
} }
@ -673,21 +734,36 @@ scanPseudo(const StreamFormat& format, StreamBuffer& input, long& cursor)
{ {
sscanf(input(cursor+2*i), "%2x", &inchar); sscanf(input(cursor+2*i), "%2x", &inchar);
} }
else
if (format.flags & left_flag) // poor man's hex: 0x30 - 0x3F
{
if ((input[cursor+2*i] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i]);
return -1;
}
if ((input[cursor+2*i+1] & 0xf0) != 0x30)
{
debug("ChecksumConverter %s: Input byte 0x%02X is not in range 0x30 - 0x3F\n",
checksumMap[fnum].name, input[cursor+2*i+1]);
return -1;
}
inchar = ((input[cursor+2*i] & 0x0f) << 4) | (input[cursor+2*i+1] & 0x0f);
}
else // binary else // binary
{ {
inchar = input[cursor+i] & 0xff; inchar = input[cursor+i] & 0xff;
} }
if (inchar != ((sum >> 8*j) & 0xff)) if (inchar != ((sum >> 8*j) & 0xff))
{ {
error("Input byte 0x%02X does not match checksum 0x%0*lX\n", debug("ChecksumConverter %s: Input byte 0x%02X does not match checksum 0x%0*X\n",
inchar, 2*checksumMap[fnum].bytes, sum); checksumMap[fnum].name, inchar, 2*checksumMap[fnum].bytes, sum);
return -1; return -1;
} }
} }
} }
if (format.flags & zero_flag) // ASCII return expectedLength;
return 2*checksumMap[fnum].bytes;
return checksumMap[fnum].bytes;
} }
RegisterConverter (ChecksumConverter, "<"); RegisterConverter (ChecksumConverter, "<");

View File

@ -30,15 +30,17 @@
#define vsnprintf epicsVsnprintf #define vsnprintf epicsVsnprintf
#endif #endif
#define P PRINTF_SIZE_T_PREFIX
void StreamBuffer:: void StreamBuffer::
init(const void* s, long minsize) init(const void* s, ssize_t minsize)
{ {
len = 0; len = 0;
offs = 0; offs = 0;
buffer = local; buffer = local;
cap = sizeof(local); cap = sizeof(local);
if (minsize < 0) minsize = 0; if (minsize < 0) minsize = 0;
if (minsize >= cap) if ((size_t)minsize >= cap)
{ {
// use allocated buffer // use allocated buffer
grow(minsize); grow(minsize);
@ -55,18 +57,18 @@ init(const void* s, long minsize)
} }
// How the buffer looks like: // How the buffer looks like:
// |----free-----|####used####|-------free-------| // |----free-----|####used####|--------00--------|
///|<--- offs -->|<-- len --->|<- cap-offs-len ->| ///|<--- offs -->|<-- len --->|<- cap-offs-len ->|
// 0 offs offs+len cap // 0 offs offs+len cap
// |<-------------- minsize ---------------> // |<-------------- minsize --------------->
void StreamBuffer:: void StreamBuffer::
grow(long minsize) grow(size_t minsize)
{ {
// make space for minsize + 1 (for termination) bytes // make space for minsize + 1 (for termination) bytes
char* newbuffer; char* newbuffer;
long newcap; size_t newcap;
#ifdef EXPLODE #ifdef EXPLODE
if (minsize > 1000000) if (minsize > 1000000)
{ {
@ -117,12 +119,12 @@ grow(long minsize)
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
append(const void* s, long size) append(const void* s, ssize_t size)
{ {
if (size <= 0) if (size <= 0)
{ {
// append negative number of bytes? let's delete some // append negative number of bytes? let's delete some
if (size < -len) size = -len; if (size < -(ssize_t)len) size = -(ssize_t)len;
memset (buffer+offs+len+size, 0, -size); memset (buffer+offs+len+size, 0, -size);
} }
else else
@ -134,8 +136,8 @@ append(const void* s, long size)
return *this; return *this;
} }
long int StreamBuffer:: ssize_t StreamBuffer::
find(const void* m, long size, long start) const find(const void* m, size_t size, ssize_t start) const
{ {
if (start < 0) if (start < 0)
{ {
@ -147,7 +149,7 @@ find(const void* m, long size, long start) const
const char* s = static_cast<const char*>(m); const char* s = static_cast<const char*>(m);
char* b = buffer+offs; char* b = buffer+offs;
char* p = b+start; char* p = b+start;
long i; size_t i;
while ((p = static_cast<char*>(memchr(p, s[0], b-p+len-size+1)))) while ((p = static_cast<char*>(memchr(p, s[0], b-p+len-size+1))))
{ {
for (i = 1; i < size; i++) for (i = 1; i < size; i++)
@ -161,7 +163,7 @@ next: p++;
} }
StreamBuffer& StreamBuffer:: StreamBuffer& StreamBuffer::
replace(long remstart, long remlen, const void* ins, long inslen) replace(ssize_t remstart, ssize_t remlen, const void* ins, ssize_t inslen)
{ {
if (remstart < 0) if (remstart < 0)
{ {
@ -187,12 +189,12 @@ replace(long remstart, long remlen, const void* ins, long inslen)
remlen += remstart; remlen += remstart;
remstart = 0; remstart = 0;
} }
if (remstart > len) if ((size_t)remstart > len)
{ {
// remove begins after bufferend // remove begins after bufferend
remstart = len; remstart = len;
} }
if (remlen >= len-remstart) if ((size_t)remlen >= len-remstart)
{ {
// truncate remove after bufferend // truncate remove after bufferend
remlen = len-remstart; remlen = len-remstart;
@ -205,12 +207,12 @@ replace(long remstart, long remlen, const void* ins, long inslen)
return *this; return *this;
} }
if (inslen < 0) inslen = 0; if (inslen < 0) inslen = 0;
long remend = remstart+remlen; size_t remend = remstart+remlen;
long newlen = len+inslen-remlen; size_t newlen = len+inslen-remlen;
if (cap <= newlen) if (cap <= newlen)
{ {
// buffer too short // buffer too short
long newcap; size_t newcap;
for (newcap = sizeof(local)*2; newcap <= newlen; newcap *= 2); for (newcap = sizeof(local)*2; newcap <= newlen; newcap *= 2);
char* newbuffer = new char[newcap]; char* newbuffer = new char[newcap];
memcpy(newbuffer, buffer+offs, remstart); memcpy(newbuffer, buffer+offs, remstart);
@ -251,13 +253,13 @@ StreamBuffer& StreamBuffer::
print(const char* fmt, ...) print(const char* fmt, ...)
{ {
va_list va; va_list va;
int printed; ssize_t printed;
while (1) while (1)
{ {
va_start(va, fmt); va_start(va, fmt);
printed = vsnprintf(buffer+offs+len, cap-offs-len, fmt, va); printed = vsnprintf(buffer+offs+len, cap-offs-len, fmt, va);
va_end(va); va_end(va);
if (printed > -1 && printed < (int)(cap-offs-len)) if (printed > -1 && printed < (ssize_t)(cap-offs-len))
{ {
len += printed; len += printed;
return *this; return *this;
@ -267,9 +269,9 @@ print(const char* fmt, ...)
} }
} }
StreamBuffer StreamBuffer::expand(long start, long length) const StreamBuffer StreamBuffer::expand(ssize_t start, ssize_t length) const
{ {
long end; size_t end;
if (start < 0) if (start < 0)
{ {
start += len; start += len;
@ -289,7 +291,7 @@ StreamBuffer StreamBuffer::expand(long start, long length) const
StreamBuffer result((end-start)*2); StreamBuffer result((end-start)*2);
start += offs; start += offs;
end += offs; end += offs;
long i; size_t i;
char c; char c;
for (i = start; i < end; i++) for (i = start; i < end; i++)
{ {
@ -311,8 +313,8 @@ dump() const
{ {
StreamBuffer result(256+cap*5); StreamBuffer result(256+cap*5);
result.append("\033[0m"); result.append("\033[0m");
long i; size_t i;
result.print("%ld,%ld,%ld:\033[37m", offs, len, cap); result.print("%"P"d,%"P"d,%"P"d:\033[37m", offs, len, cap);
for (i = 0; i < cap; i++) for (i = 0; i < cap; i++)
{ {
if (i == offs) result.append("\033[34m[\033[0m"); if (i == offs) result.append("\033[34m[\033[0m");

View File

@ -21,29 +21,34 @@
#define StreamBuffer_h #define StreamBuffer_h
#include <string.h> #include <string.h>
#include <stdlib.h>
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(x) #define __attribute__(x)
#endif #endif
#ifdef _WIN32
#define ssize_t ptrdiff_t
#endif
class StreamBuffer class StreamBuffer
{ {
char local[64]; char local[64];
long len; size_t len;
long cap; size_t cap;
long offs; size_t offs;
char* buffer; char* buffer;
void init(const void* s, long minsize); void init(const void* s, ssize_t minsize);
void check(long size) void check(size_t size)
{if (len+offs+size >= cap) grow(len+size);} {if (len+offs+size >= cap) grow(len+size);}
void grow(long minsize); void grow(size_t minsize);
public: public:
// Hints: // Hints:
// * Any index parameter (long) can be negative // * Any index parameter (ssize_t) can be negative
// meaning "count from end" (-1 is the last byte) // meaning "count from end" (-1 is the last byte)
// * Appending negative count deletes from end // * Appending negative count deletes from end
// * Any returned char* pointer becomes invalid when // * Any returned char* pointer becomes invalid when
@ -54,7 +59,7 @@ public:
StreamBuffer() StreamBuffer()
{init(NULL, 0);} {init(NULL, 0);}
StreamBuffer(const void* s, long size) StreamBuffer(const void* s, ssize_t size)
{init(s, size);} {init(s, size);}
StreamBuffer(const char* s) StreamBuffer(const char* s)
@ -63,24 +68,24 @@ public:
StreamBuffer(const StreamBuffer& s) StreamBuffer(const StreamBuffer& s)
{init(s.buffer+s.offs, s.len);} {init(s.buffer+s.offs, s.len);}
StreamBuffer(long size) StreamBuffer(ssize_t size)
{init(NULL, size);} {init(NULL, size);}
~StreamBuffer() ~StreamBuffer()
{if (buffer != local) delete buffer;} {if (buffer != local) delete buffer;}
// operator (): get char* pointing to index // operator (): get char* pointing to index
const char* operator()(long index=0) const const char* operator()(ssize_t index=0) const
{return buffer+offs+(index<0?index+len:index);} {return buffer+offs+(index<0?index+len:index);}
char* operator()(long index=0) char* operator()(ssize_t index=0)
{return buffer+offs+(index<0?index+len:index);} {return buffer+offs+(index<0?index+len:index);}
// operator []: get byte at index // operator []: get byte at index
char operator[](long index) const char operator[](ssize_t index) const
{return buffer[offs+(index<0?index+len:index)];} {return buffer[offs+(index<0?index+len:index)];}
char& operator[](long index) char& operator[](ssize_t index)
{return buffer[offs+(index<0?index+len:index)];} {return buffer[offs+(index<0?index+len:index)];}
// cast to bool: not empty? // cast to bool: not empty?
@ -88,11 +93,11 @@ public:
{return len>0;} {return len>0;}
// length: get current data length // length: get current data length
long length() const ssize_t length() const
{return len;} {return len;}
// capacity: get current max data length (spare one byte for end) // capacity: get current max data length (spare one byte for end)
long capacity() const ssize_t capacity() const
{return cap-1;} {return cap-1;}
// end: get pointer to byte after last data byte // end: get pointer to byte after last data byte
@ -105,19 +110,19 @@ public:
// reserve: reserve size bytes of memory and return // reserve: reserve size bytes of memory and return
// pointer to that memory (for copying something to it) // pointer to that memory (for copying something to it)
char* reserve(long size) char* reserve(size_t size)
{check(size); char* p=buffer+offs+len; len+=size; return p;} {check(size); char* p=buffer+offs+len; len+=size; return p;}
// append: append data at the end of the buffer // append: append data at the end of the buffer
StreamBuffer& append(char c) StreamBuffer& append(char c)
{check(1); buffer[offs+len++]=c; return *this;} {check(1); buffer[offs+len++]=c; return *this;}
StreamBuffer& append(char c, long count) StreamBuffer& append(char c, ssize_t count)
{if (count < 0) truncate(count); {if (count < 0) truncate(count);
else {check(count); memset(buffer+offs+len, c, count); len+=count;} else {check(count); memset(buffer+offs+len, c, count); len+=count;}
return *this;} return *this;}
StreamBuffer& append(const void* s, long size); StreamBuffer& append(const void* s, ssize_t size);
StreamBuffer& append(const char* s) StreamBuffer& append(const char* s)
{return append(s, s?strlen(s):0);} {return append(s, s?strlen(s):0);}
@ -125,7 +130,7 @@ public:
StreamBuffer& append(const StreamBuffer& s) StreamBuffer& append(const StreamBuffer& s)
{return append(s.buffer+s.offs, s.len);} {return append(s.buffer+s.offs, s.len);}
// operator += alias for set // operator += alias for append
StreamBuffer& operator+=(char c) StreamBuffer& operator+=(char c)
{return append(c);} {return append(c);}
@ -136,7 +141,7 @@ public:
{return append(s);} {return append(s);}
// set: clear buffer and fill with new data // set: clear buffer and fill with new data
StreamBuffer& set(const void* s, long size) StreamBuffer& set(const void* s, size_t size)
{clear(); return append(s, size);} {clear(); return append(s, size);}
StreamBuffer& set(const char* s) StreamBuffer& set(const char* s)
@ -154,61 +159,61 @@ public:
// replace: delete part of buffer (pos/length) and insert new data // replace: delete part of buffer (pos/length) and insert new data
StreamBuffer& replace( StreamBuffer& replace(
long pos, long length, const void* s, long size); ssize_t pos, ssize_t length, const void* s, ssize_t size);
StreamBuffer& replace(long pos, long length, const char* s) StreamBuffer& replace(ssize_t pos, ssize_t length, const char* s)
{return replace(pos, length, s, s?strlen(s):0);} {return replace(pos, length, s, s?strlen(s):0);}
StreamBuffer& replace(long pos, long length, const StreamBuffer& s) StreamBuffer& replace(ssize_t pos, ssize_t length, const StreamBuffer& s)
{return replace(pos, length, s.buffer+s.offs, s.len);} {return replace(pos, length, s.buffer+s.offs, s.len);}
// remove: delete from start/pos // remove: delete from start/pos
StreamBuffer& remove(long pos, long length) StreamBuffer& remove(ssize_t pos, ssize_t length)
{return replace(pos, length, NULL, 0);} {return replace(pos, length, NULL, 0);}
// remove from start: no memset, no function call, fast! // remove from start: no memset, no function call, fast!
StreamBuffer& remove(long length) StreamBuffer& remove(size_t length)
{if (length>len) length=len; {if (length>len) length=len;
offs+=length; len-=length; return *this;} offs+=length; len-=length; return *this;}
// truncate: delete end of buffer // truncate: delete end of buffer
StreamBuffer& truncate(long pos) StreamBuffer& truncate(ssize_t pos)
{return replace(pos, len, NULL, 0);} {return replace(pos, len, NULL, 0);}
// insert: insert new data into buffer // insert: insert new data into buffer
StreamBuffer& insert(long pos, const void* s, long size) StreamBuffer& insert(ssize_t pos, const void* s, ssize_t size)
{return replace(pos, 0, s, size);} {return replace(pos, 0, s, size);}
StreamBuffer& insert(long pos, const char* s) StreamBuffer& insert(ssize_t pos, const char* s)
{return replace(pos, 0, s, s?strlen(s):0);} {return replace(pos, 0, s, s?strlen(s):0);}
StreamBuffer& insert(long pos, const StreamBuffer& s) StreamBuffer& insert(ssize_t pos, const StreamBuffer& s)
{return replace(pos, 0, s.buffer+s.offs, s.len);} {return replace(pos, 0, s.buffer+s.offs, s.len);}
StreamBuffer& insert(long pos, char c) StreamBuffer& insert(ssize_t pos, char c)
{return replace(pos, 0, &c, 1);} {return replace(pos, 0, &c, 1);}
StreamBuffer& print(const char* fmt, ...) StreamBuffer& print(const char* fmt, ...)
__attribute__ ((format(printf,2,3))); __attribute__ ((format(printf,2,3)));
// find: get index of data in buffer or -1 // find: get index of data in buffer or -1
long find(char c, long start=0) const ssize_t find(char c, ssize_t start=0) const
{char* p; {char* p;
return (p = static_cast<char*>( return (p = static_cast<char*>(
memchr(buffer+offs+(start<0?start+len:start), memchr(buffer+offs+(start<0?start+len:start),
c, start<0?-start:len-start)))? c, start<0?-start:len-start)))?
p-(buffer+offs) : -1;} p-(buffer+offs) : -1;}
long find(const void* s, long size, long start=0) const; ssize_t find(const void* s, size_t size, ssize_t start=0) const;
long find(const char* s, long start=0) const ssize_t find(const char* s, ssize_t start=0) const
{return find(s, s?strlen(s):0, start);} {return find(s, s?strlen(s):0, start);}
long int find(const StreamBuffer& s, long start=0) const ssize_t find(const StreamBuffer& s, ssize_t start=0) const
{return find(s.buffer+s.offs, s.len, start);} {return find(s.buffer+s.offs, s.len, start);}
// startswith: returns true if first size bytes are equal // startswith: returns true if first size bytes are equal
bool startswith(const void* s, long size) const bool startswith(const void* s, size_t size) const
{return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;} {return len>=size ? memcmp(buffer+offs, s, size) == 0 : false;}
// startswith: returns true if first string is equal (empty string matches) // startswith: returns true if first string is equal (empty string matches)
@ -217,9 +222,9 @@ public:
// expand: create copy of StreamBuffer where all nonprintable characters // expand: create copy of StreamBuffer where all nonprintable characters
// are replaced by <xx> with xx being the hex code of the characters // are replaced by <xx> with xx being the hex code of the characters
StreamBuffer expand(long start, long length) const; StreamBuffer expand(ssize_t start, ssize_t length) const;
StreamBuffer expand(long start=0) const StreamBuffer expand(ssize_t start=0) const
{return expand(start, len);} {return expand(start, len);}
// dump: debug function, like expand but also show the 'hidden' memory // dump: debug function, like expand but also show the 'hidden' memory
@ -227,4 +232,13 @@ public:
StreamBuffer dump() const; StreamBuffer dump() const;
}; };
// printf size prefix for size_t and ssize_t
#if defined (__GNUC__) && __GNUC__ >= 3
#define PRINTF_SIZE_T_PREFIX "z"
#elif defined (_WIN32)
#define PRINTF_SIZE_T_PREFIX "I"
#else
#define PRINTF_SIZE_T_PREFIX ""
#endif
#endif #endif

View File

@ -18,14 +18,9 @@
***************************************************************/ ***************************************************************/
#include "StreamBusInterface.h" #include "StreamBusInterface.h"
#include "StreamError.h"
const char* StreamIoStatusStr[] = { StreamIoStatusStrClass StreamIoStatusStr;
"StreamIoSuccess",
"StreamIoTimeout",
"StreamIoNoReply",
"StreamIoEnd",
"StreamIoFault"
};
StreamBusInterfaceRegistrarBase* StreamBusInterfaceRegistrarBase::first; StreamBusInterfaceRegistrarBase* StreamBusInterfaceRegistrarBase::first;
@ -64,11 +59,17 @@ supportsAsyncRead()
StreamBusInterface* StreamBusInterface:: StreamBusInterface* StreamBusInterface::
find(Client* client, const char* busname, int addr, const char* param) find(Client* client, const char* busname, int addr, const char* param)
{ {
debug("StreamBusInterface::find(%s, %s, %d, \"%s\")\n",
client->name(), busname, addr, param);
StreamBusInterfaceRegistrarBase* r; StreamBusInterfaceRegistrarBase* r;
StreamBusInterface* bus; StreamBusInterface* bus;
for (r = r->first; r; r = r->next) for (r = StreamBusInterfaceRegistrarBase::first; r; r = r->next)
{ {
debug("StreamBusInterface::find %s check %s\n",
client->name(), r->name);
bus = r->find(client, busname, addr, param); bus = r->find(client, busname, addr, param);
debug("StreamBusInterface::find %s %s\n",
r->name, bus ? "matches" : "does not match");
if (bus) return bus; if (bus) return bus;
} }
return NULL; return NULL;

View File

@ -21,13 +21,26 @@
#define StreamBusInterface_h #define StreamBusInterface_h
#include <stddef.h> #include <stddef.h>
#include <StreamBuffer.h>
enum StreamIoStatus { enum StreamIoStatus {
StreamIoSuccess, StreamIoTimeout, StreamIoNoReply, StreamIoSuccess, StreamIoTimeout, StreamIoNoReply,
StreamIoEnd, StreamIoFault StreamIoEnd, StreamIoFault
}; };
extern const char* StreamIoStatusStr[]; class StreamIoStatusStrClass {
public:
const char* operator [] (int index) {
switch (index) {
case StreamIoSuccess: return "StreamIoSuccess";
case StreamIoTimeout: return "StreamIoTimeout";
case StreamIoNoReply: return "StreamIoNoReply";
case StreamIoEnd: return "StreamIoEnd";
case StreamIoFault: return "StreamIoFault";
default: return "illegal status";
}
}
} extern StreamIoStatusStr;
class StreamBusInterface class StreamBusInterface
{ {
@ -44,70 +57,53 @@ public:
virtual void connectCallback(StreamIoStatus status); virtual void connectCallback(StreamIoStatus status);
virtual void disconnectCallback(StreamIoStatus status); virtual void disconnectCallback(StreamIoStatus status);
virtual long priority(); virtual long priority();
virtual const char* name() = 0;
virtual const char* getInTerminator(size_t& length) = 0; virtual const char* getInTerminator(size_t& length) = 0;
virtual const char* getOutTerminator(size_t& length) = 0; virtual const char* getOutTerminator(size_t& length) = 0;
public: public:
virtual const char* name() = 0;
virtual ~Client(); virtual ~Client();
protected: protected:
StreamBusInterface* businterface; StreamBusInterface* businterface;
bool busSupportsEvent() { bool busSupportsEvent() {
if (businterface) return businterface && businterface->supportsEvent();
return businterface->supportsEvent();
else return false;
} }
bool busSupportsAsyncRead() { bool busSupportsAsyncRead() {
if (businterface) return businterface && businterface->supportsAsyncRead();
return businterface->supportsAsyncRead();
else return false;
} }
bool busAcceptEvent(unsigned long mask, bool busAcceptEvent(unsigned long mask,
unsigned long replytimeout_ms) { unsigned long replytimeout_ms) {
if (businterface) return businterface && businterface->acceptEvent(mask, replytimeout_ms);
return businterface->acceptEvent(mask, replytimeout_ms);
else return false;
} }
void busRelease() { void busRelease() {
if (businterface) if (businterface) businterface->release();
businterface->release();
} }
bool busLockRequest(unsigned long timeout_ms) { bool busLockRequest(unsigned long timeout_ms) {
if (businterface) return businterface && businterface->lockRequest(timeout_ms);
return businterface->lockRequest(timeout_ms);
else return false;
} }
bool busUnlock() { bool busUnlock() {
if (businterface) return businterface && businterface->unlock();
return businterface->unlock();
else return false;
} }
bool busWriteRequest(const void* output, size_t size, bool busWriteRequest(const void* output, size_t size,
unsigned long timeout_ms) { unsigned long timeout_ms) {
if (businterface) return businterface && businterface->writeRequest(output, size, timeout_ms);
return businterface->writeRequest(output, size, timeout_ms);
else return false;
} }
bool busReadRequest(unsigned long replytimeout_ms, bool busReadRequest(unsigned long replytimeout_ms,
unsigned long readtimeout_ms, long expectedLength, unsigned long readtimeout_ms, long expectedLength,
bool async) { bool async) {
if (businterface) return businterface && businterface->readRequest(replytimeout_ms,
return businterface->readRequest(replytimeout_ms,
readtimeout_ms, expectedLength, async); readtimeout_ms, expectedLength, async);
else return false;
} }
void busFinish() { void busFinish() {
if (businterface) if (businterface) businterface->finish();
businterface->finish();
} }
bool busConnectRequest(unsigned long timeout_ms) { bool busConnectRequest(unsigned long timeout_ms) {
if (businterface) return businterface && businterface->connectRequest(timeout_ms);
return businterface->connectRequest(timeout_ms);
else return false;
} }
bool busDisconnect() { bool busDisconnect() {
if (businterface) return businterface && businterface->disconnectRequest();
return businterface->disconnectRequest(); }
else return false; void busPrintStatus(StreamBuffer& buffer) {
if (businterface) businterface->printStatus(buffer);
} }
}; };
@ -157,6 +153,7 @@ protected:
virtual bool connectRequest(unsigned long connecttimeout_ms); virtual bool connectRequest(unsigned long connecttimeout_ms);
virtual bool disconnectRequest(); virtual bool disconnectRequest();
virtual void finish(); virtual void finish();
virtual void printStatus(StreamBuffer& buffer) {};
// pure virtual // pure virtual
virtual bool lockRequest(unsigned long timeout_ms) = 0; virtual bool lockRequest(unsigned long timeout_ms) = 0;

View File

@ -23,6 +23,8 @@
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#define P PRINTF_SIZE_T_PREFIX
enum Commands { end_cmd, in_cmd, out_cmd, wait_cmd, event_cmd, exec_cmd, enum Commands { end_cmd, in_cmd, out_cmd, wait_cmd, event_cmd, exec_cmd,
connect_cmd, disconnect_cmd }; connect_cmd, disconnect_cmd };
const char* commandStr[] = { "end", "in", "out", "wait", "event", "exec", const char* commandStr[] = { "end", "in", "out", "wait", "event", "exec",
@ -57,7 +59,7 @@ static char* printCommands(StreamBuffer& buffer, const char* c)
break; break;
case wait_cmd: case wait_cmd:
timeout = extract<unsigned long>(c); timeout = extract<unsigned long>(c);
buffer.print(" wait %ld;\n # ms", timeout); buffer.print(" wait %ld; # ms\n", timeout);
break; break;
case event_cmd: case event_cmd:
eventnumber = extract<unsigned long>(c); eventnumber = extract<unsigned long>(c);
@ -163,7 +165,7 @@ attachBus(const char* busname, int addr, const char* param)
businterface = StreamBusInterface::find(this, busname, addr, param); businterface = StreamBusInterface::find(this, busname, addr, param);
if (!businterface) if (!businterface)
{ {
error("Businterface '%s' not found for '%s'\n", error("Cannot find a bus named '%s' for '%s'\n",
busname, name()); busname, name());
return false; return false;
} }
@ -341,6 +343,7 @@ compileCommand(StreamProtocolParser::Protocol* protocol,
return false; return false;
} }
args++; args++;
while (isspace(*args)) args++;
} }
buffer.append(&eventmask, sizeof(eventmask)); buffer.append(&eventmask, sizeof(eventmask));
if (*args) if (*args)
@ -815,7 +818,7 @@ lockCallback(StreamIoStatus status)
{ {
MutexLock lock(this); MutexLock lock(this);
debug("StreamCore::lockCallback(%s, status=%s)\n", debug("StreamCore::lockCallback(%s, status=%s)\n",
name(), status ? "Timeout" : "Success"); name(), StreamIoStatusStr[status]);
if (!(flags & LockPending)) if (!(flags & LockPending))
{ {
error("StreamCore::lockCallback(%s) called unexpectedly\n", error("StreamCore::lockCallback(%s) called unexpectedly\n",
@ -829,9 +832,21 @@ lockCallback(StreamIoStatus status)
case StreamIoSuccess: case StreamIoSuccess:
break; break;
case StreamIoTimeout: case StreamIoTimeout:
error("%s: Cannot lock device within %ld ms, device seems to be busy\n",
name(), lockTimeout);
flags &= ~BusOwner;
finishProtocol(LockTimeout);
return;
case StreamIoFault:
error("%s: Locking failed because of a device fault\n",
name());
flags &= ~BusOwner;
finishProtocol(LockTimeout); finishProtocol(LockTimeout);
return; return;
default: default:
error("StreamCore::lockCallback(%s) unexpected status %s\n",
name(), StreamIoStatusStr[status]);
flags &= ~BusOwner;
finishProtocol(Fault); finishProtocol(Fault);
return; return;
} }
@ -982,7 +997,7 @@ readCallback(StreamIoStatus status,
finishProtocol(ReplyTimeout); finishProtocol(ReplyTimeout);
return 0; return 0;
case StreamIoFault: case StreamIoFault:
error("%s: I/O error after reading %ld byte%s: \"%s%s\"\n", error("%s: I/O error after reading %"P"d byte%s: \"%s%s\"\n",
name(), name(),
inputBuffer.length(), inputBuffer.length()==1 ? "" : "s", inputBuffer.length(), inputBuffer.length()==1 ? "" : "s",
inputBuffer.length() > 20 ? "..." : "", inputBuffer.length() > 20 ? "..." : "",
@ -991,7 +1006,7 @@ readCallback(StreamIoStatus status,
return 0; return 0;
} }
inputBuffer.append(input, size); inputBuffer.append(input, size);
debug("StreamCore::readCallback(%s) inputBuffer=\"%s\", size %ld\n", debug("StreamCore::readCallback(%s) inputBuffer=\"%s\", size %"P"d\n",
name(), inputBuffer.expand()(), inputBuffer.length()); name(), inputBuffer.expand()(), inputBuffer.length());
if (*activeCommand != in_cmd) if (*activeCommand != in_cmd)
{ {
@ -1184,6 +1199,7 @@ normal_format:
int consumed; int consumed;
// code layout: // code layout:
// formatstring <eos> StreamFormat [info] // formatstring <eos> StreamFormat [info]
formatstring.clear();
commandIndex = StreamProtocolParser::printString(formatstring, commandIndex); commandIndex = StreamProtocolParser::printString(formatstring, commandIndex);
StreamFormat fmt = extract<StreamFormat>(commandIndex); StreamFormat fmt = extract<StreamFormat>(commandIndex);
@ -1303,8 +1319,8 @@ normal_format:
inputLine.length()-consumedInput > 20 ? "..." : "", inputLine.length()-consumedInput > 20 ? "..." : "",
formatstring()); formatstring());
else else
error("%s: Format \"%%%s\" has data type %s which does not match variable \"%s\".\n", error("%s: Format \"%%%s\" has data type %s which does not match the type of \"%s\".\n",
name(), formatstring(), StreamFormatTypeStr[fmt.type], fieldName); name(), formatstring(), StreamFormatTypeStr[fmt.type], fieldAddress ? fieldName : name());
} }
return false; return false;
} }
@ -1734,4 +1750,25 @@ disconnectCallback(StreamIoStatus status)
} }
} }
void StreamCore::
printStatus(StreamBuffer& buffer)
{
buffer.print("active command=%s ",
activeCommand ? commandName(*activeCommand) : "NULL");
buffer.print("flags=0x%04lx ", flags);
if (flags & IgnoreExtraInput) buffer.append("IgnoreExtraInput ");
if (flags & InitRun) buffer.append("InitRun ");
if (flags & AsyncMode) buffer.append("AsyncMode ");
if (flags & GotValue) buffer.append("GotValue ");
if (flags & BusOwner) buffer.append("BusOwner ");
if (flags & Separator) buffer.append("Separator ");
if (flags & ScanTried) buffer.append("ScanTried ");
if (flags & AcceptInput) buffer.append("AcceptInput ");
if (flags & AcceptEvent) buffer.append("AcceptEvent ");
if (flags & LockPending) buffer.append("LockPending ");
if (flags & WritePending) buffer.append("WritePending ");
if (flags & WaitPending) buffer.append("WaitPending ");
busPrintStatus(buffer);
}
#include "streamReferences" #include "streamReferences"

View File

@ -219,6 +219,7 @@ public:
bool parse(const char* filename, const char* protocolname); bool parse(const char* filename, const char* protocolname);
void printProtocol(); void printProtocol();
const char* name() { return streamname; } const char* name() { return streamname; }
void printStatus(StreamBuffer& buffer);
}; };
#endif #endif

View File

@ -18,7 +18,9 @@
* * * *
***************************************************************/ ***************************************************************/
#define epicsExportSharedSymbols
#include "devStream.h" #include "devStream.h"
#undef epicsExportSharedSymbols
#include "StreamCore.h" #include "StreamCore.h"
#include "StreamError.h" #include "StreamError.h"
@ -31,6 +33,9 @@
extern "C" { extern "C" {
#endif #endif
#define epicsAlarmGLOBAL
#include <alarm.h>
#undef epicsAlarmGLOBAL
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
@ -39,8 +44,6 @@ extern "C" {
#include <recSup.h> #include <recSup.h>
#include <recGbl.h> #include <recGbl.h>
#include <devLib.h> #include <devLib.h>
#define epicsAlarmGLOBAL
#include <alarm.h>
#include <callback.h> #include <callback.h>
#ifdef EPICS_3_13 #ifdef EPICS_3_13
@ -347,6 +350,12 @@ report(int interest)
{ {
printf(" %s: %s\n", pstream->name(), printf(" %s: %s\n", pstream->name(),
pstream->ioLink->value.instio.string); pstream->ioLink->value.instio.string);
if (interest == 3)
{
StreamBuffer buffer;
pstream->printStatus(buffer);
printf(" %s\n", buffer());
}
} }
} }
return OK; return OK;
@ -419,26 +428,35 @@ long streamInitRecord(dbCommon* record, const struct link *ioLink,
if (!pstream) if (!pstream)
{ {
// initialize the first time // initialize the first time
debug("streamInitRecord(%s): create new Stream object\n",
record->name);
pstream = new Stream(record, ioLink, readData, writeData); pstream = new Stream(record, ioLink, readData, writeData);
record->dpvt = pstream; record->dpvt = pstream;
} else { } else {
// stop any running protocol // stop any running protocol
debug("streamInitRecord(%s): stop running protocol\n",
record->name);
pstream->finishProtocol(Stream::Abort); pstream->finishProtocol(Stream::Abort);
} }
// scan the i/o link // scan the i/o link
debug("streamInitRecord(%s): parse link \"%s\"\n",
record->name, ioLink->value.instio.string);
pstream->parseLink(ioLink, filename, protocol, pstream->parseLink(ioLink, filename, protocol,
busname, &addr, busparam); busname, &addr, busparam);
// (re)initialize bus and protocol // (re)initialize bus and protocol
debug("streamInitRecord(%s): calling initRecord\n",
record->name);
long status = pstream->initRecord(filename, protocol, long status = pstream->initRecord(filename, protocol,
busname, addr, busparam); busname, addr, busparam);
if (status != OK && status != DO_NOT_CONVERT) if (status != OK && status != DO_NOT_CONVERT)
{ {
error("%s: Record initialization failed\n", record->name); error("%s: Record initialization failed\n", record->name);
} }
if (!pstream->ioscanpvt) else if (!pstream->ioscanpvt)
{ {
scanIoInit(&pstream->ioscanpvt); scanIoInit(&pstream->ioscanpvt);
} }
debug("streamInitRecord(%s) done status=%#lx\n", record->name, status);
return status; return status;
} }
@ -608,6 +626,8 @@ initRecord(const char* filename, const char* protocol,
// It is safe to call this function again with different arguments // It is safe to call this function again with different arguments
// attach to bus interface // attach to bus interface
debug("Stream::initRecord %s: attachBus(%s, %d, \"%s\")\n",
name(), busname, addr, busparam);
if (!attachBus(busname, addr, busparam)) if (!attachBus(busname, addr, busparam))
{ {
error("%s: Can't attach to bus %s %d\n", error("%s: Can't attach to bus %s %d\n",
@ -616,6 +636,8 @@ initRecord(const char* filename, const char* protocol,
} }
// parse protocol file // parse protocol file
debug("Stream::initRecord %s: parse(%s, %s)\n",
name(), filename, protocol);
if (!parse(filename, protocol)) if (!parse(filename, protocol))
{ {
error("%s: Protocol parse error\n", error("%s: Protocol parse error\n",

View File

@ -1037,7 +1037,7 @@ compileNumber(unsigned long& number, const char*& source, unsigned long max)
"Garbage after numeric value: %s\n", buffer()); "Garbage after numeric value: %s\n", buffer());
return false; return false;
} }
if (n < 0 || n > max) if (n > max)
{ {
debug("StreamProtocolParser::Protocol::compileNumber: %s\n", debug("StreamProtocolParser::Protocol::compileNumber: %s\n",
buffer.expand()()); buffer.expand()());

View File

@ -26,6 +26,24 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
/* timezone in UNIX contains the seconds between UTC and local time,
but not in Free-BSD! Here timezone() is a function delivering
the time zone abbreviation (e.g. CET). Alternatively, the timezone
value can also be gained from tm_gmtoff of the tm-structure.
HJK, 4.4.14 */
/* The same seems to be true for other BSDs. DZ. */
#if defined(__FreeBSD__) || \
defined(__NetBSD__) || \
defined(__OpenBSD__) || \
defined(__bsdi__ ) || \
defined(__DragonFly__)
static int timezone_bsd=0;
#define timezone timezone_bsd
#define tzset() { struct tm tm; time_t timet; tzset(); time(&timet); \
localtime_r(&timet, &tm); timezone=tm.tm_gmtoff; }
#endif
#ifdef _WIN32 #ifdef _WIN32
#define tzset() _tzset() #define tzset() _tzset()
#define timezone _timezone #define timezone _timezone

View File

@ -23,7 +23,7 @@
#define STREAM_MAJOR 2 #define STREAM_MAJOR 2
#define STREAM_MINOR 6 #define STREAM_MINOR 6
#define STREAM_PATCHLEVEL 0 #define STREAM_PATCHLEVEL 6
#if defined(__vxworks) || defined(vxWorks) #if defined(__vxworks) || defined(vxWorks)
#include <vxWorks.h> #include <vxWorks.h>
@ -41,7 +41,7 @@
#define INIT_RUN (!interruptAccept) #define INIT_RUN (!interruptAccept)
#include <epicsVersion.h> #include <epicsVersion.h>
#ifdef BASE_RELEASE #ifdef BASE_VERSION
#define EPICS_3_13 #define EPICS_3_13
#endif #endif
@ -49,6 +49,11 @@
extern "C" { extern "C" {
#endif #endif
#ifdef epicsExportSharedSymbols
# define devStream_epicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <stdio.h> #include <stdio.h>
#include <dbCommon.h> #include <dbCommon.h>
#include <dbScan.h> #include <dbScan.h>
@ -56,6 +61,11 @@ extern "C" {
/* #include <dbFldTypes.h> */ /* #include <dbFldTypes.h> */
#include <dbAccess.h> #include <dbAccess.h>
#ifdef devStream_epicsExportSharedSymbols
# define epicsExportSharedSymbols
# include "shareLib.h"
#endif
#if defined(__cplusplus) && defined(EPICS_3_13) #if defined(__cplusplus) && defined(EPICS_3_13)
} }
#endif #endif
@ -76,16 +86,16 @@ extern const char StreamVersion [];
typedef long (*streamIoFunction) (dbCommon*, format_t*); typedef long (*streamIoFunction) (dbCommon*, format_t*);
epicsShareExtern long streamInit(int after); epicsShareFunc long streamInit(int after);
epicsShareExtern long streamInitRecord(dbCommon *record, epicsShareFunc long streamInitRecord(dbCommon *record,
const struct link *ioLink, const struct link *ioLink,
streamIoFunction readData, streamIoFunction writeData); streamIoFunction readData, streamIoFunction writeData);
epicsShareExtern long streamReport(int interest); epicsShareFunc long streamReport(int interest);
epicsShareExtern long streamReadWrite(dbCommon *record); epicsShareFunc long streamReadWrite(dbCommon *record);
epicsShareExtern long streamGetIointInfo(int cmd, epicsShareFunc long streamGetIointInfo(int cmd,
dbCommon *record, IOSCANPVT *ppvt); dbCommon *record, IOSCANPVT *ppvt);
epicsShareExtern long streamPrintf(dbCommon *record, format_t *format, ...); epicsShareFunc long streamPrintf(dbCommon *record, format_t *format, ...);
epicsShareExtern long streamScanfN(dbCommon *record, format_t *format, epicsShareFunc long streamScanfN(dbCommon *record, format_t *format,
void*, size_t maxStringSize); void*, size_t maxStringSize);
/* backward compatibility stuff */ /* backward compatibility stuff */

View File

@ -31,9 +31,11 @@ PROD_LIBS = stream
ifdef ASYN ifdef ASYN
# edit asynRegistrars.dbd if necessary # edit asynRegistrars.dbd if necessary
streamApp_DBD += asynRegistrars.dbd streamApp_DBD += asynRegistrars.dbd
# add asyn.dbd if you want to have asyn Record and asyn device supports # add asynRecord.dbd if you like
# streamApp_DBD += asyn.dbd streamApp_DBD += asynRecord.dbd
PROD_LIBS += asyn PROD_LIBS += asyn
# cygwin needs separate RPC library for asyn
PROD_SYS_LIBS_cygwin32 += $(CYGWIN_RPC_LIB)
endif endif
ifneq ($(words $(CALC) $(SYNAPPS)), 0) ifneq ($(words $(CALC) $(SYNAPPS)), 0)
@ -49,7 +51,7 @@ endif
streamApp_DBD += stream.dbd streamApp_DBD += stream.dbd
ifdef PCRE ifdef PCRE
LIB_LIBS += pcre PROD_LIBS += pcre
else else
ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0) ifneq ($(words $(PCRE_LIB) $(PCRE_INCLUDE)),0)
PROD_SYS_LIBS_DEFAULT += pcre PROD_SYS_LIBS_DEFAULT += pcre
@ -66,7 +68,7 @@ CPPFLAGS += -DDEBUGFILE=StreamDebug.log
include $(TOP)/configure/RULES include $(TOP)/configure/RULES
ifeq ($(EPICS_REVISION),14) ifeq ($(BASE_3_14), YES)
clean:: myclean clean:: myclean
else else
clean: myclean clean: myclean

View File

@ -40,11 +40,13 @@ proc escape {string} {
} }
proc sendReply {sock text} { proc sendReply {sock text} {
.$sock.t mark set insert end catch {
.$sock.t insert end $text # ignore that socket may already be closed
.$sock.t see end .$sock.t mark set insert end
puts -nonewline $sock $text .$sock.t insert end $text
# puts "sending \"[escape $text]\"\n" .$sock.t see end
puts -nonewline $sock $text
}
} }
proc checkNum {n} { proc checkNum {n} {
@ -89,7 +91,7 @@ proc receiveHandler {sock} {
"start" { "start" {
set wait [checkNum [lindex $l 1]] set wait [checkNum [lindex $l 1]]
set ::counter 0 set ::counter 0
after $wait sendAsync $wait [list [lrange $l 2 end-1]] after $wait [list sendAsync $wait "[string range $a [string wordend $a 7] end]"]
sendReply $sock "Started\n" sendReply $sock "Started\n"
} }
"stop" { "stop" {
@ -131,7 +133,7 @@ proc receiveHandler {sock} {
proc sendAsync {wait message} { proc sendAsync {wait message} {
if {$::counter < 0} return if {$::counter < 0} return
foreach term [array names ::socket] { foreach term [array names ::socket] {
sendReply $::socket($term) "Message number [incr ::counter] $message\n"; sendReply $::socket($term) "Message number [incr ::counter]$message";
} }
after $wait sendAsync $wait [list $message] after $wait sendAsync $wait [list $message]
} }

View File

@ -41,7 +41,7 @@ proc receiveHandler {sock} {
} }
proc startioc {} { proc startioc {} {
global debug records protocol startup port sock ioc testname env streamversion global debug records protocol startup port sock ioc testname env streamversion asynversion
set fd [open test.db w] set fd [open test.db w]
puts $fd $records puts $fd $records
close $fd close $fd
@ -52,6 +52,9 @@ proc startioc {} {
if [info exists streamversion] { if [info exists streamversion] {
puts $fd "#!/usr/local/bin/iocsh" puts $fd "#!/usr/local/bin/iocsh"
if [info exists asynversion] {
puts $fd "require asyn,$asynversion"
}
puts $fd "require stream2,$streamversion" puts $fd "require stream2,$streamversion"
} else { } else {
puts $fd "#!../O.$env(EPICS_HOST_ARCH)/streamApp" puts $fd "#!../O.$env(EPICS_HOST_ARCH)/streamApp"
@ -202,3 +205,7 @@ if {[lindex $argv 0] == "-sls"} {
set streamversion [lindex $argv 1] set streamversion [lindex $argv 1]
set argv [lrange $argv 2 end] set argv [lrange $argv 2 end]
} }
if {[lindex $argv 0] == "-asyn"} {
set asynversion [lindex $argv 1]
set argv [lrange $argv 2 end]
}

View File

@ -7,7 +7,7 @@ source streamtestlib.tcl
# Send commands to the ioc shell with ioccmd # Send commands to the ioc shell with ioccmd
set records { set records {
record (ao, "DZ:test1") record (stringout, "DZ:test1")
{ {
field (DTYP, "stream") field (DTYP, "stream")
field (OUT, "@test.proto test1 device") field (OUT, "@test.proto test1 device")
@ -15,7 +15,225 @@ set records {
} }
set protocol { set protocol {
test1 {out 0x55 0x40 0x04 0x00 0x00 'z;' "%<sum>";} Terminator="\n";
test1 {
out "sum %s %9.1<sum>"; in "sum %=s %9.1<sum>";
out "sum8 %s %9.1<sum8>"; in "sum8 %=s %9.1<sum8>";
out "sum16 %s %9.1<sum16>"; in "sum16 %=s %9.1<sum16>";
out "sum32 %s %9.1<sum32>"; in "sum32 %=s %9.1<sum32>";
out "nsum %s %9.1<nsum>"; in "nsum %=s %9.1<nsum>";
out "negsum %s %9.1<negsum>"; in "negsum %=s %9.1<negsum>";
out "-sum %s %9.1<-sum>"; in "-sum %=s %9.1<-sum>";
out "nsum8 %s %9.1<nsum8>"; in "nsum8 %=s %9.1<nsum8>";
out "negsum8 %s %9.1<negsum8>"; in "negsum8 %=s %9.1<negsum8>";
out "-sum8 %s %9.1<-sum8>"; in "-sum8 %=s %9.1<-sum8>";
out "nsum16 %s %9.1<nsum16>"; in "nsum16 %=s %9.1<nsum16>";
out "negsum16 %s %9.1<negsum1>"; in "negsum16 %=s %9.1<negsum1>";
out "-sum16 %s %9.1<-sum16>"; in "-sum16 %=s %9.1<-sum16>";
out "nsum32 %s %9.1<nsum32>"; in "nsum32 %=s %9.1<nsum32>";
out "negsum32 %s %9.1<negsum3>"; in "negsum32 %=s %9.1<negsum3>";
out "-sum32 %s %9.1<-sum32>"; in "-sum32 %=s %9.1<-sum32>";
out "notsum %s %9.1<notsum>"; in "notsum %=s %9.1<notsum>";
out "~sum %s %9.1<~sum>"; in "~sum %=s %9.1<~sum>";
out "xor %s %9.1<xor>"; in "xor %=s %9.1<xor>";
out "xor8 %s %9.1<xor8>"; in "xor8 %=s %9.1<xor8>";
out "xor7 %s %9.1<xor7>"; in "xor7 %=s %9.1<xor7>";
out "crc8 %s %9.1<crc8>"; in "crc8 %=s %9.1<crc8>";
out "ccitt8 %s %9.1<ccitt8>"; in "ccitt8 %=s %9.1<ccitt8>";
out "crc16 %s %9.1<crc16>"; in "crc16 %=s %9.1<crc16>";
out "crc16r %s %9.1<crc16r>"; in "crc16r %=s %9.1<crc16r>";
out "ccitt16 %s %9.1<ccitt16>"; in "ccitt16 %=s %9.1<ccitt16>";
out "ccitt16a %s %9.1<ccitt16a>"; in "ccitt16a %=s %9.1<ccitt16a>";
out "ccitt16x %s %9.1<ccitt16x>"; in "ccitt16x %=s %9.1<ccitt16x>";
out "crc16c %s %9.1<crc16c>"; in "crc16c %=s %9.1<crc16c>";
out "xmodem %s %9.1<xmodem>"; in "xmodem %=s %9.1<xmodem>";
out "crc32 %s %9.1<crc32>"; in "crc32 %=s %9.1<crc32>";
out "crc32r %s %9.1<crc32r>"; in "crc32r %=s %9.1<crc32r>";
out "jamcrc %s %9.1<jamcrc>"; in "jamcrc %=s %9.1<jamcrc>";
out "adler32 %s %9.1<adler32>"; in "adler32 %=s %9.1<adler32>";
out "hexsum8 %s %9.1<hexsum8>"; in "hexsum8 %=s %9.1<hexsum8>";
out "sum %s %09.1<sum>"; in "sum %=s %09.1<sum>";
out "sum8 %s %09.1<sum8>"; in "sum8 %=s %09.1<sum8>";
out "sum16 %s %09.1<sum16>"; in "sum16 %=s %09.1<sum16>";
out "sum32 %s %09.1<sum32>"; in "sum32 %=s %09.1<sum32>";
out "nsum %s %09.1<nsum>"; in "nsum %=s %09.1<nsum>";
out "negsum %s %09.1<negsum>"; in "negsum %=s %09.1<negsum>";
out "-sum %s %09.1<-sum>"; in "-sum %=s %09.1<-sum>";
out "nsum8 %s %09.1<nsum8>"; in "nsum8 %=s %09.1<nsum8>";
out "negsum8 %s %09.1<negsum8>"; in "negsum8 %=s %09.1<negsum8>";
out "-sum8 %s %09.1<-sum8>"; in "-sum8 %=s %09.1<-sum8>";
out "nsum16 %s %09.1<nsum16>"; in "nsum16 %=s %09.1<nsum16>";
out "negsum16 %s %09.1<negsum1>"; in "negsum16 %=s %09.1<negsum1>";
out "-sum16 %s %09.1<-sum16>"; in "-sum16 %=s %09.1<-sum16>";
out "nsum32 %s %09.1<nsum32>"; in "nsum32 %=s %09.1<nsum32>";
out "negsum32 %s %09.1<negsum3>"; in "negsum32 %=s %09.1<negsum3>";
out "-sum32 %s %09.1<-sum32>"; in "-sum32 %=s %09.1<-sum32>";
out "notsum %s %09.1<notsum>"; in "notsum %=s %09.1<notsum>";
out "~sum %s %09.1<~sum>"; in "~sum %=s %09.1<~sum>";
out "xor %s %09.1<xor>"; in "xor %=s %09.1<xor>";
out "xor8 %s %09.1<xor8>"; in "xor8 %=s %09.1<xor8>";
out "xor7 %s %09.1<xor7>"; in "xor7 %=s %09.1<xor7>";
out "crc8 %s %09.1<crc8>"; in "crc8 %=s %09.1<crc8>";
out "ccitt8 %s %09.1<ccitt8>"; in "ccitt8 %=s %09.1<ccitt8>";
out "crc16 %s %09.1<crc16>"; in "crc16 %=s %09.1<crc16>";
out "crc16r %s %09.1<crc16r>"; in "crc16r %=s %09.1<crc16r>";
out "ccitt16 %s %09.1<ccitt16>"; in "ccitt16 %=s %09.1<ccitt16>";
out "ccitt16a %s %09.1<ccitt16a>"; in "ccitt16a %=s %09.1<ccitt16a>";
out "ccitt16x %s %09.1<ccitt16x>"; in "ccitt16x %=s %09.1<ccitt16x>";
out "crc16c %s %09.1<crc16c>"; in "crc16c %=s %09.1<crc16c>";
out "xmodem %s %09.1<xmodem>"; in "xmodem %=s %09.1<xmodem>";
out "crc32 %s %09.1<crc32>"; in "crc32 %=s %09.1<crc32>";
out "crc32r %s %09.1<crc32r>"; in "crc32r %=s %09.1<crc32r>";
out "jamcrc %s %09.1<jamcrc>"; in "jamcrc %=s %09.1<jamcrc>";
out "adler32 %s %09.1<adler32>"; in "adler32 %=s %09.1<adler32>";
out "hexsum8 %s %09.1<hexsum8>"; in "hexsum8 %=s %09.1<hexsum8>";
out "sum %s %-9.1<sum>"; in "sum %=s %-9.1<sum>";
out "sum8 %s %-9.1<sum8>"; in "sum8 %=s %-9.1<sum8>";
out "sum16 %s %-9.1<sum16>"; in "sum16 %=s %-9.1<sum16>";
out "sum32 %s %-9.1<sum32>"; in "sum32 %=s %-9.1<sum32>";
out "nsum %s %-9.1<nsum>"; in "nsum %=s %-9.1<nsum>";
out "negsum %s %-9.1<negsum>"; in "negsum %=s %-9.1<negsum>";
out "-sum %s %-9.1<-sum>"; in "-sum %=s %-9.1<-sum>";
out "nsum8 %s %-9.1<nsum8>"; in "nsum8 %=s %-9.1<nsum8>";
out "negsum8 %s %-9.1<negsum8>"; in "negsum8 %=s %-9.1<negsum8>";
out "-sum8 %s %-9.1<-sum8>"; in "-sum8 %=s %-9.1<-sum8>";
out "nsum16 %s %-9.1<nsum16>"; in "nsum16 %=s %-9.1<nsum16>";
out "negsum16 %s %-9.1<negsum1>"; in "negsum16 %=s %-9.1<negsum1>";
out "-sum16 %s %-9.1<-sum16>"; in "-sum16 %=s %-9.1<-sum16>";
out "nsum32 %s %-9.1<nsum32>"; in "nsum32 %=s %-9.1<nsum32>";
out "negsum32 %s %-9.1<negsum3>"; in "negsum32 %=s %-9.1<negsum3>";
out "-sum32 %s %-9.1<-sum32>"; in "-sum32 %=s %-9.1<-sum32>";
out "notsum %s %-9.1<notsum>"; in "notsum %=s %-9.1<notsum>";
out "~sum %s %-9.1<~sum>"; in "~sum %=s %-9.1<~sum>";
out "xor %s %-9.1<xor>"; in "xor %=s %-9.1<xor>";
out "xor8 %s %-9.1<xor8>"; in "xor8 %=s %-9.1<xor8>";
out "xor7 %s %-9.1<xor7>"; in "xor7 %=s %-9.1<xor7>";
out "crc8 %s %-9.1<crc8>"; in "crc8 %=s %-9.1<crc8>";
out "ccitt8 %s %-9.1<ccitt8>"; in "ccitt8 %=s %-9.1<ccitt8>";
out "crc16 %s %-9.1<crc16>"; in "crc16 %=s %-9.1<crc16>";
out "crc16r %s %-9.1<crc16r>"; in "crc16r %=s %-9.1<crc16r>";
out "ccitt16 %s %-9.1<ccitt16>"; in "ccitt16 %=s %-9.1<ccitt16>";
out "ccitt16a %s %-9.1<ccitt16a>"; in "ccitt16a %=s %-9.1<ccitt16a>";
out "ccitt16x %s %-9.1<ccitt16x>"; in "ccitt16x %=s %-9.1<ccitt16x>";
out "crc16c %s %-9.1<crc16c>"; in "crc16c %=s %-9.1<crc16c>";
out "xmodem %s %-9.1<xmodem>"; in "xmodem %=s %-9.1<xmodem>";
out "crc32 %s %-9.1<crc32>"; in "crc32 %=s %-9.1<crc32>";
out "crc32r %s %-9.1<crc32r>"; in "crc32r %=s %-9.1<crc32r>";
out "jamcrc %s %-9.1<jamcrc>"; in "jamcrc %=s %-9.1<jamcrc>";
out "adler32 %s %-9.1<adler32>"; in "adler32 %=s %-9.1<adler32>";
out "hexsum8 %s %-9.1<hexsum8>"; in "hexsum8 %=s %-9.1<hexsum8>";
out "sum %s %#9.1<sum>"; in "sum %=s %#9.1<sum>";
out "sum8 %s %#9.1<sum8>"; in "sum8 %=s %#9.1<sum8>";
out "sum16 %s %#9.1<sum16>"; in "sum16 %=s %#9.1<sum16>";
out "sum32 %s %#9.1<sum32>"; in "sum32 %=s %#9.1<sum32>";
out "nsum %s %#9.1<nsum>"; in "nsum %=s %#9.1<nsum>";
out "negsum %s %#9.1<negsum>"; in "negsum %=s %#9.1<negsum>";
out "-sum %s %#9.1<-sum>"; in "-sum %=s %#9.1<-sum>";
out "nsum8 %s %#9.1<nsum8>"; in "nsum8 %=s %#9.1<nsum8>";
out "negsum8 %s %#9.1<negsum8>"; in "negsum8 %=s %#9.1<negsum8>";
out "-sum8 %s %#9.1<-sum8>"; in "-sum8 %=s %#9.1<-sum8>";
out "nsum16 %s %#9.1<nsum16>"; in "nsum16 %=s %#9.1<nsum16>";
out "negsum16 %s %#9.1<negsum1>"; in "negsum16 %=s %#9.1<negsum1>";
out "-sum16 %s %#9.1<-sum16>"; in "-sum16 %=s %#9.1<-sum16>";
out "nsum32 %s %#9.1<nsum32>"; in "nsum32 %=s %#9.1<nsum32>";
out "negsum32 %s %#9.1<negsum3>"; in "negsum32 %=s %#9.1<negsum3>";
out "-sum32 %s %#9.1<-sum32>"; in "-sum32 %=s %#9.1<-sum32>";
out "notsum %s %#9.1<notsum>"; in "notsum %=s %#9.1<notsum>";
out "~sum %s %#9.1<~sum>"; in "~sum %=s %#9.1<~sum>";
out "xor %s %#9.1<xor>"; in "xor %=s %#9.1<xor>";
out "xor8 %s %#9.1<xor8>"; in "xor8 %=s %#9.1<xor8>";
out "xor7 %s %#9.1<xor7>"; in "xor7 %=s %#9.1<xor7>";
out "crc8 %s %#9.1<crc8>"; in "crc8 %=s %#9.1<crc8>";
out "ccitt8 %s %#9.1<ccitt8>"; in "ccitt8 %=s %#9.1<ccitt8>";
out "crc16 %s %#9.1<crc16>"; in "crc16 %=s %#9.1<crc16>";
out "crc16r %s %#9.1<crc16r>"; in "crc16r %=s %#9.1<crc16r>";
out "ccitt16 %s %#9.1<ccitt16>"; in "ccitt16 %=s %#9.1<ccitt16>";
out "ccitt16a %s %#9.1<ccitt16a>"; in "ccitt16a %=s %#9.1<ccitt16a>";
out "ccitt16x %s %#9.1<ccitt16x>"; in "ccitt16x %=s %#9.1<ccitt16x>";
out "crc16c %s %#9.1<crc16c>"; in "crc16c %=s %#9.1<crc16c>";
out "xmodem %s %#9.1<xmodem>"; in "xmodem %=s %#9.1<xmodem>";
out "crc32 %s %#9.1<crc32>"; in "crc32 %=s %#9.1<crc32>";
out "crc32r %s %#9.1<crc32r>"; in "crc32r %=s %#9.1<crc32r>";
out "jamcrc %s %#9.1<jamcrc>"; in "jamcrc %=s %#9.1<jamcrc>";
out "adler32 %s %#9.1<adler32>"; in "adler32 %=s %#9.1<adler32>";
out "hexsum8 %s %#9.1<hexsum8>"; in "hexsum8 %=s %#9.1<hexsum8>";
out "sum %s %#09.1<sum>"; in "sum %=s %#09.1<sum>";
out "sum8 %s %#09.1<sum8>"; in "sum8 %=s %#09.1<sum8>";
out "sum16 %s %#09.1<sum16>"; in "sum16 %=s %#09.1<sum16>";
out "sum32 %s %#09.1<sum32>"; in "sum32 %=s %#09.1<sum32>";
out "nsum %s %#09.1<nsum>"; in "nsum %=s %#09.1<nsum>";
out "negsum %s %#09.1<negsum>"; in "negsum %=s %#09.1<negsum>";
out "-sum %s %#09.1<-sum>"; in "-sum %=s %#09.1<-sum>";
out "nsum8 %s %#09.1<nsum8>"; in "nsum8 %=s %#09.1<nsum8>";
out "negsum8 %s %#09.1<negsum8>"; in "negsum8 %=s %#09.1<negsum8>";
out "-sum8 %s %#09.1<-sum8>"; in "-sum8 %=s %#09.1<-sum8>";
out "nsum16 %s %#09.1<nsum16>"; in "nsum16 %=s %#09.1<nsum16>";
out "negsum16 %s %#09.1<negsum1>"; in "negsum16 %=s %#09.1<negsum1>";
out "-sum16 %s %#09.1<-sum16>"; in "-sum16 %=s %#09.1<-sum16>";
out "nsum32 %s %#09.1<nsum32>"; in "nsum32 %=s %#09.1<nsum32>";
out "negsum32 %s %#09.1<negsum3>"; in "negsum32 %=s %#09.1<negsum3>";
out "-sum32 %s %#09.1<-sum32>"; in "-sum32 %=s %#09.1<-sum32>";
out "notsum %s %#09.1<notsum>"; in "notsum %=s %#09.1<notsum>";
out "~sum %s %#09.1<~sum>"; in "~sum %=s %#09.1<~sum>";
out "xor %s %#09.1<xor>"; in "xor %=s %#09.1<xor>";
out "xor8 %s %#09.1<xor8>"; in "xor8 %=s %#09.1<xor8>";
out "xor7 %s %#09.1<xor7>"; in "xor7 %=s %#09.1<xor7>";
out "crc8 %s %#09.1<crc8>"; in "crc8 %=s %#09.1<crc8>";
out "ccitt8 %s %#09.1<ccitt8>"; in "ccitt8 %=s %#09.1<ccitt8>";
out "crc16 %s %#09.1<crc16>"; in "crc16 %=s %#09.1<crc16>";
out "crc16r %s %#09.1<crc16r>"; in "crc16r %=s %#09.1<crc16r>";
out "ccitt16 %s %#09.1<ccitt16>"; in "ccitt16 %=s %#09.1<ccitt16>";
out "ccitt16a %s %#09.1<ccitt16a>"; in "ccitt16a %=s %#09.1<ccitt16a>";
out "ccitt16x %s %#09.1<ccitt16x>"; in "ccitt16x %=s %#09.1<ccitt16x>";
out "crc16c %s %#09.1<crc16c>"; in "crc16c %=s %#09.1<crc16c>";
out "xmodem %s %#09.1<xmodem>"; in "xmodem %=s %#09.1<xmodem>";
out "crc32 %s %#09.1<crc32>"; in "crc32 %=s %#09.1<crc32>";
out "crc32r %s %#09.1<crc32r>"; in "crc32r %=s %#09.1<crc32r>";
out "jamcrc %s %#09.1<jamcrc>"; in "jamcrc %=s %#09.1<jamcrc>";
out "adler32 %s %#09.1<adler32>"; in "adler32 %=s %#09.1<adler32>";
out "hexsum8 %s %#09.1<hexsum8>"; in "hexsum8 %=s %#09.1<hexsum8>";
out "sum %s %#-9.1<sum>"; in "sum %=s %#-9.1<sum>";
out "sum8 %s %#-9.1<sum8>"; in "sum8 %=s %#-9.1<sum8>";
out "sum16 %s %#-9.1<sum16>"; in "sum16 %=s %#-9.1<sum16>";
out "sum32 %s %#-9.1<sum32>"; in "sum32 %=s %#-9.1<sum32>";
out "nsum %s %#-9.1<nsum>"; in "nsum %=s %#-9.1<nsum>";
out "negsum %s %#-9.1<negsum>"; in "negsum %=s %#-9.1<negsum>";
out "-sum %s %#-9.1<-sum>"; in "-sum %=s %#-9.1<-sum>";
out "nsum8 %s %#-9.1<nsum8>"; in "nsum8 %=s %#-9.1<nsum8>";
out "negsum8 %s %#-9.1<negsum8>"; in "negsum8 %=s %#-9.1<negsum8>";
out "-sum8 %s %#-9.1<-sum8>"; in "-sum8 %=s %#-9.1<-sum8>";
out "nsum16 %s %#-9.1<nsum16>"; in "nsum16 %=s %#-9.1<nsum16>";
out "negsum16 %s %#-9.1<negsum1>"; in "negsum16 %=s %#-9.1<negsum1>";
out "-sum16 %s %#-9.1<-sum16>"; in "-sum16 %=s %#-9.1<-sum16>";
out "nsum32 %s %#-9.1<nsum32>"; in "nsum32 %=s %#-9.1<nsum32>";
out "negsum32 %s %#-9.1<negsum3>"; in "negsum32 %=s %#-9.1<negsum3>";
out "-sum32 %s %#-9.1<-sum32>"; in "-sum32 %=s %#-9.1<-sum32>";
out "notsum %s %#-9.1<notsum>"; in "notsum %=s %#-9.1<notsum>";
out "~sum %s %#-9.1<~sum>"; in "~sum %=s %#-9.1<~sum>";
out "xor %s %#-9.1<xor>"; in "xor %=s %#-9.1<xor>";
out "xor8 %s %#-9.1<xor8>"; in "xor8 %=s %#-9.1<xor8>";
out "xor7 %s %#-9.1<xor7>"; in "xor7 %=s %#-9.1<xor7>";
out "crc8 %s %#-9.1<crc8>"; in "crc8 %=s %#-9.1<crc8>";
out "ccitt8 %s %#-9.1<ccitt8>"; in "ccitt8 %=s %#-9.1<ccitt8>";
out "crc16 %s %#-9.1<crc16>"; in "crc16 %=s %#-9.1<crc16>";
out "crc16r %s %#-9.1<crc16r>"; in "crc16r %=s %#-9.1<crc16r>";
out "ccitt16 %s %#-9.1<ccitt16>"; in "ccitt16 %=s %#-9.1<ccitt16>";
out "ccitt16a %s %#-9.1<ccitt16a>"; in "ccitt16a %=s %#-9.1<ccitt16a>";
out "ccitt16x %s %#-9.1<ccitt16x>"; in "ccitt16x %=s %#-9.1<ccitt16x>";
out "crc16c %s %#-9.1<crc16c>"; in "crc16c %=s %#-9.1<crc16c>";
out "xmodem %s %#-9.1<xmodem>"; in "xmodem %=s %#-9.1<xmodem>";
out "crc32 %s %#-9.1<crc32>"; in "crc32 %=s %#-9.1<crc32>";
out "crc32r %s %#-9.1<crc32r>"; in "crc32r %=s %#-9.1<crc32r>";
out "jamcrc %s %#-9.1<jamcrc>"; in "jamcrc %=s %#-9.1<jamcrc>";
out "adler32 %s %#-9.1<adler32>"; in "adler32 %=s %#-9.1<adler32>";
out "hexsum8 %s %#-9.1<hexsum8>"; in "hexsum8 %=s %#-9.1<hexsum8>";
out "DONE";
}
} }
set startup { set startup {
@ -24,7 +242,432 @@ set startup {
set debug 0 set debug 0
startioc startioc
ioccmd {dbpf DZ:test1 "1"} ioccmd {dbpf DZ:test1 "123456789"}
assure "\x55\x40\x04\x00\x00z;\x4e" assure "sum 123456789 \xDD\n"
send "sum 123456789 \xDD\n"
assure "sum8 123456789 \xDD\n"
send "sum8 123456789 \xDD\n"
assure "sum16 123456789 \x01\xDD\n"
send "sum16 123456789 \x01\xDD\n"
assure "sum32 123456789 \x00\x00\x01\xDD\n"
send "sum32 123456789 \x00\x00\x01\xDD\n"
assure "nsum 123456789 \x23\n"
send "nsum 123456789 \x23\n"
assure "negsum 123456789 \x23\n"
send "negsum 123456789 \x23\n"
assure "-sum 123456789 \x23\n"
send "-sum 123456789 \x23\n"
assure "nsum8 123456789 \x23\n"
send "nsum8 123456789 \x23\n"
assure "negsum8 123456789 \x23\n"
send "negsum8 123456789 \x23\n"
assure "-sum8 123456789 \x23\n"
send "-sum8 123456789 \x23\n"
assure "nsum16 123456789 \xFE\x23\n"
send "nsum16 123456789 \xFE\x23\n"
assure "negsum16 123456789 \xFE\x23\n"
send "negsum16 123456789 \xFE\x23\n"
assure "-sum16 123456789 \xFE\x23\n"
send "-sum16 123456789 \xFE\x23\n"
assure "nsum32 123456789 \xFF\xFF\xFE\x23\n"
send "nsum32 123456789 \xFF\xFF\xFE\x23\n"
assure "negsum32 123456789 \xFF\xFF\xFE\x23\n"
send "negsum32 123456789 \xFF\xFF\xFE\x23\n"
assure "-sum32 123456789 \xFF\xFF\xFE\x23\n"
send "-sum32 123456789 \xFF\xFF\xFE\x23\n"
assure "notsum 123456789 \x22\n"
send "notsum 123456789 \x22\n"
assure "~sum 123456789 \x22\n"
send "~sum 123456789 \x22\n"
assure "xor 123456789 \x31\n"
send "xor 123456789 \x31\n"
assure "xor8 123456789 \x31\n"
send "xor8 123456789 \x31\n"
assure "xor7 123456789 \x31\n"
send "xor7 123456789 \x31\n"
assure "crc8 123456789 \xF4\n"
send "crc8 123456789 \xF4\n"
assure "ccitt8 123456789 \xA1\n"
send "ccitt8 123456789 \xA1\n"
assure "crc16 123456789 \xFE\xE8\n"
send "crc16 123456789 \xFE\xE8\n"
assure "crc16r 123456789 \xBB\x3D\n"
send "crc16r 123456789 \xBB\x3D\n"
assure "ccitt16 123456789 \x29\xB1\n"
send "ccitt16 123456789 \x29\xB1\n"
assure "ccitt16a 123456789 \xE5\xCC\n"
send "ccitt16a 123456789 \xE5\xCC\n"
assure "ccitt16x 123456789 \x31\xC3\n"
send "ccitt16x 123456789 \x31\xC3\n"
assure "crc16c 123456789 \x31\xC3\n"
send "crc16c 123456789 \x31\xC3\n"
assure "xmodem 123456789 \x31\xC3\n"
send "xmodem 123456789 \x31\xC3\n"
assure "crc32 123456789 \xFC\x89\x19\x18\n"
send "crc32 123456789 \xFC\x89\x19\x18\n"
assure "crc32r 123456789 \xCB\xF4\x39\x26\n"
send "crc32r 123456789 \xCB\xF4\x39\x26\n"
assure "jamcrc 123456789 \x34\x0B\xC6\xD9\n"
send "jamcrc 123456789 \x34\x0B\xC6\xD9\n"
assure "adler32 123456789 \x09\x1E\x01\xDE\n"
send "adler32 123456789 \x09\x1E\x01\xDE\n"
assure "hexsum8 123456789 \x2D\n"
send "hexsum8 123456789 \x2D\n"
assure "sum 123456789 DD\n"
send "sum 123456789 DD\n"
assure "sum8 123456789 DD\n"
send "sum8 123456789 DD\n"
assure "sum16 123456789 01DD\n"
send "sum16 123456789 01DD\n"
assure "sum32 123456789 000001DD\n"
send "sum32 123456789 000001DD\n"
assure "nsum 123456789 23\n"
send "nsum 123456789 23\n"
assure "negsum 123456789 23\n"
send "negsum 123456789 23\n"
assure "-sum 123456789 23\n"
send "-sum 123456789 23\n"
assure "nsum8 123456789 23\n"
send "nsum8 123456789 23\n"
assure "negsum8 123456789 23\n"
send "negsum8 123456789 23\n"
assure "-sum8 123456789 23\n"
send "-sum8 123456789 23\n"
assure "nsum16 123456789 FE23\n"
send "nsum16 123456789 FE23\n"
assure "negsum16 123456789 FE23\n"
send "negsum16 123456789 FE23\n"
assure "-sum16 123456789 FE23\n"
send "-sum16 123456789 FE23\n"
assure "nsum32 123456789 FFFFFE23\n"
send "nsum32 123456789 FFFFFE23\n"
assure "negsum32 123456789 FFFFFE23\n"
send "negsum32 123456789 FFFFFE23\n"
assure "-sum32 123456789 FFFFFE23\n"
send "-sum32 123456789 FFFFFE23\n"
assure "notsum 123456789 22\n"
send "notsum 123456789 22\n"
assure "~sum 123456789 22\n"
send "~sum 123456789 22\n"
assure "xor 123456789 31\n"
send "xor 123456789 31\n"
assure "xor8 123456789 31\n"
send "xor8 123456789 31\n"
assure "xor7 123456789 31\n"
send "xor7 123456789 31\n"
assure "crc8 123456789 F4\n"
send "crc8 123456789 F4\n"
assure "ccitt8 123456789 A1\n"
send "ccitt8 123456789 A1\n"
assure "crc16 123456789 FEE8\n"
send "crc16 123456789 FEE8\n"
assure "crc16r 123456789 BB3D\n"
send "crc16r 123456789 BB3D\n"
assure "ccitt16 123456789 29B1\n"
send "ccitt16 123456789 29B1\n"
assure "ccitt16a 123456789 E5CC\n"
send "ccitt16a 123456789 E5CC\n"
assure "ccitt16x 123456789 31C3\n"
send "ccitt16x 123456789 31C3\n"
assure "crc16c 123456789 31C3\n"
send "crc16c 123456789 31C3\n"
assure "xmodem 123456789 31C3\n"
send "xmodem 123456789 31C3\n"
assure "crc32 123456789 FC891918\n"
send "crc32 123456789 FC891918\n"
assure "crc32r 123456789 CBF43926\n"
send "crc32r 123456789 CBF43926\n"
assure "jamcrc 123456789 340BC6D9\n"
send "jamcrc 123456789 340BC6D9\n"
assure "adler32 123456789 091E01DE\n"
send "adler32 123456789 091E01DE\n"
assure "hexsum8 123456789 2D\n"
send "hexsum8 123456789 2D\n"
assure "sum 123456789 \x3D\x3D\n"
send "sum 123456789 \x3D\x3D\n"
assure "sum8 123456789 \x3D\x3D\n"
send "sum8 123456789 \x3D\x3D\n"
assure "sum16 123456789 \x30\x31\x3D\x3D\n"
send "sum16 123456789 \x30\x31\x3D\x3D\n"
assure "sum32 123456789 \x30\x30\x30\x30\x30\x31\x3D\x3D\n"
send "sum32 123456789 \x30\x30\x30\x30\x30\x31\x3D\x3D\n"
assure "nsum 123456789 \x32\x33\n"
send "nsum 123456789 \x32\x33\n"
assure "negsum 123456789 \x32\x33\n"
send "negsum 123456789 \x32\x33\n"
assure "-sum 123456789 \x32\x33\n"
send "-sum 123456789 \x32\x33\n"
assure "nsum8 123456789 \x32\x33\n"
send "nsum8 123456789 \x32\x33\n"
assure "negsum8 123456789 \x32\x33\n"
send "negsum8 123456789 \x32\x33\n"
assure "-sum8 123456789 \x32\x33\n"
send "-sum8 123456789 \x32\x33\n"
assure "nsum16 123456789 \x3F\x3E\x32\x33\n"
send "nsum16 123456789 \x3F\x3E\x32\x33\n"
assure "negsum16 123456789 \x3F\x3E\x32\x33\n"
send "negsum16 123456789 \x3F\x3E\x32\x33\n"
assure "-sum16 123456789 \x3F\x3E\x32\x33\n"
send "-sum16 123456789 \x3F\x3E\x32\x33\n"
assure "nsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
send "nsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
assure "negsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
send "negsum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
assure "-sum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
send "-sum32 123456789 \x3F\x3F\x3F\x3F\x3F\x3E\x32\x33\n"
assure "notsum 123456789 \x32\x32\n"
send "notsum 123456789 \x32\x32\n"
assure "~sum 123456789 \x32\x32\n"
send "~sum 123456789 \x32\x32\n"
assure "xor 123456789 \x33\x31\n"
send "xor 123456789 \x33\x31\n"
assure "xor8 123456789 \x33\x31\n"
send "xor8 123456789 \x33\x31\n"
assure "xor7 123456789 \x33\x31\n"
send "xor7 123456789 \x33\x31\n"
assure "crc8 123456789 \x3F\x34\n"
send "crc8 123456789 \x3F\x34\n"
assure "ccitt8 123456789 \x3A\x31\n"
send "ccitt8 123456789 \x3A\x31\n"
assure "crc16 123456789 \x3F\x3E\x3E\x38\n"
send "crc16 123456789 \x3F\x3E\x3E\x38\n"
assure "crc16r 123456789 \x3B\x3B\x33\x3D\n"
send "crc16r 123456789 \x3B\x3B\x33\x3D\n"
assure "ccitt16 123456789 \x32\x39\x3B\x31\n"
send "ccitt16 123456789 \x32\x39\x3B\x31\n"
assure "ccitt16a 123456789 \x3E\x35\x3C\x3C\n"
send "ccitt16a 123456789 \x3E\x35\x3C\x3C\n"
assure "ccitt16x 123456789 \x33\x31\x3C\x33\n"
send "ccitt16x 123456789 \x33\x31\x3C\x33\n"
assure "crc16c 123456789 \x33\x31\x3C\x33\n"
send "crc16c 123456789 \x33\x31\x3C\x33\n"
assure "xmodem 123456789 \x33\x31\x3C\x33\n"
send "xmodem 123456789 \x33\x31\x3C\x33\n"
assure "crc32 123456789 \x3F\x3C\x38\x39\x31\x39\x31\x38\n"
send "crc32 123456789 \x3F\x3C\x38\x39\x31\x39\x31\x38\n"
assure "crc32r 123456789 \x3C\x3B\x3F\x34\x33\x39\x32\x36\n"
send "crc32r 123456789 \x3C\x3B\x3F\x34\x33\x39\x32\x36\n"
assure "jamcrc 123456789 \x33\x34\x30\x3B\x3C\x36\x3D\x39\n"
send "jamcrc 123456789 \x33\x34\x30\x3B\x3C\x36\x3D\x39\n"
assure "adler32 123456789 \x30\x39\x31\x3E\x30\x31\x3D\x3E\n"
send "adler32 123456789 \x30\x39\x31\x3E\x30\x31\x3D\x3E\n"
assure "hexsum8 123456789 \x32\x3D\n"
send "hexsum8 123456789 \x32\x3D\n"
assure "sum 123456789 \xDD\n"
send "sum 123456789 \xDD\n"
assure "sum8 123456789 \xDD\n"
send "sum8 123456789 \xDD\n"
assure "sum16 123456789 \xDD\x01\n"
send "sum16 123456789 \xDD\x01\n"
assure "sum32 123456789 \xDD\x01\x00\x00\n"
send "sum32 123456789 \xDD\x01\x00\x00\n"
assure "nsum 123456789 \x23\n"
send "nsum 123456789 \x23\n"
assure "negsum 123456789 \x23\n"
send "negsum 123456789 \x23\n"
assure "-sum 123456789 \x23\n"
send "-sum 123456789 \x23\n"
assure "nsum8 123456789 \x23\n"
send "nsum8 123456789 \x23\n"
assure "negsum8 123456789 \x23\n"
send "negsum8 123456789 \x23\n"
assure "-sum8 123456789 \x23\n"
send "-sum8 123456789 \x23\n"
assure "nsum16 123456789 \x23\xFE\n"
send "nsum16 123456789 \x23\xFE\n"
assure "negsum16 123456789 \x23\xFE\n"
send "negsum16 123456789 \x23\xFE\n"
assure "-sum16 123456789 \x23\xFE\n"
send "-sum16 123456789 \x23\xFE\n"
assure "nsum32 123456789 \x23\xFE\xFF\xFF\n"
send "nsum32 123456789 \x23\xFE\xFF\xFF\n"
assure "negsum32 123456789 \x23\xFE\xFF\xFF\n"
send "negsum32 123456789 \x23\xFE\xFF\xFF\n"
assure "-sum32 123456789 \x23\xFE\xFF\xFF\n"
send "-sum32 123456789 \x23\xFE\xFF\xFF\n"
assure "notsum 123456789 \x22\n"
send "notsum 123456789 \x22\n"
assure "~sum 123456789 \x22\n"
send "~sum 123456789 \x22\n"
assure "xor 123456789 \x31\n"
send "xor 123456789 \x31\n"
assure "xor8 123456789 \x31\n"
send "xor8 123456789 \x31\n"
assure "xor7 123456789 \x31\n"
send "xor7 123456789 \x31\n"
assure "crc8 123456789 \xF4\n"
send "crc8 123456789 \xF4\n"
assure "ccitt8 123456789 \xA1\n"
send "ccitt8 123456789 \xA1\n"
assure "crc16 123456789 \xE8\xFE\n"
send "crc16 123456789 \xE8\xFE\n"
assure "crc16r 123456789 \x3D\xBB\n"
send "crc16r 123456789 \x3D\xBB\n"
assure "ccitt16 123456789 \xB1\x29\n"
send "ccitt16 123456789 \xB1\x29\n"
assure "ccitt16a 123456789 \xCC\xE5\n"
send "ccitt16a 123456789 \xCC\xE5\n"
assure "ccitt16x 123456789 \xC3\x31\n"
send "ccitt16x 123456789 \xC3\x31\n"
assure "crc16c 123456789 \xC3\x31\n"
send "crc16c 123456789 \xC3\x31\n"
assure "xmodem 123456789 \xC3\x31\n"
send "xmodem 123456789 \xC3\x31\n"
assure "crc32 123456789 \x18\x19\x89\xFC\n"
send "crc32 123456789 \x18\x19\x89\xFC\n"
assure "crc32r 123456789 \x26\x39\xF4\xCB\n"
send "crc32r 123456789 \x26\x39\xF4\xCB\n"
assure "jamcrc 123456789 \xD9\xC6\x0B\x34\n"
send "jamcrc 123456789 \xD9\xC6\x0B\x34\n"
assure "adler32 123456789 \xDE\x01\x1E\x09\n"
send "adler32 123456789 \xDE\x01\x1E\x09\n"
assure "hexsum8 123456789 \x2D\n"
send "hexsum8 123456789 \x2D\n"
assure "sum 123456789 DD\n"
send "sum 123456789 DD\n"
assure "sum8 123456789 DD\n"
send "sum8 123456789 DD\n"
assure "sum16 123456789 DD01\n"
send "sum16 123456789 DD01\n"
assure "sum32 123456789 DD010000\n"
send "sum32 123456789 DD010000\n"
assure "nsum 123456789 23\n"
send "nsum 123456789 23\n"
assure "negsum 123456789 23\n"
send "negsum 123456789 23\n"
assure "-sum 123456789 23\n"
send "-sum 123456789 23\n"
assure "nsum8 123456789 23\n"
send "nsum8 123456789 23\n"
assure "negsum8 123456789 23\n"
send "negsum8 123456789 23\n"
assure "-sum8 123456789 23\n"
send "-sum8 123456789 23\n"
assure "nsum16 123456789 23FE\n"
send "nsum16 123456789 23FE\n"
assure "negsum16 123456789 23FE\n"
send "negsum16 123456789 23FE\n"
assure "-sum16 123456789 23FE\n"
send "-sum16 123456789 23FE\n"
assure "nsum32 123456789 23FEFFFF\n"
send "nsum32 123456789 23FEFFFF\n"
assure "negsum32 123456789 23FEFFFF\n"
send "negsum32 123456789 23FEFFFF\n"
assure "-sum32 123456789 23FEFFFF\n"
send "-sum32 123456789 23FEFFFF\n"
assure "notsum 123456789 22\n"
send "notsum 123456789 22\n"
assure "~sum 123456789 22\n"
send "~sum 123456789 22\n"
assure "xor 123456789 31\n"
send "xor 123456789 31\n"
assure "xor8 123456789 31\n"
send "xor8 123456789 31\n"
assure "xor7 123456789 31\n"
send "xor7 123456789 31\n"
assure "crc8 123456789 F4\n"
send "crc8 123456789 F4\n"
assure "ccitt8 123456789 A1\n"
send "ccitt8 123456789 A1\n"
assure "crc16 123456789 E8FE\n"
send "crc16 123456789 E8FE\n"
assure "crc16r 123456789 3DBB\n"
send "crc16r 123456789 3DBB\n"
assure "ccitt16 123456789 B129\n"
send "ccitt16 123456789 B129\n"
assure "ccitt16a 123456789 CCE5\n"
send "ccitt16a 123456789 CCE5\n"
assure "ccitt16x 123456789 C331\n"
send "ccitt16x 123456789 C331\n"
assure "crc16c 123456789 C331\n"
send "crc16c 123456789 C331\n"
assure "xmodem 123456789 C331\n"
send "xmodem 123456789 C331\n"
assure "crc32 123456789 181989FC\n"
send "crc32 123456789 181989FC\n"
assure "crc32r 123456789 2639F4CB\n"
send "crc32r 123456789 2639F4CB\n"
assure "jamcrc 123456789 D9C60B34\n"
send "jamcrc 123456789 D9C60B34\n"
assure "adler32 123456789 DE011E09\n"
send "adler32 123456789 DE011E09\n"
assure "hexsum8 123456789 2D\n"
send "hexsum8 123456789 2D\n"
assure "sum 123456789 \x3D\x3D\n"
send "sum 123456789 \x3D\x3D\n"
assure "sum8 123456789 \x3D\x3D\n"
send "sum8 123456789 \x3D\x3D\n"
assure "sum16 123456789 \x3D\x3D\x30\x31\n"
send "sum16 123456789 \x3D\x3D\x30\x31\n"
assure "sum32 123456789 \x3D\x3D\x30\x31\x30\x30\x30\x30\n"
send "sum32 123456789 \x3D\x3D\x30\x31\x30\x30\x30\x30\n"
assure "nsum 123456789 \x32\x33\n"
send "nsum 123456789 \x32\x33\n"
assure "negsum 123456789 \x32\x33\n"
send "negsum 123456789 \x32\x33\n"
assure "-sum 123456789 \x32\x33\n"
send "-sum 123456789 \x32\x33\n"
assure "nsum8 123456789 \x32\x33\n"
send "nsum8 123456789 \x32\x33\n"
assure "negsum8 123456789 \x32\x33\n"
send "negsum8 123456789 \x32\x33\n"
assure "-sum8 123456789 \x32\x33\n"
send "-sum8 123456789 \x32\x33\n"
assure "nsum16 123456789 \x32\x33\x3F\x3E\n"
send "nsum16 123456789 \x32\x33\x3F\x3E\n"
assure "negsum16 123456789 \x32\x33\x3F\x3E\n"
send "negsum16 123456789 \x32\x33\x3F\x3E\n"
assure "-sum16 123456789 \x32\x33\x3F\x3E\n"
send "-sum16 123456789 \x32\x33\x3F\x3E\n"
assure "nsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
send "nsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
assure "negsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
send "negsum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
assure "-sum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
send "-sum32 123456789 \x32\x33\x3F\x3E\x3F\x3F\x3F\x3F\n"
assure "notsum 123456789 \x32\x32\n"
send "notsum 123456789 \x32\x32\n"
assure "~sum 123456789 \x32\x32\n"
send "~sum 123456789 \x32\x32\n"
assure "xor 123456789 \x33\x31\n"
send "xor 123456789 \x33\x31\n"
assure "xor8 123456789 \x33\x31\n"
send "xor8 123456789 \x33\x31\n"
assure "xor7 123456789 \x33\x31\n"
send "xor7 123456789 \x33\x31\n"
assure "crc8 123456789 \x3F\x34\n"
send "crc8 123456789 \x3F\x34\n"
assure "ccitt8 123456789 \x3A\x31\n"
send "ccitt8 123456789 \x3A\x31\n"
assure "crc16 123456789 \x3E\x38\x3F\x3E\n"
send "crc16 123456789 \x3E\x38\x3F\x3E\n"
assure "crc16r 123456789 \x33\x3D\x3B\x3B\n"
send "crc16r 123456789 \x33\x3D\x3B\x3B\n"
assure "ccitt16 123456789 \x3B\x31\x32\x39\n"
send "ccitt16 123456789 \x3B\x31\x32\x39\n"
assure "ccitt16a 123456789 \x3C\x3C\x3E\x35\n"
send "ccitt16a 123456789 \x3C\x3C\x3E\x35\n"
assure "ccitt16x 123456789 \x3C\x33\x33\x31\n"
send "ccitt16x 123456789 \x3C\x33\x33\x31\n"
assure "crc16c 123456789 \x3C\x33\x33\x31\n"
send "crc16c 123456789 \x3C\x33\x33\x31\n"
assure "xmodem 123456789 \x3C\x33\x33\x31\n"
send "xmodem 123456789 \x3C\x33\x33\x31\n"
assure "crc32 123456789 \x31\x38\x31\x39\x38\x39\x3F\x3C\n"
send "crc32 123456789 \x31\x38\x31\x39\x38\x39\x3F\x3C\n"
assure "crc32r 123456789 \x32\x36\x33\x39\x3F\x34\x3C\x3B\n"
send "crc32r 123456789 \x32\x36\x33\x39\x3F\x34\x3C\x3B\n"
assure "jamcrc 123456789 \x3D\x39\x3C\x36\x30\x3B\x33\x34\n"
send "jamcrc 123456789 \x3D\x39\x3C\x36\x30\x3B\x33\x34\n"
assure "adler32 123456789 \x3D\x3E\x30\x31\x31\x3E\x30\x39\n"
send "adler32 123456789 \x3D\x3E\x30\x31\x31\x3E\x30\x39\n"
assure "hexsum8 123456789 \x32\x3D\n"
send "hexsum8 123456789 \x32\x3D\n"
assure "DONE\n"
finish finish

View File

@ -30,11 +30,6 @@ set records {
field (DTYP, "stream") field (DTYP, "stream")
field (OUT, "@test.proto bcd device") field (OUT, "@test.proto bcd device")
} }
record (stringout, "DZ:chksum")
{
field (DTYP, "stream")
field (OUT, "@test.proto chksum device")
}
} }
set protocol { set protocol {
@ -43,13 +38,6 @@ set protocol {
ao {out "%.2f %.2e %.2E %.2g %.2G %i %d %u %o %04x %#.2f %#.2e %#.2E %#.2g %#.2G %#i %#d %#u %#o %#06x";} ao {out "%.2f %.2e %.2E %.2g %.2G %i %d %u %o %04x %#.2f %#.2e %#.2E %#.2g %#.2G %#i %#d %#u %#o %#06x";}
lo {out "%d %(VAL)d %06d %x %06X %b %06b %.6b %B.! %06B.!";} lo {out "%d %(VAL)d %06d %x %06X %b %06b %.6b %B.! %06B.!";}
bcd {out "%D %6D %.2D %.4D %.6D %.8D %#D %#6D %#.2D %#.4D %#.6D";} bcd {out "%D %6D %.2D %.4D %.6D %.8D %#D %#6D %#.2D %#.4D %#.6D";}
chksum {out "%s%<xor>";
out "%s%0<sum>";
out "%s%0<crc8>";
out "%s%0<crc16>";
out "%s%0<crc32>";
out "%s%0<adler32>";
}
} }
set startup { set startup {
@ -100,11 +88,4 @@ assure "\0\0\0\0\1\2\3\4 \0\0\0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1\0\0\0
} else { } else {
assure "\1\2\3\4 \0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1 \4\3\2\1\0\0 \4 \4\3 \4\3\2\n" assure "\1\2\3\4 \0\0\1\2\3\4 \4 \3\4 \2\3\4 \1\2\3\4 \4\3\2\1 \4\3\2\1\0\0 \4 \4\3 \4\3\2\n"
} }
ioccmd {dbpf DZ:chksum "123456789"}
assure "1234567891\n"
assure "123456789DD\n"
assure "123456789F4\n"
assure "123456789FEE8\n"
assure "123456789FC891918\n"
assure "123456789091E01DE\n"
finish finish

33
streamApp/tests/testStrangesum Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env tclsh
source streamtestlib.tcl
# Define records, protocol and startup (text goes to files)
# The asynPort "device" is connected to a network TCP socket
# Talk to the socket with send/receive/assure
# Send commands to the ioc shell with ioccmd
set records {
record (stringout, "DZ:test1")
{
field (DTYP, "stream")
field (OUT, "@test.proto test1 device")
}
}
set protocol {
Terminator="\r\n";
test1 {
out ":%s%01<-hexsum8>";
}
}
set startup {
}
set debug 0
startioc
ioccmd {dbpf DZ:test1 "010304010001"}
assure ":010304010001F6\r\n"
finish