diff --git a/src/asynStreamGeneratorDriver.cpp b/src/asynStreamGeneratorDriver.cpp index 4d816b0..3e1ae89 100644 --- a/src/asynStreamGeneratorDriver.cpp +++ b/src/asynStreamGeneratorDriver.cpp @@ -444,13 +444,13 @@ asynStatus asynStreamGeneratorDriver::writeInt32(asynUser *pasynUser, } else if (function == P_EnableElectronics) { if (value) { setIntegerParam(function, 1); - CommandHeader ch(start); + CommandHeader ch(CommandId::start); std::size_t written; pasynOctetSyncIO->write(pasynUDPUser, (char *)&ch, sizeof(ch), 1, &written); } else { setIntegerParam(function, 0); - CommandHeader ch(stop); + CommandHeader ch(CommandId::stop); std::size_t written; pasynOctetSyncIO->write(pasynUDPUser, (char *)&ch, sizeof(ch), 1, &written); @@ -566,6 +566,8 @@ void asynStreamGeneratorDriver::normaliseUDP() { lastBufferNumber[header->McpdID] = header->BufferNumber; + // TODO I think monitor and detector events aren't mixed, so we + // could do the check once for (std::size_t i = 0; i < total_events; ++i) { char *event = (buffer + 21 * 2 + i * 6); const bool isMonitorEvent = event[5] & 0x80; diff --git a/src/asynStreamGeneratorDriver.h b/src/asynStreamGeneratorDriver.h index f5c1db1..bd7be9d 100644 --- a/src/asynStreamGeneratorDriver.h +++ b/src/asynStreamGeneratorDriver.h @@ -12,7 +12,12 @@ /******************************************************************************* * UDP Packet Definitions */ -enum CommandId : std::int16_t { reset = 0, start = 1, stop = 2, cont = 3 }; +enum class CommandId : std::uint16_t { + reset = 0, + start = 1, + stop = 2, + cont = 3 +}; struct __attribute__((__packed__)) CommandHeader { uint16_t BufferLength; @@ -29,8 +34,11 @@ struct __attribute__((__packed__)) CommandHeader { CommandHeader(const CommandId commandId) : BufferLength(10), BufferType(0x8000), HeaderLength(10), - BufferNumber(0), Command(commandId), McpdIdStatus(0), TimeStampLo(0), - TimeStampMid(0), TimeStampHigh(0), Checksum(0), Finalizer(0xffff) { + BufferNumber(0), + Command( + static_cast::type>(commandId)), + McpdIdStatus(0), TimeStampLo(0), TimeStampMid(0), TimeStampHigh(0), + Checksum(0), Finalizer(0xffff) { Checksum = BufferLength ^ BufferType ^ HeaderLength ^ BufferNumber ^ Command ^ McpdIdStatus ^ TimeStampLo ^ TimeStampMid ^ @@ -66,11 +74,12 @@ struct __attribute__((__packed__)) DetectorEvent { uint16_t Amplitude : 8; uint16_t Id : 1; inline uint32_t nanosecs() const { return TimeStamp * 100; } - inline uint64_t pixelId(uint32_t mpcdId) const { + inline uint32_t pixelId(uint32_t mpcdId) const { const uint32_t x_pixels = 128; const uint32_t y_pixels = 128; return (mpcdId - 1) * x_pixels * y_pixels + - x_pixels * (uint32_t)this->XPosition + (uint32_t)this->YPosition; + x_pixels * (uint32_t)(this->XPosition >> 3) + + (uint32_t)(this->YPosition >> 3); } };