eDosStation/EpdBase3/Epd3Base.cpp

1813 lines
52 KiB
C++
Raw Normal View History

2022-04-26 08:43:13 +02:00
#include "pch.h"
2024-08-30 13:57:04 +02:00
#include "pch.h"
2022-04-26 08:43:13 +02:00
#pragma unmanaged
#include "Epd3Base.h"
#include "TimeFunctions.h"
#pragma unmanaged
2024-08-30 13:57:04 +02:00
#define noDeissueWithClear
2024-09-05 16:10:29 +02:00
#define ProtectSession
2022-04-26 08:43:13 +02:00
2024-09-11 15:44:51 +02:00
#if _DEBUG
#define DebugWrite(f,...) snprintf(current->DiagnosticsWrite, DiagnosticsWriteSize, f ,__VA_ARGS__); OutputDebugStringA(current->DiagnosticsWrite);
#else
#define DebugWrite(f,...) ;
#endif
constexpr int SleepAfterClear = 1000;
2022-08-18 16:20:04 +02:00
//-102 = permission
2022-04-26 08:43:13 +02:00
Epd3Base::Epd3U* current;
2024-09-04 13:05:16 +02:00
void Epd3Base::Epd3U::ResetStepReturnValues()
{
CurrentStep = -1;
2024-09-05 16:10:29 +02:00
HasStepError = 0;
for (int i = MaxSteps - 1; i >= 0; --i) for (int j = 0; j < 4; j++) StepReturnValues[i][j] = 0;
2024-09-04 13:05:16 +02:00
}
2024-09-06 16:00:41 +02:00
int Epd3Base::Epd3U::SetFunctionReturnValue(enum eFunctions f, BYTE CanIgnore)
2024-09-04 13:05:16 +02:00
{
if (CurrentStep < -1) CurrentStep = -1;
if (CurrentStep < MaxSteps - 1) {
++CurrentStep;
2024-09-05 16:10:29 +02:00
if (CurrentStep == 0) HasStepError = 0;
2024-09-04 13:05:16 +02:00
StepReturnValues[CurrentStep][0] = f;
StepReturnValues[CurrentStep][1] = -1;
StepReturnValues[CurrentStep][2] = -1;
2024-09-05 16:10:29 +02:00
StepReturnValues[CurrentStep][3] = CanIgnore;
2024-09-04 13:05:16 +02:00
}
2024-09-06 16:00:41 +02:00
return CurrentStep;
2024-09-04 13:05:16 +02:00
}
2024-09-06 16:00:41 +02:00
void Epd3Base::Epd3U::SetCommitReturnValue(int step, int32_t rv)
2024-09-04 13:05:16 +02:00
{
2024-09-06 16:00:41 +02:00
if (CurrentStep >= 0 && CurrentStep < MaxSteps)
StepReturnValues[step][1] = rv;
2024-09-04 13:05:16 +02:00
}
2024-09-06 16:00:41 +02:00
void Epd3Base::Epd3U::SetCommitReturnValue(int32_t rv)
2024-09-04 13:05:16 +02:00
{
2024-09-06 16:00:41 +02:00
SetCommitReturnValue(CurrentStep, rv);
}
uint32_t Epd3Base::Epd3U::SetEndReturnValue(int step, int32_t rv)
{
if (step >= 0 && step < MaxSteps) {
2024-09-06 16:00:41 +02:00
StepReturnValues[step][2] = rv;
if (rv != 0) {
HasStepError = 1;
if (StepReturnValues[step][3]) rv = 0; //if canIngore set rv ok
Error = GetErrorCode();
}
2024-09-06 16:00:41 +02:00
}
2024-09-05 16:10:29 +02:00
return rv;
2024-09-04 13:05:16 +02:00
}
2024-09-06 16:00:41 +02:00
uint32_t Epd3Base::Epd3U::SetEndReturnValue(int32_t rv)
{
return SetEndReturnValue(CurrentStep, rv);
}
2024-09-05 16:10:29 +02:00
2024-09-04 13:05:16 +02:00
int32_t Epd3Base::Epd3U::CommitAndSetRV()
{
int32_t r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
return r;
}
2024-09-06 16:00:41 +02:00
int32_t Epd3Base::Epd3U::CommitAndSetRV(int idx[], int len)
{
int32_t r = Commit3(epdComsHandle);
for(int i = 0; i < len ;++i)
SetCommitReturnValue(idx[i],r);
return r;
}
2024-09-04 13:05:16 +02:00
int32_t Epd3Base::Epd3U::CommitAndEnd2RV(int32_t (WINAPI *endFunction2)(CommsHandle hComms, CompletionToken token), CompletionToken token)
{
int32_t r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
if (!r) r = (*endFunction2)(epdComsHandle, token);
2024-09-05 16:10:29 +02:00
r= SetEndReturnValue(r);
2024-09-04 13:05:16 +02:00
return r;
}
2024-09-06 16:00:41 +02:00
int32_t Epd3Base::Epd3U::End2RV(int step, int32_t(WINAPI* endFunction2)(CommsHandle hComms, CompletionToken token), CompletionToken token)
{
int32_t r = (*endFunction2)(epdComsHandle, token);
r = SetEndReturnValue(step,r);
return r;
}
2022-04-26 08:43:13 +02:00
void WINAPI completion(CommsHandle hComms, CompletionToken token)
{
SetEvent(current->hCompletion);
}
void WINAPI discovery(CommsHandle hComms, DiscoveryId const discovered[], int32_t count)
{
if (count > 0)
{
2024-05-29 16:08:18 +02:00
memcpy(&current->Epd, &discovered[0], sizeof(DiscoveryId));
2022-04-26 08:43:13 +02:00
current->CurrentDeviceID = discovered[0].Id;
current->DeviceCount = count;
SetEvent(current->hCompletion);
current->isMK3 = (current->Epd.Gen == EpdGeneration::Mk3);
current->EpdID = current->Epd.Id;
}
}
2024-05-29 16:08:18 +02:00
void WINAPI connectcallback(CommsHandle hComms, DiscoveryId ID)
{
current->isConnected = 1;
current->CurrentDeviceID = ID.Id;
current->DeviceCount = 1;
}
2022-04-26 08:43:13 +02:00
void WINAPI disconnectcallback(CommsHandle hComms, DiscoveryId ID)
{
2024-09-11 15:44:51 +02:00
OutputDebugStringA("**** Disconnect ****\n");
2024-05-29 16:08:18 +02:00
current->isConnected = 0;
2022-04-26 08:43:13 +02:00
current->CurrentDeviceID = 0;
current->DeviceCount = 0;
SetEvent(current->hCompletion);
}
Epd3Base::Epd3U::Epd3U(int _comport)
{
port = _comport;
comPort[3] = 48 + _comport;
CommsInitialized = 0;
2024-05-29 16:08:18 +02:00
epdComsHandle = nullptr;
2022-04-26 08:43:13 +02:00
isBG = isNG = VersionOK = 0;
Error = 123;
current = this;
DeviceCount = 0;
BaseCountsClock = 0;
CurrentDeviceID = 0;
countsRead = 0; utc = 0; seconds = 0;
memset(WearerID, 0, WearerIDLength + 1);
memset(WearerName, 0, WearerNameLength + 1);
Error = 0;
EpdID = 4567;
EpdType = EpdTypes::Mk2BetaGamma;
isBG = 1; isNG = 0; VersionOK = 1;
isMK3 = true;
FunctionFlags = 0x000;
Epd.Gen = EpdGeneration::None;
Epd.MaxBaud = 0;
Epd.Id = EpdID;
OperatingStatus = (OpStatusFlags)0U;
AlarmStatus = (AlarmStatusFlags)0U;
ErrorStatus = (FaultStatusFlags)0;
IssueCount = OtherAlarms = EEPROMBadSectors = 0;
RealTime = EpdClock = OffTime = EpdID = 0;
2024-05-29 16:08:18 +02:00
EPDFaulty = false;
hasAlarm = hasFault = 0;
2022-04-26 08:43:13 +02:00
ErrorSource = ErrorReason = ErrorData = 0;
2024-05-29 16:08:18 +02:00
HardVersion = HardVersionMinor = SoftVersion = FunctionFlags = 0;
2022-04-26 08:43:13 +02:00
K1 = K2 = K3 = K4 = K4 = K6 = 0.0F;
HG = SG = BC = FB = 0;
D1 = D2 = D3 = D4 = 0;
Hp10Total = Hp07Total = 0;
Hp10Dose = Hp07Dose = 0;
Hp10Peak = Hp07Peak = 0;
Hp10Time = Hp07Time = 0;
Hp10FTime = Hp07FTime = 0;
Hp07THDose = 0; Hp07RateOn = 0; Hp07RateOff = 0;
Hp07THDoseA = 0; Hp07RateAOn = 0; Hp07RateAOff = 0;
Hp10THDose1 = 0; Hp10Rate1On = 0; Hp10Rate1Off = 0;
Hp10THDose2 = 0; Hp10Rate2On = 0; Hp10Rate2Off = 0;
if (_comport == 0) return;
if (hCompletion == 0) hCompletion = CreateEvent(NULL, TRUE, FALSE, NULL);
2024-09-04 13:05:16 +02:00
2024-09-06 16:00:41 +02:00
2022-04-26 08:43:13 +02:00
}
Epd3Base::Epd3U::~Epd3U()
{
2024-09-05 16:10:29 +02:00
EndCom(isConnected);
2024-05-29 16:08:18 +02:00
if (hCompletion != 0) { CloseHandle(hCompletion); hCompletion = 0; }
2022-04-26 08:43:13 +02:00
//if (hWaitTimer != 0) { CloseHandle(hWaitTimer); hWaitTimer = 0; }
}
int Epd3Base::Epd3U::DisconnectAndConnect()
{
int rv = 0;
rv = Disconnect(epdComsHandle);
Sleep(200);
rv = SetConnectCallback(epdComsHandle, connectcallback);
int tries = 3; rv = 1;
while (rv && --tries>=0) {
rv = Connect3(epdComsHandle, Epd, true);
2024-09-11 15:44:51 +02:00
DebugWrite( "**** DisconnectAndConnect rv=%d tries %d ****\n", rv, tries);
Sleep(100);
}
return rv;
}
2022-04-26 08:43:13 +02:00
DWORD Epd3Base::Epd3U::StartCom()
{
ErrorReason = 0;
2024-05-29 16:08:18 +02:00
ConnectRetries = 0;
OpenRetries = 0;
2024-05-29 16:08:18 +02:00
int step = 1;
2022-04-26 08:43:13 +02:00
int mx = 10;
2024-05-29 16:08:18 +02:00
epdComsHandle = nullptr;
2022-04-26 08:43:13 +02:00
if (port == 0) {
CommsInitialized = 1;
return 1;
}
2024-05-29 16:08:18 +02:00
if (CommsInitialized == 0 || epdComsHandle == nullptr) {
step = 2;
SetFunctionReturnValue(fCreateReaderInterface, 0);
2022-04-26 08:43:13 +02:00
epdComsHandle = CreateReaderInterface();
if (!epdComsHandle ) step = 3;
while (epdComsHandle == nullptr && ++ConnectRetries < 4) {
Sleep(200);
2024-05-29 16:08:18 +02:00
epdComsHandle = CreateReaderInterface(); //try again;
}
SetCommitReturnValue(0);
if (epdComsHandle) SetEndReturnValue(0); else SetEndReturnValue(-1);
2024-05-29 16:08:18 +02:00
if (epdComsHandle != nullptr) {
step = 4;
SetFunctionReturnValue(fOpenReader, 0);
2024-05-29 16:08:18 +02:00
Dll3RV = OpenReader(epdComsHandle, comPort); //-6 = r_OperationFailed
if (Dll3RV) step = 5;
while (Dll3RV && ++OpenRetries <4 ) { //retry
Sleep(200);
2024-05-29 16:08:18 +02:00
Dll3RV = OpenReader(epdComsHandle, comPort);
}
SetCommitReturnValue(0);
if (!Dll3RV) SetEndReturnValue(0); else SetEndReturnValue(-1);
2024-05-29 16:08:18 +02:00
if (Dll3RV == 0)
{
step = 7;
CommsInitialized = 1;
Dll3RV = SetMultipleDiscoveryMode(epdComsHandle, false);
2024-09-09 11:24:35 +02:00
Dll3RV = SetResponseTimeout(epdComsHandle, ResponseTimeout);
2024-05-29 16:08:18 +02:00
}
}
else {
Dll3RV = r_FunctionFail;
2022-04-26 08:43:13 +02:00
}
}
2024-05-29 16:08:18 +02:00
if (Dll3RV) goto error;
return Dll3RV;
error:
ErrorStep = step;
Error = Dll3RV;
2022-04-26 08:43:13 +02:00
return Dll3RV;
}
2024-09-05 16:10:29 +02:00
void Epd3Base::Epd3U::EndCom(bool doDiscon)
2022-04-26 08:43:13 +02:00
{
int rv;
2024-05-28 08:09:23 +02:00
if (CommsInitialized == 1 || CurrentDeviceID != 0) {
if (CommsInitialized == 1) {
2024-09-11 15:44:51 +02:00
DebugWrite( "**** EndCom(%d) is Connected=%d ****\n", doDiscon, isConnected);
2024-05-29 16:08:18 +02:00
if (epdComsHandle != nullptr) {
if (doDiscon && isConnected) { DisCon(0); }
2024-08-30 13:57:04 +02:00
//Dll3RV = CloseReader(epdComsHandle); // not necessary if followed by DestroyReaderInterface
//if (Dll3RV) {
// rv = 1;
//}
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::fDestroyReaderInterface,0);
2024-05-28 08:09:23 +02:00
Dll3RV = DestroyReaderInterface(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(0);
SetEndReturnValue(Dll3RV);
2024-08-30 13:57:04 +02:00
if (Dll3RV) rv = 1;
2022-04-26 08:43:13 +02:00
}
}
2024-05-28 08:09:23 +02:00
Epd.Id = 0;
CurrentDeviceID = 0;
CommsInitialized = 0;
2024-05-29 16:08:18 +02:00
epdComsHandle = nullptr;
2022-04-26 08:43:13 +02:00
}
}
/// <summary>
///
/// </summary>
/// <param name="tokentimeout"></param>
/// <returns>rv=1 ,ook bij timeout <>1 voor error</returns>
int Epd3Base::Epd3U::StartDiscover(int tokentimeout)
{
2024-05-29 16:08:18 +02:00
int32_t rv = 1;
2022-05-04 07:53:20 +02:00
int32_t rv2 = 0;
2022-04-26 08:43:13 +02:00
Error = 0;
if (port == 0) {
DeviceCount = 1;
2024-05-29 16:08:18 +02:00
isBG = 1;
2022-04-26 08:43:13 +02:00
DeviceIDs[0] = 768;
return 0;
}
2024-05-29 16:08:18 +02:00
current = this;
2022-04-26 08:43:13 +02:00
Dll3RV = SetDiscoveryCacheTimeout(epdComsHandle, tokentimeout);
2024-05-29 16:08:18 +02:00
DeviceCount = 0;
2022-04-26 08:43:13 +02:00
ResetEvent(hCompletion);
ConnectTimerFired = 0;
2024-05-29 16:08:18 +02:00
isConnected = 0;
2024-09-04 13:05:16 +02:00
2022-04-26 08:43:13 +02:00
Dll3RV = StartDiscovery(epdComsHandle, discovery);
if (Dll3RV == 0) {
2024-05-29 16:08:18 +02:00
Dll3RV = WaitForSingleObject(hCompletion, tokentimeout);
if (Dll3RV == WAIT_OBJECT_0) rv = 1;
else if (Dll3RV == WAIT_TIMEOUT) {
rv = 1;
ConnectTimerFired = 1;
rv2 = StopDiscovery(epdComsHandle);
DeviceCount = 0;
}
else rv = 2;
2022-04-26 08:43:13 +02:00
}
2024-05-29 16:08:18 +02:00
if (DeviceCount > 0) {
Dll3RV = SetConnectCallback(epdComsHandle, connectcallback);
2022-04-26 08:43:13 +02:00
Dll3RV = Connect3(epdComsHandle, Epd, true);
2024-05-29 16:08:18 +02:00
if (Dll3RV != 0) rv = 2;
else {
Dll3RV = SetDisconnectCallback(epdComsHandle, disconnectcallback);
}
2022-04-26 08:43:13 +02:00
}
return rv;
}
int Epd3Base::Epd3U::OpenDev(DiscoveryId DeviceID)
{
CurrentDeviceID = DeviceID.Id;
2024-05-29 16:08:18 +02:00
if (epdComsHandle != nullptr)
2022-04-26 08:43:13 +02:00
{
Dll3RV = Connect3(epdComsHandle, DeviceID, true);
2024-09-09 11:24:35 +02:00
SetDisconnectCallback(epdComsHandle, disconnectcallback);
OutputDebugStringA("**** Open ****\n");
2022-04-26 08:43:13 +02:00
}
2024-05-22 13:31:10 +02:00
else { Dll3RV = r_InvalidCommsHandle; }
2022-04-26 08:43:13 +02:00
return Dll3RV;
}
2024-05-16 15:56:07 +02:00
int Epd3Base::Epd3U::ReOpenDev()
{
2024-05-29 16:08:18 +02:00
if (epdComsHandle != nullptr)
2024-05-16 15:56:07 +02:00
{
SetDisconnectCallback(epdComsHandle, disconnectcallback);
2024-05-16 15:56:07 +02:00
Dll3RV = Connect3(epdComsHandle, Epd, true);
OutputDebugStringA("**** ReOpen ****\n");
2024-05-16 15:56:07 +02:00
}
2024-05-29 16:08:18 +02:00
else {
OutputDebugStringA("**** ReOpen no epdComsHandle ****\n");
2024-05-29 16:08:18 +02:00
Dll3RV = r_InvalidCommsHandle;
} //no handle ..
2024-05-16 15:56:07 +02:00
return Dll3RV;
}
//
2022-04-26 08:43:13 +02:00
int Epd3Base::Epd3U::DisCon(UINT16 alarm)
{
// 5432109876543210
constexpr UINT16 ca = 0b1001110011000111;
2022-04-26 08:43:13 +02:00
int rv = 0;
2024-05-28 08:09:23 +02:00
int step = 0;
2024-09-11 15:44:51 +02:00
DebugWrite( "**** Discon(%hu) ****\n", alarm);
2022-04-26 08:43:13 +02:00
if (CurrentDeviceID != 0) {
ResetEvent(hCompletion);
current = this;
2024-05-28 08:09:23 +02:00
step = 1;
2022-04-26 08:43:13 +02:00
Dll3RV = SetDisconnectCallback(epdComsHandle, disconnectcallback);
2024-09-04 13:05:16 +02:00
if (alarm) {
2024-09-11 15:44:51 +02:00
DebugWrite("**** DisconnectAndNotify(%hX,15) HardVersionMinor: %d ****\n", ca, HardVersionMinor);
if (HardVersionMinor > 0) {
SetFunctionReturnValue(TestVibe, 0);
token = BeginTestVibe_R3(epdComsHandle, 1.0 , nullptr);
rv = CommitAndEnd2RV(EndTestVibe_R3, token);
}
2024-09-11 15:44:51 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(fDisconnectAndNotify,0);
Dll3RV = DisconnectAndNotify(epdComsHandle, ca, 12); //1.2 secon
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(0); SetEndReturnValue(Dll3RV);
Sleep(1200);
2024-09-04 13:05:16 +02:00
} else {
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(fDisconnect,0);
2022-04-26 08:43:13 +02:00
Dll3RV = Disconnect(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(0); SetEndReturnValue(Dll3RV);
}
2024-05-28 08:09:23 +02:00
if (Dll3RV) { rv = Dll3RV; goto error; }
2024-05-29 16:08:18 +02:00
2024-05-28 08:09:23 +02:00
step = 2;
2022-08-18 16:20:04 +02:00
Dll3RV = WaitForSingleObject(hCompletion, 3000);
2022-04-26 08:43:13 +02:00
switch (Dll3RV) {
2024-09-05 16:10:29 +02:00
case WAIT_OBJECT_0:
rv = 0; break;
2024-05-29 16:08:18 +02:00
case WAIT_TIMEOUT:
rv = 0;
current->CurrentDeviceID = 0;
current->DeviceCount = 0;
break;
default: rv = 3; break;
2022-04-26 08:43:13 +02:00
}
}
return rv;
2024-05-28 08:09:23 +02:00
error:
return rv;
2022-04-26 08:43:13 +02:00
}
void Epd3Base::Epd3U::CloseDev(bool CloseAll)
{
2024-05-29 16:08:18 +02:00
if (epdComsHandle != nullptr) {
2022-04-26 08:43:13 +02:00
DisCon(0);
if (CloseAll) {
2024-09-04 13:05:16 +02:00
//CloseReader(epdComsHandle);
2022-04-26 08:43:13 +02:00
DestroyReaderInterface(epdComsHandle);
2024-05-29 16:08:18 +02:00
epdComsHandle = nullptr;
2022-04-26 08:43:13 +02:00
}
}
}
BYTE checkStatus(OpStatusFlags status, OpStatusFlags flag)
{
if (((uint32_t)status & (uint32_t)flag) == (uint32_t)flag) return 1; else return 0;
}
2022-08-24 11:42:03 +02:00
2022-04-26 08:43:13 +02:00
BYTE checkStatus(FaultStatusFlags status, FaultStatusFlags flag)
{
if (((uint32_t)status & (uint32_t)flag) == (uint32_t)flag) return 1; else return 0;
}
2022-08-24 11:42:03 +02:00
2022-04-26 08:43:13 +02:00
BYTE checkStatus(AlarmStatusFlags status, AlarmStatusFlags flag)
{
uint32_t ustatus = (uint32_t)status;
uint32_t uflag = (uint32_t)flag;
if ((ustatus & uflag) == uflag) return 1; else return 0;
}
2022-08-24 11:42:03 +02:00
2022-04-26 08:43:13 +02:00
BYTE checkStatus(DoseAlarmFlags status, DoseAlarmFlags flag)
{
if (((uint32_t)status & (uint32_t)flag) == (uint32_t)flag) return 1; else return 0;
}
void Epd3Base::Epd3U::DecodeStatus()
{
eDosDose07Warning = eDosDose07Alarm = eDosDose10Warning = eDosDose10Alarm = eDosRate07Warning = eDosRate07Alarm = eDosRate10Warning = eDosRate10Alarm = eDosBatteryWarning = eDosDoseAlarm = eDosRateAlarm = 0;
2024-05-30 13:42:08 +02:00
AlarmDoseHP07N = AlarmRateHP07N = AlarmDoseHP101G = AlarmDoseHP102G = AlarmRateHP101G = AlarmRateHP102G= 0;
2022-04-26 08:43:13 +02:00
hasAlarm = hasFault = false;
DetectorsOn = checkStatus(epd3status.OperatingStatus, OpStatusFlags::EpdOn);
EPDIssued = checkStatus(epd3status.OperatingStatus, OpStatusFlags::EpdIssued);
EPDLocked = checkStatus(epd3status.OperatingStatus, OpStatusFlags::GainAdjustable);
EPDTesting = checkStatus(epd3status.OperatingStatus, OpStatusFlags::DetectorTestRequested);
2024-05-29 16:08:18 +02:00
EPDFaulty = checkStatus(epd3status.FaultStatus, FaultStatusFlags::EpdFaulty);
EPDNewFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::ErrorLogged);
2022-04-26 08:43:13 +02:00
EPDComFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::EarlyCommsTermination);
EPDCalFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::NotCalibrated);
EPDDetFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::DetectorTestFail);
EPDEprFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::EepromFailure);
EPDTrhFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::BadThreshold);
for (int ix = 0; ix < 4; ix++)
{
DoseAlarmFlags status = epd3status.DoseAlarms[ix].Status;
switch ((MeasurementId)epd3status.DoseAlarms[ix].Id)
{
case MeasurementId::Meas_Hp07:
case MeasurementId::Meas_Hp10N:
eDosDose07Warning = checkStatus(status, DoseAlarmFlags::DoseWarning);
eDosDose07Alarm = checkStatus(status, DoseAlarmFlags::DoseAlarm);
2024-05-30 13:42:08 +02:00
eDosRate07Warning = checkStatus(status, DoseAlarmFlags::RateWarning);// | checkStatus(status, DoseAlarmFlags::LatchedRateWarning);
eDosRate07Alarm = checkStatus(status, DoseAlarmFlags::RateAlarm) ; // checkStatus(status, DoseAlarmFlags::LatchedRateAlarm)
2024-05-29 16:08:18 +02:00
AlarmDoseHP07N = checkStatus(status, DoseAlarmFlags::DoseAlarm);
2024-05-30 13:42:08 +02:00
AlarmRateHP07N = checkStatus(status, DoseAlarmFlags::RateAlarm);; // | checkStatus(status, DoseAlarmFlags::LatchedRateAlarm);
2022-04-26 08:43:13 +02:00
break;
case MeasurementId::Meas_Hp10:
case MeasurementId::Meas_Hp10G:
eDosDose10Warning = checkStatus(status, DoseAlarmFlags::DoseWarning);
eDosDose10Alarm = checkStatus(status, DoseAlarmFlags::DoseAlarm);
eDosRate10Warning = checkStatus(status, DoseAlarmFlags::LatchedRateWarning) | checkStatus(status, DoseAlarmFlags::RateWarning);
eDosRate10Alarm = checkStatus(status, DoseAlarmFlags::LatchedRateAlarm) | checkStatus(status, DoseAlarmFlags::RateAlarm);
AlarmDoseHP101G = checkStatus(status, DoseAlarmFlags::DoseAlarm);
AlarmDoseHP102G = AlarmDoseHP101G;
AlarmRateHP101G = checkStatus(status, DoseAlarmFlags::RateAlarm) | checkStatus(status, DoseAlarmFlags::LatchedRateAlarm);
AlarmRateHP102G = AlarmRateHP101G;
break;
}
}
2024-05-29 16:08:18 +02:00
2022-04-26 08:43:13 +02:00
OtherAlarmReturn = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::ReturnForRead);
OtherAlarmBatLow = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::LowBattery);
OtherAlarmCarrier = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::TelemetryAlert);
OtherAlarmBatVolt = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::LowBattery);
2024-05-29 16:08:18 +02:00
2024-05-30 13:42:08 +02:00
eDosDoseAlarm = (eDosDose10Alarm || eDosDose07Alarm) && checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::DoseAlarm);
eDosRateAlarm = (eDosRate07Alarm || eDosRate10Alarm) && checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::RateAlarm);
2024-05-28 08:09:23 +02:00
2024-05-29 16:08:18 +02:00
hasAlarm = eDosDoseAlarm || eDosRateAlarm;
hasFault = ((uint32_t)epd3status.FaultStatus & ~(uint32_t)FaultStatusFlags::ErrorLogged) != 0;
2022-04-26 08:43:13 +02:00
eDosBatteryWarning = OtherAlarmBatLow | OtherAlarmBatVolt;
}
2024-08-28 13:05:03 +02:00
int Epd3Base::Epd3U::SetTime() //Only R3
2022-04-26 08:43:13 +02:00
{
2024-08-28 13:05:03 +02:00
int r = 0;
if (Epd.Gen == EpdGeneration::Mk3)
{
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(WriteRTC_R3,1);
2022-04-26 08:43:13 +02:00
utc = TimeFunctions::NowToEpdTime(Epd.Gen == EpdGeneration::Mk2);
token = BeginWriteRTC_R3(epdComsHandle, utc, nullptr);
2024-09-05 16:10:29 +02:00
r = CommitAndEnd2RV(EndWriteRTC_R3, token);
2022-04-26 08:43:13 +02:00
}
2024-08-28 13:05:03 +02:00
return r;
2022-04-26 08:43:13 +02:00
}
void WINAPI ReadStatusCompletion(CommsHandle hComms, CompletionToken token)
{
int rv = EndReadStatus(current->epdComsHandle, token, &current->epd3status);
rv = current->SetEndReturnValue(rv);
current->IssueCount = current->epd3status.IssueCount;
current->OperatingStatus = current->epd3status.OperatingStatus;
current->AlarmStatus = current->epd3status.AlarmStatus;
current->ErrorStatus = current->epd3status.FaultStatus;
current->OtherAlarms = current->epd3status.OtherBits;
current->DecodeStatus(); //Alarm status...
2024-09-11 15:44:51 +02:00
DebugWrite("**** ReadStatusCompletion %04x ****\n", current->OperatingStatus);
SetEvent(current->hCompletion);
}
int Epd3Base::Epd3U::ReadStatusOnly()
{
int rv = 0;
ResetEvent(hCompletion);
SetFunctionReturnValue(eFunctions::ReadStatus, 0);
token = BeginReadStatus(epdComsHandle, ReadStatusCompletion);
rv = CommitAndSetRV();
return rv;
}
2022-04-26 08:43:13 +02:00
/// <summary>
///
/// </summary>
/// <returns>0 = ok</returns>
int Epd3Base::Epd3U::ReadStatus(bool onlyStatus)
2022-04-26 08:43:13 +02:00
{
2024-09-09 11:24:35 +02:00
int rv; //0=ok
//constexpr int maxbatch = 2;
//int batchstep;
//int s[maxbatch];
//int r[maxbatch];
2024-05-22 13:31:10 +02:00
int step = 0;
2022-04-26 08:43:13 +02:00
uint8_t length = 0;
countsRead = 0; utc = 0; seconds = 0;
memset(WearerID, 0, WearerIDLength + 1);
memset(WearerName, 0, WearerNameLength + 1);
2024-09-09 11:24:35 +02:00
rv = SetResponseTimeout(epdComsHandle, ResponseTimeout);
2022-04-26 08:43:13 +02:00
Error = 0;
if (port == 0) {
EpdID = 4567;
EpdType = EpdTypes::Mk2BetaGamma;
isBG = 1; isNG = 0; VersionOK = 1;
isMK3 = true;
FunctionFlags = 0x000;
Epd.Gen = EpdGeneration::None;
Epd.MaxBaud = 0;
Epd.Id = EpdID;
return 0;
}
isMK3 = Epd.Gen == EpdGeneration::Mk3;
OperatingStatus = (OpStatusFlags)0U;
AlarmStatus = (AlarmStatusFlags)0U;
ErrorStatus = (FaultStatusFlags)0;
IssueCount = OtherAlarms = EEPROMBadSectors = 0;
RealTime = EpdClock = OffTime = EpdID = 0;
ErrorSource = ErrorReason = ErrorData = 0;
2024-05-22 13:31:10 +02:00
HardVersion = HardVersionMinor = SoftVersion = FunctionFlags = 0;
2022-04-26 08:43:13 +02:00
2024-05-22 13:31:10 +02:00
step = 1;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadStatus,0);
2022-04-26 08:43:13 +02:00
token = BeginReadStatus(epdComsHandle, nullptr);
2024-09-09 11:24:35 +02:00
rv = CommitAndSetRV();
//batchstep = 0; //ReadStatus
//r = Commit3(epdComsHandle); SetCommitReturnValue(r);
if (!rv) rv = EndReadStatus(epdComsHandle, token, &epd3status);
rv = SetEndReturnValue(rv);
if (rv != 0) goto error;
2022-04-26 08:43:13 +02:00
IssueCount = epd3status.IssueCount;
OperatingStatus = epd3status.OperatingStatus;
AlarmStatus = epd3status.AlarmStatus;
ErrorStatus = epd3status.FaultStatus;
OtherAlarms = epd3status.OtherBits;
DecodeStatus(); //Alarm status...
2022-04-26 08:43:13 +02:00
if (onlyStatus) goto exitroutine;
uint32_t EpdID32 ;
2022-04-26 08:43:13 +02:00
uint32_t capabilities;
2024-09-09 11:24:35 +02:00
MarkNumber_t MarkNumber;
2022-04-26 08:43:13 +02:00
VersionNumber_t VersionNumber;
2024-05-29 16:08:18 +02:00
2024-05-22 13:31:10 +02:00
step = 2;
2024-09-09 11:24:35 +02:00
//batchstep = 1; //ReadEpdIdentities
EpdID32 = 0;
MarkNumber.Major = 0;
MarkNumber.Minor=0;
VersionNumber.Major = 0;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(ReadEpdIdentities,0);
2022-04-26 08:43:13 +02:00
token = BeginReadEpdIdentities(epdComsHandle, nullptr);
2024-09-09 11:24:35 +02:00
rv = CommitAndSetRV();
if (!rv) rv = EndReadEpdIdentities(epdComsHandle, token, &EpdID32, (EpdTypes*)&EpdType, &capabilities, &MarkNumber, &VersionNumber, NULL, 0);
rv = SetEndReturnValue(rv);
if (rv != 0) goto error;
2024-09-05 16:10:29 +02:00
2024-05-29 16:08:18 +02:00
2022-04-26 08:43:13 +02:00
EpdID = EpdID32;
isBG = (EpdType == EpdTypes::Mk2BetaGamma || EpdType == EpdTypes::Mk3BetaGamma);
isNG = (EpdType == EpdTypes::Mk2Neutron || EpdType == EpdTypes::Mk3Neutron);
HardVersion = MarkNumber.Major;
2024-05-22 13:31:10 +02:00
HardVersionMinor = MarkNumber.Minor;
2022-04-26 08:43:13 +02:00
SoftVersion = VersionNumber.Major;
VersionOK = true;
2022-04-26 08:43:13 +02:00
2024-05-22 13:31:10 +02:00
step = 3;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(ReadCounts,0);
2022-04-26 08:43:13 +02:00
token = BeginReadCounts(epdComsHandle, nullptr, 0, nullptr);
2024-09-09 11:24:35 +02:00
rv = CommitAndSetRV();
if (!rv) rv = EndReadCounts(epdComsHandle, token, Counts, MaxCounts, &countsRead, &utc, &seconds);
rv= SetEndReturnValue(rv);
if (rv) goto error;
2022-04-26 08:43:13 +02:00
decodeCounters(countsRead); //HG,SG ..
//Times
//1601-01-01T00:00:00Z.
//MK2 .. some utc... but no real time clock
2024-05-22 13:31:10 +02:00
step = 6;
2024-09-09 11:24:35 +02:00
//batchstep = 3;
2022-04-26 08:43:13 +02:00
if (utc == 0) {
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(ReadRTC,0);
2022-04-26 08:43:13 +02:00
token = BeginReadRTC(epdComsHandle, nullptr);
2024-09-09 11:24:35 +02:00
rv = CommitAndSetRV();
if (!rv) rv = EndReadRTC(epdComsHandle, token, &utc); //EpdClock for MK2
rv= SetEndReturnValue(rv);
if (rv) goto error;
2022-04-26 08:43:13 +02:00
EpdClock = utc;
utc = TimeFunctions::NowToEpdTime(true);
}
else {
EpdClock = utc;
}
FILETIME fUTC;
TimeFunctions::EpdTimeToFileTime(utc, &fUTC, Epd.Gen == EpdGeneration::Mk2);
FileTimeToSystemTime(&fUTC, &tRealTime);
2024-09-09 11:24:35 +02:00
step = 4;
if (EPDIssued) {
IdString_t mk3WearerID;
mk3WearerID.Length = 0;
2024-09-09 11:24:35 +02:00
//Mk2 EPDs only support Name and Primary ID
//batchstep = 0;
SetFunctionReturnValue(ReadWearerId, 0);
token= BeginReadWearerId(epdComsHandle, static_cast<uint16_t>(WearerIdType::WearerId_Name), nullptr);
rv = CommitAndSetRV();
if (!rv) rv = EndReadWearerId(epdComsHandle, token, &mk3WearerID);
rv = SetEndReturnValue(rv);
if (rv != 0) goto error;
if (mk3WearerID.Length > WearerNameLength) mk3WearerID.Length = WearerNameLength;
memcpy(WearerName, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length] = 0;
step = 5;
//batchstep = 1;
SetFunctionReturnValue(ReadWearerId, 0);
token = BeginReadWearerId(epdComsHandle, static_cast<uint16_t>(WearerIdType::WearerId_Primary), nullptr);
rv = CommitAndSetRV();
if (!rv) rv = EndReadWearerId(epdComsHandle, token, &mk3WearerID);
rv = SetEndReturnValue(rv);
if (rv != 0) goto error;
if (mk3WearerID.Length > WearerIDLength) mk3WearerID.Length = WearerIDLength;
memcpy(this->WearerID, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length] = 0;
for (int i = 0; i < mk3WearerID.Length; i++)
if (WearerID[i] == 0xb) WearerID[i] = '0'; else WearerID[i] |= 0x30;
}
exitroutine:
2024-09-09 11:24:35 +02:00
return rv;
2024-05-22 13:31:10 +02:00
2022-04-26 08:43:13 +02:00
error:
2024-09-09 11:24:35 +02:00
//Cancel(epdComsHandle);
Error = rv;
2024-05-22 13:31:10 +02:00
ErrorStep = step;
2024-09-09 11:24:35 +02:00
return rv;
2024-05-29 16:08:18 +02:00
2022-04-26 08:43:13 +02:00
}
/// <summary>
/// discover, connect and read status
/// </summary>
/// <param name="tokenSourceTimeout"></param>
2022-05-04 07:53:20 +02:00
/// <returns>0=success 1=connect error, 2 = time out , no devices, 3= error reading status</returns>
2022-04-26 08:43:13 +02:00
int Epd3Base::Epd3U::ConnectAndStatus(int tokenSourceTimeout)
{
WORD dllStatus;
int rv = 1;
2024-05-29 16:08:18 +02:00
Error = 0; ErrorStep = 0; hasAlarm = hasFault = 0;
2024-09-04 13:05:16 +02:00
ResetStepReturnValues();
2022-04-26 08:43:13 +02:00
if (CommsInitialized == 0) StartCom();
if (CommsInitialized) {
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(fStartDiscover,0);
2022-04-26 08:43:13 +02:00
dllStatus = StartDiscover(tokenSourceTimeout);
2024-09-05 16:10:29 +02:00
SetCommitReturnValue(0);
if (dllStatus==1) SetEndReturnValue(0); else SetEndReturnValue(dllStatus);
2024-09-04 13:05:16 +02:00
2022-04-26 08:43:13 +02:00
if (dllStatus != 1) rv = 1; //Connect error
else if (DeviceCount < 1) rv = 2; //TO
else if (isMK3 && ReadStatus(false) != 0) rv = 1; //Read Error
2022-04-26 08:43:13 +02:00
else rv = 0;
}
else rv = 1;
return rv;
}
/// <summary>
/// K1 = K2 = K3 = K4 = K4 = K6 (*100000 )
/// </summary>
/// <param name="count"></param>
2022-08-24 11:42:03 +02:00
2022-04-26 08:43:13 +02:00
void Epd3Base::Epd3U::decodeSensitivities(int count) {
K1 = K2 = K3 = K4 = K4 = K6 = 0.0F;
for (int ix = count - 1; ix >= 0; ix--) {
switch ((SensitivityId)sensitivities[ix].id)
{
case SensitivityId::Hg1Sens10G: K1 = sensitivities[ix].value * 100000; break;
case SensitivityId::Sg1Sens10G: K2 = sensitivities[ix].value * 100000; break;
case SensitivityId::Hg1Sens07G: K3 = sensitivities[ix].value * 100000; break; //Neutr=FN
case SensitivityId::Sg1Sens07G: K4 = sensitivities[ix].value * 100000; break; //Neutr=AN
case SensitivityId::Fb1Sens07B: K5 = sensitivities[ix].value * 100000; break;
case SensitivityId::Sg2Sens07B: K6 = sensitivities[ix].value * 100000; break;
default: break;
}
}
}
void Epd3Base::Epd3U::decodetotDoses(int count)
{
//doses
Hp10Total = Hp07Total = 0;
for (int ix = 0; ix < count; ix++)
{
switch ((MeasurementId)doses[ix].id) {
case MeasurementId::Meas_Hp07: Hp07Total = doses[ix].value; break;
case MeasurementId::Meas_Hp10: Hp10Total = doses[ix].value; break;
case MeasurementId::Meas_Hp10N: Hp07Total = doses[ix].value; break;
case MeasurementId::Meas_Hp10G: Hp10Total = doses[ix].value; break;
}
}
}
void Epd3Base::Epd3U::decodeDoses(int count)
{
//doses
Hp10Dose = Hp07Dose = 0;
for (int ix = 0; ix < count; ix++)
{
switch ((MeasurementId)doses[ix].id) {
case MeasurementId::Meas_Hp07: Hp07Dose = doses[ix].value; break;
case MeasurementId::Meas_Hp10: Hp10Dose = doses[ix].value; break;
case MeasurementId::Meas_Hp10N: Hp07Dose = doses[ix].value; break;
case MeasurementId::Meas_Hp10G: Hp10Dose = doses[ix].value; break;
}
}
}
void Epd3Base::Epd3U::decodePeakRates(int count)
{
//Rates
Hp10Peak = Hp07Peak = 0;
Hp10Time = Hp07Time = 0;
/*SYSTEMTIME st07,st10;*/
for (int ix = 0; ix < count; ix++)
{
switch ((MeasurementId)peakRates[ix].id) {
case MeasurementId::Meas_Hp07:
case MeasurementId::Meas_Hp10N:
Hp07Peak = peakRates[ix].value;
Hp07Time = peakRates[ix].timestamp;
TimeFunctions::EpdTimeToFileTime(Hp07Time, (LPFILETIME)&Hp07FTime, false);
//FileTimeToSystemTime(&Hp07FTime, &st07);
break;
case MeasurementId::Meas_Hp10:
case MeasurementId::Meas_Hp10G:
Hp10Peak = peakRates[ix].value;
Hp10Time = peakRates[ix].timestamp;
TimeFunctions::EpdTimeToFileTime(Hp10Time, (LPFILETIME)&Hp10FTime, false);
//FileTimeToSystemTime(&Hp10FTime, &st10);
break;
}
}
}
void Epd3Base::Epd3U::decodeCounters(int count)
{
HG = SG = BC = FB = 0;
for (int ix = 0; ix < count; ix++)
{
switch ((CounterType)Counts[ix].type) {
case CounterType::Counter_Hg1: HG = Counts[ix].value; break;
case CounterType::Counter_Sg1: SG = Counts[ix].value; break;
case CounterType::Counter_Sg2: BC = Counts[ix].value; break;
case CounterType::Counter_Fb1: FB = Counts[ix].value; break;
}
}
}
void Epd3Base::Epd3U::decodeBaseCounters(int count)
{
D1 = D2 = D3 = D4 = 0;
for (int ix = 0; ix < count; ix++)
{
switch ((CounterType)Counts[ix].type) {
case CounterType::Counter_Hg1: D1 = Counts[ix].value; break;
case CounterType::Counter_Sg1: D2 = Counts[ix].value; break;
case CounterType::Counter_Sg2: D3 = Counts[ix].value; break;
case CounterType::Counter_Fb1: D4 = Counts[ix].value; break;
}
}
}
void Epd3Base::Epd3U::decodeTreshold(Mk3AlarmThresholds_t* th)
{
float* pThDose = nullptr, * pThRate = nullptr, * pTHDoseWarning = nullptr, * pTHRateWarning = nullptr;
switch ((MeasurementId)th->MeasId)
{
case MeasurementId::Meas_Hp07:
case MeasurementId::Meas_Hp10N:
Hp07THDose = 0; Hp07RateOn = 0; Hp07RateOff = 0;
pThDose = &Hp07THDose;
pThRate = &Hp07RateOn;
pTHDoseWarning = &Hp07THDoseA;
pTHRateWarning = &Hp07RateAOn;
break;
case MeasurementId::Meas_Hp10:
Hp10THDose1 = 0; Hp10THDose2 = 0;
Hp10Rate1On = Hp10Rate2On = Hp10Rate1Off = Hp10Rate2Off = 0;
pThDose = &Hp10THDose2;
pThRate = &Hp10Rate2On;
pTHDoseWarning = &Hp10THDose1;
pTHRateWarning = &Hp10Rate1Off;
break;
}
for (int ix = 0; ix < th->NumberThresholds; ix++)
{
switch ((ThresholdId)th->Thresholds[ix].Id) {
case ThresholdId::Thres_DoseAlarm: if (pThDose != nullptr) *pThDose = th->Thresholds[ix].Value; break;
case ThresholdId::Thres_DoseWarning: if (pTHDoseWarning != nullptr) *pTHDoseWarning = th->Thresholds[ix].Value; break;
case ThresholdId::Thres_RateAlarm: if (pThRate != nullptr) *pThRate = th->Thresholds[ix].Value; break;
case ThresholdId::Thres_RateWarning: if (pTHRateWarning != nullptr) *pTHRateWarning = th->Thresholds[ix].Value; break;
}
}
}
void Epd3Base::Epd3U::encodeTreshold(Mk3AlarmThresholds_t* th)
{
//th.MeasId
float* pThDose, * pThRate, * pTHDoseWarning, * pTHRateWarning;
//Voorlopig
Hp07THDoseA = Hp07THDose * 0.8F;
Hp07RateAOn = Hp07RateOn * 0.8F;
// einde voorlopig
th->NumberThresholds = 4;
switch ((MeasurementId)th->MeasId) {
case MeasurementId::Meas_Hp07:
case MeasurementId::Meas_Hp10N:
pThDose = &Hp07THDose;
pTHDoseWarning = &Hp07THDoseA;
pThRate = &Hp07RateOn;
pTHRateWarning = &Hp07RateAOn;
RatePct[0].MeasId = th->MeasId;
RatePct[0].Value = 85; // (int)(Hp07RateOff * 100.0 / Hp07RateOn);
break;
case MeasurementId::Meas_Hp10:
case MeasurementId::Meas_Hp10G:
pThDose = &Hp10THDose2;
pThRate = &Hp10Rate2On;
pTHDoseWarning = &Hp10THDose1;
pTHRateWarning = &Hp10Rate1On;
RatePct[1].MeasId = th->MeasId;
RatePct[1].Value = 85; // (int)(Hp10Rate2Off * 100.0 / Hp10Rate2On);
break;
default:
pThDose = &Hp07THDose;
pTHDoseWarning = &Hp07THDoseA;
pThRate = &Hp07RateOn;
pTHRateWarning = &Hp07RateAOn;
}
th->Thresholds[0].Id = (uint16_t)ThresholdId::Thres_DoseAlarm;
th->Thresholds[0].Value = *pThDose;
th->Thresholds[1].Id = (uint16_t)ThresholdId::Thres_RateAlarm;
th->Thresholds[1].Value = *pThRate;
th->Thresholds[2].Id = (uint16_t)ThresholdId::Thres_DoseWarning;
th->Thresholds[2].Value = *pTHDoseWarning;
th->Thresholds[3].Id = (uint16_t)ThresholdId::Thres_RateWarning;
th->Thresholds[3].Value = *pTHRateWarning;
}
/// <summary>
/// HG, SG, BC, FB, BC, FB
/// </summary>
/// <param name="numdTresholds"></param>
void Epd3Base::Epd3U::decodedTresholds(int numdTresholds)
{
for (int ix = 0; ix < numdTresholds; ix++) {
switch ((CounterType)dTresholds[ix].type) {
case CounterType::Counter_Hg1: HG = dTresholds[ix].value; break;
case CounterType::Counter_Sg1: SG = dTresholds[ix].value; break;
case CounterType::Counter_Sg2: BC = dTresholds[ix].value; break;
case CounterType::Counter_Fb1: FB = dTresholds[ix].value; break;
case CounterType::Counter_An1: BC = dTresholds[ix].value; break; //AN-> BC
case CounterType::Counter_Fn2: FB = dTresholds[ix].value; break; //FN->FB
}
}
}
/// <summary>
/// Read K1 = K2 = K3 = K4 = K4 = K6
/// </summary>
/// <returns></returns>
WORD Epd3Base::Epd3U::ReadCal()
{
int r = 0;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(ReadSensitivities,0);
2022-04-26 08:43:13 +02:00
token = BeginReadSensitivities(epdComsHandle, nullptr, 0, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndSetRV();
//r = Commit3(epdComsHandle); SetCommitReturnValue(r);
2022-04-26 08:43:13 +02:00
r = EndReadSensitivities(epdComsHandle, token, sensitivities, MaxSensitivities, &numSensitivities);
2024-09-05 16:10:29 +02:00
r = SetEndReturnValue(r);
if (r != 0) goto error;
2022-04-26 08:43:13 +02:00
decodeSensitivities(numSensitivities);
return r;
error:
2024-05-22 13:31:10 +02:00
Error = r;
2022-04-26 08:43:13 +02:00
return r;
}
/// <summary>
/// K1 .. K6, SG , BC ,FB , HG
/// </summary>
/// <returns>0 OK</returns>
WORD Epd3Base::Epd3U::ReadSensitivitiesAndTresholds()
{
int32_t r = 0;
if (Epd.Gen == EpdGeneration::Mk2) {
uint16_t HGSens10;
uint16_t SGSens10;
uint16_t HGSens07;
uint16_t SGSens07;
uint16_t FBSens07;
uint16_t BCSens07;
uint16_t SGthresh;
uint16_t BCthresh;
uint16_t FBthresh;
uint16_t HGthresh;
token = BeginReadCalibrationData_R2(epdComsHandle, nullptr);
r = Commit3(epdComsHandle);
r = EndReadCalibrationData_R2(epdComsHandle, token,
&HGSens10,
&SGSens10,
&HGSens07,
&SGSens07,
&FBSens07,
&BCSens07,
&SGthresh,
&BCthresh,
&FBthresh,
&HGthresh
);
K1 = HGSens10;
K2 = SGSens10;
K3 = HGSens07;
K4 = SGSens07;
K5 = FBSens07;
K6 = BCSens07;
SG = SGthresh;
BC = BCthresh;
FB = FBthresh;
HG = HGthresh;
}
else {
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(ReadDetectorThresholds,0);
2022-04-26 08:43:13 +02:00
token = BeginReadDetectorThresholds_R3(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(r);
2022-04-26 08:43:13 +02:00
r = EndReadDetectorThresholds_R3(epdComsHandle, token, dTresholds, MaxTresholds, &numTresholds);
2024-09-05 16:10:29 +02:00
r = SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
decodedTresholds(numTresholds); // HG, SG, BC, FB, BC, FB
r = ReadCal();// K1 = K2 = K3 = K4 = K4 = K6
}
return r;
error:
return r;
}
/// <summary>
/// Doses, totDoses, Knocks + Resets , PeakRates, SensitivitiesAndTresholds: K1 .. K6, SG , BC ,FB , HG
/// </summary>
/// <returns>0 OK</returns>
WORD Epd3Base::Epd3U::ReadDoses()
{
int32_t r = 1;
eDosDose07Warning = eDosDose07Alarm = eDosDose10Warning = eDosDose10Alarm = eDosRate07Warning = eDosRate07Alarm = eDosRate10Warning = eDosRate10Alarm = eDosBatteryWarning = 0;
if (port == 0) {
Hp10Dose = Hp07Dose = Hp10Total = Hp07Total = 0.0;
Knocks = Resets = QualityData = 21;
Hp10Peak = Hp07Peak = 0.0;
Hp10Time = Hp07Time = 1000;
ErrorSource = ErrorReason = ErrorData = 0;
K1 = 1; K2 = 2; K3 = 3; K4 = 4; K5 = 5; K6 = 6;
SG = 7; BC = 8; FB = 9; HG = 10;
2024-05-29 16:08:18 +02:00
return r_OK;
2022-04-26 08:43:13 +02:00
}
2024-05-29 16:08:18 +02:00
2022-04-26 08:43:13 +02:00
numDoses = 0; utc = 0;
2024-05-29 16:08:18 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::fReadDoses,0);
2022-04-26 08:43:13 +02:00
token = BeginReadDoses(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(r);
2022-04-26 08:43:13 +02:00
if (!r) r = EndReadDoses(epdComsHandle, token, doses, MaxDoses, &numDoses, &utc);
2024-09-05 16:10:29 +02:00
r = SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
2024-05-22 13:31:10 +02:00
2022-04-26 08:43:13 +02:00
decodeDoses(numDoses);
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadTotalDoses,0);
2022-04-26 08:43:13 +02:00
token = BeginReadTotalDoses(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(r);
2022-04-26 08:43:13 +02:00
if (!r) r = EndReadTotalDoses(epdComsHandle, token, totdoses, MaxDoses, &numtotDoses, &utc);
2024-09-05 16:10:29 +02:00
r = SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
decodetotDoses(numtotDoses);
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadQualityData,0);
2022-04-26 08:43:13 +02:00
token = BeginReadQualityData(epdComsHandle, nullptr);
r = Commit3(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(r);
2022-04-26 08:43:13 +02:00
if (!r) r = EndReadQualityData(epdComsHandle, token, &quality);
2024-09-05 16:10:29 +02:00
r = SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
2024-05-22 13:31:10 +02:00
2022-04-26 08:43:13 +02:00
Knocks = quality.Knocks;
Resets = quality.PowerCycles;
2024-05-29 16:08:18 +02:00
2024-09-04 13:05:16 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadPeakRates,0);
2022-04-26 08:43:13 +02:00
token = BeginReadPeakRates(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(r);
2022-04-26 08:43:13 +02:00
if (!r) r = EndReadPeakRates(epdComsHandle, token, peakRates, MaxPeakRates, &numRates);
2024-09-05 16:10:29 +02:00
r= SetEndReturnValue(r);
2024-09-04 13:05:16 +02:00
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
decodePeakRates(numRates);
2024-09-04 13:05:16 +02:00
2024-05-29 16:08:18 +02:00
r = ReadSensitivitiesAndTresholds(); //K1 .. K6, SG , BC ,FB , HG
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
return r;
2024-05-29 16:08:18 +02:00
2022-04-26 08:43:13 +02:00
error:
2024-05-29 16:08:18 +02:00
Error = r;
2022-04-26 08:43:13 +02:00
return r;
}
/// <summary>
///
/// </summary>
/// <returns>0 success</returns>
int Epd3Base::Epd3U::ClearDoses()
{
2024-09-09 11:24:35 +02:00
//constexpr int maxbatch = 3;
2024-09-06 16:00:41 +02:00
int rv;
2024-09-09 11:24:35 +02:00
//int r[maxbatch];
//int s[maxbatch];
//int batchstep = 0;
SetFunctionReturnValue(eFunctions::ClearTotalDose,0);
token = BeginClearTotalDose(epdComsHandle, nullptr);
rv = CommitAndEnd2RV(EndClearTotalDose, token);
if (rv) goto error;
//batchstep = 1;
SetFunctionReturnValue(eFunctions::ClearDose,0);
token= BeginClearDose(epdComsHandle, nullptr);
rv = CommitAndEnd2RV(EndClearDose, token);
if (rv) goto error;
//batchstep = 2;
SetFunctionReturnValue(eFunctions::ClearPeakRates,0);
token= BeginClearPeakRates(epdComsHandle, nullptr);
rv = CommitAndEnd2RV(EndClearPeakRates, token);
if (rv) goto error;
2024-09-06 16:00:41 +02:00
2024-09-09 11:24:35 +02:00
//rv = CommitAndSetRV(s, maxbatch);
//batchstep = 0;
//r[batchstep] = End2RV(s[batchstep], EndClearTotalDose, btoken[batchstep]);
//batchstep = 1;
//r[batchstep] = End2RV(s[batchstep], EndClearDose, btoken[batchstep]);
//batchstep = 2;
//r[batchstep] = End2RV(s[batchstep], EndClearPeakRates, btoken[batchstep]);
//rv = r[0];
//for (int b = 1; !rv && b < maxbatch;++b) if (r[b]) rv = r[b];
error:
2024-09-06 16:00:41 +02:00
Error = rv;
return rv;
2024-05-29 16:08:18 +02:00
2022-04-26 08:43:13 +02:00
}
int Epd3Base::Epd3U::ClearAlarms()
{
2024-09-06 16:00:41 +02:00
constexpr int maxbatch = 2;
int rv;
int r[maxbatch];
int s[maxbatch];
int batchstep = 0;
2024-09-04 13:05:16 +02:00
2024-09-06 16:00:41 +02:00
s[batchstep] = SetFunctionReturnValue(eFunctions::ClearFaultStatus,0);
btoken[batchstep]= BeginClearFaultStatus(epdComsHandle, nullptr);
batchstep = 1;
s[batchstep] = SetFunctionReturnValue(eFunctions::ClearLatchedAlarms, 0);
btoken[batchstep] = BeginClearLatchedAlarms(epdComsHandle, nullptr);
rv = CommitAndSetRV(s, maxbatch);
batchstep = 0;
r[batchstep] = End2RV(s[batchstep],EndClearFaultStatus, btoken[batchstep]);
batchstep = 1;
r[batchstep] = End2RV(s[batchstep],EndClearLatchedAlarms, btoken[batchstep]);
rv = r[0];
for (int b = 1; !rv && b < maxbatch; ++b) if (r[b]) rv = r[b];
Error = rv;
return rv;
2022-04-26 08:43:13 +02:00
}
WORD Epd3Base::Epd3U::PrepareForIssue()
{
int rv = 0;
2024-05-16 15:56:07 +02:00
int step = 0;
2022-04-26 08:43:13 +02:00
if (port == 0) return 0;
2024-05-29 16:08:18 +02:00
2024-09-04 13:05:16 +02:00
2024-08-28 13:05:03 +02:00
/*if (DetectorsOn) {
2022-04-26 08:43:13 +02:00
token = BeginEpdOnOff(epdComsHandle, 0, nullptr);
rv = Commit3(epdComsHandle);
if (!rv) rv = EndEpdOnOff(epdComsHandle, token);
2024-05-22 13:31:10 +02:00
rv = ReOpenDev();
}
if (rv != 0)
2024-08-28 13:05:03 +02:00
goto error;*/
2024-09-05 16:10:29 +02:00
/* gebeurt bij clearalrms
SetFunctionReturnValue(eFunctions::ClearLatchedAlarms,0);
2024-08-28 13:05:03 +02:00
token = BeginEpdOnOff(epdComsHandle, 1, nullptr);
2024-09-05 16:10:29 +02:00
rv = CommitAndEnd2RV(EndEpdOnOff, token);
*/
2024-05-22 13:31:10 +02:00
step = 2;
if (WriteConfig32) {
rv = WriteConfig();
if (rv != 0)
goto error;
2022-04-26 08:43:13 +02:00
}
2024-05-22 13:31:10 +02:00
step = 3;
2024-08-28 13:05:03 +02:00
if (!isConnected)
rv = ReOpenDev();
2024-05-29 16:08:18 +02:00
2024-09-06 16:00:41 +02:00
step = 5;
rv = ClearAlarms();
2022-04-26 08:43:13 +02:00
if (rv != 0)
goto error;
2024-05-22 13:31:10 +02:00
2024-09-06 16:00:41 +02:00
step = 4;
rv = ClearDoses();
2022-04-26 08:43:13 +02:00
if (rv != 0)
goto error;
2024-09-05 16:10:29 +02:00
OutputDebugStringA("**** After clear ****\n");
Disconnect(epdComsHandle);
Sleep(SleepAfterClear);
2024-05-22 13:31:10 +02:00
2022-04-26 08:43:13 +02:00
return rv;
error:
2024-09-11 15:44:51 +02:00
DebugWrite("**** After clear step %d error %d ****\n", step, rv);
2024-05-22 13:31:10 +02:00
ErrorStep = step;
Error = rv;
2022-04-26 08:43:13 +02:00
return rv;
}
WORD Epd3Base::Epd3U::ReadAlarmConfig() {
//Alleen MK3 ? leeg bij MK2
2024-09-04 13:05:16 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadAlarmConfiguration,0);
2022-04-26 08:43:13 +02:00
token = BeginReadAlarmConfiguration(epdComsHandle, nullptr, 0, nullptr);
2024-09-06 16:00:41 +02:00
int32_t r = CommitAndSetRV();
2024-09-05 16:10:29 +02:00
if (!r) { r = EndReadAlarmConfiguration(epdComsHandle, token, alarmConfig, MaxAlarmConfig, &numAlarm); SetEndReturnValue(r); }
2022-04-26 08:43:13 +02:00
return numAlarm;
}
WORD Epd3Base::Epd3U::ReadAlarmTresholds() {
//Alleen MK3 ? leeg bij MK2
bool isNeutron = (EpdType == EpdTypes::Mk2Neutron || EpdType == EpdTypes::Mk3Neutron);
uint8_t measID;
uint32_t r;
2024-09-09 11:24:35 +02:00
SetResponseTimeout(epdComsHandle, ResponseTimeout);
2022-04-26 08:43:13 +02:00
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10N; else measID = (uint8_t)MeasurementId::Meas_Hp07;
hp07tresholds.MeasId = measID;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadAlarmThresholds,0);
2022-04-26 08:43:13 +02:00
token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)hp07tresholds.MeasId, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(r);
2024-09-05 16:10:29 +02:00
if (!r) { r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds); r = SetEndReturnValue(r); }
2022-04-26 08:43:13 +02:00
decodeTreshold(&hp07tresholds);
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10G; else measID = (uint8_t)MeasurementId::Meas_Hp10;
hp10tresholds.MeasId = measID;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadAlarmThresholds,0);
2022-04-26 08:43:13 +02:00
token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
2024-09-04 13:05:16 +02:00
SetCommitReturnValue(r);
2024-09-05 16:10:29 +02:00
if (!r) { r = EndReadAlarmThresholds(epdComsHandle, token, &hp10tresholds); r= SetEndReturnValue(r); }
2022-04-26 08:43:13 +02:00
decodeTreshold(&hp10tresholds);
return r;
}
WORD Epd3Base::Epd3U::WriteAlarmTresholds() {
//Alleen MK3 ? leeg bij MK2
uint32_t r;
bool isNeutron = (EpdType == EpdTypes::Mk2Neutron || EpdType == EpdTypes::Mk3Neutron);
uint8_t measID;
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10G; else measID = (uint8_t)MeasurementId::Meas_Hp10;
hp10tresholds.MeasId = measID;
encodeTreshold(&hp10tresholds);
2024-05-29 16:08:18 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteAlarmThresholds,0);
2022-04-26 08:43:13 +02:00
token = BeginWriteAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, (uint8_t)hp10tresholds.NumberThresholds, hp10tresholds.Thresholds, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndWriteAlarmThresholds, token);
if (r != 0) goto error;
2022-04-26 08:43:13 +02:00
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10N; else measID = (uint8_t)MeasurementId::Meas_Hp07;
hp07tresholds.MeasId = measID;
encodeTreshold(&hp07tresholds);
hp07tresholds.NumberThresholds = 4;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteAlarmThresholds,0);
2022-04-26 08:43:13 +02:00
token = BeginWriteAlarmThresholds(epdComsHandle, (uint8_t)hp07tresholds.MeasId, (uint8_t)hp07tresholds.NumberThresholds, hp07tresholds.Thresholds, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndWriteAlarmThresholds, token);
if (r != 0) goto error;
2022-04-26 08:43:13 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteRateOffPercentage,0);
2022-04-26 08:43:13 +02:00
token = BeginWriteRateOffPercentage(epdComsHandle, RatePct, 2, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndWriteRateOffPercentage, token);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
return r;
error:
return r;
}
WORD Epd3Base::Epd3U::DeIssue()
{
int r = 1;
2024-09-04 13:05:16 +02:00
2022-04-26 08:43:13 +02:00
if (port == 0) return 0;
2024-05-29 16:08:18 +02:00
if (CurrentDeviceID == 0) return 0;
if (EPDIssued)
{
2024-08-30 13:57:04 +02:00
#if DeissueWithClear
ErrorStep = 2;
r = ClearDoses();
ErrorStep = 1;
r = ClearAlarms();
//needed after clear alarms
Sleep(2000);
2024-08-30 13:57:04 +02:00
#endif
SetFunctionReturnValue(eFunctions::DeissueEPD, 0);
token = BeginDeissueEPD(epdComsHandle, nullptr);
r = CommitAndEnd2RV(EndDeissueEPD, token);
Sleep(100);
2022-04-26 08:43:13 +02:00
}
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::EpdOnOff,0);
2022-04-26 08:43:13 +02:00
token = BeginEpdOnOff(epdComsHandle, 0, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndEpdOnOff, token);
Sleep(100);
2024-09-05 16:10:29 +02:00
if (r) goto error;
2022-04-26 08:43:13 +02:00
return r;
2024-05-22 13:31:10 +02:00
2022-04-26 08:43:13 +02:00
error:
2024-05-22 13:31:10 +02:00
Error = r;
2022-04-26 08:43:13 +02:00
return r;
}
WORD Epd3Base::Epd3U::WriteWearer() {
int32_t r = 0;
2024-05-22 13:31:10 +02:00
int step = 0;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::SetBaselineCounters,0);
2022-04-26 08:43:13 +02:00
token = BeginSetBaselineCounters(epdComsHandle, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndSetBaselineCounters, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndSetBaselineCounters(epdComsHandle, token); SetEndReturnValue(r);
2024-05-29 16:08:18 +02:00
if (r != 0)
2022-04-26 08:43:13 +02:00
goto error;
IdString_t mk3WearerID;
//Mk2 EPDs only support Name and Primary ID
mk3WearerID.IdType = (uint16_t)WearerIdType::WearerId_Name;
mk3WearerID.Length = 23;
memcpy(mk3WearerID.Utf8String, WearerName, 23);
2024-05-29 16:08:18 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteWearerId,0);
2022-04-26 08:43:13 +02:00
token = BeginWriteWearerId(epdComsHandle, mk3WearerID, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndWriteWearerId, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndWriteWearerId(epdComsHandle, token); SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
mk3WearerID.IdType = (uint16_t)WearerIdType::WearerId_Primary;
mk3WearerID.Length = 13;
memcpy(mk3WearerID.Utf8String, WearerID, 13);
2024-05-29 16:08:18 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteWearerId,0);
2022-04-26 08:43:13 +02:00
token = BeginWriteWearerId(epdComsHandle, mk3WearerID, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndWriteWearerId, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndWriteWearerId(epdComsHandle, token); SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
return r;
2024-05-22 13:31:10 +02:00
error:
2024-09-04 13:05:16 +02:00
2024-05-22 13:31:10 +02:00
Error = r;
2022-04-26 08:43:13 +02:00
return r;
}
/// <summary>
///
/// </summary>
/// <returns>0 Success</returns>
2022-08-24 11:42:03 +02:00
2024-08-28 13:05:03 +02:00
WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru
2022-04-26 08:43:13 +02:00
{
2024-05-29 16:08:18 +02:00
int r = 0;
2024-05-16 15:56:07 +02:00
int step = 0;
2022-04-26 08:43:13 +02:00
int tries = 0;
2024-08-30 13:57:04 +02:00
UINT16 Control = 0;
2022-04-26 08:43:13 +02:00
if (port == 0) return r;
r = 0;
2022-09-06 15:44:32 +02:00
if (!PrepareDone) {
r = PrepareForIssue();
2024-05-28 08:09:23 +02:00
if (r) goto error;
2022-09-06 15:44:32 +02:00
}
2024-05-29 16:08:18 +02:00
2024-05-22 13:31:10 +02:00
step = 1;
2024-08-30 13:57:04 +02:00
if (!isConnected) r = ReOpenDev();
2024-05-28 08:09:23 +02:00
if (r) goto error;
2024-05-22 13:31:10 +02:00
2024-09-05 16:10:29 +02:00
step = 4;
//EPDIssued
//if (!DetectorsOn) {
SetFunctionReturnValue(eFunctions::EpdOnOff, 0);
token = BeginEpdOnOff(epdComsHandle, 1, nullptr);
r = CommitAndEnd2RV(EndEpdOnOff, token);
#ifdef ProtectSession
if (isMK3) {
Control = 1; // EndSessionControl;
//SetFunctionReturnValue(EnableProtectedSession, 1);
//token = BeginEnableProtectedSession(epdComsHandle, 1, nullptr);
//r = CommitAndEnd2RV(EndEnableProtectedSession, token);
//if (r != 0) goto error;
}
#else
Control = 0;
#endif
2024-05-22 13:31:10 +02:00
step = 2;
2022-04-26 08:43:13 +02:00
r = WriteAlarmTresholds();
if (r != 0)
goto error;
2024-05-29 16:08:18 +02:00
2024-05-22 13:31:10 +02:00
step = 3;
2022-04-26 08:43:13 +02:00
r = WriteWearer();
if (r != 0)
goto error;
tries = 1;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::IssueEPD,0);
2022-04-26 08:43:13 +02:00
token = BeginIssueEPD(epdComsHandle, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndIssueEPD, token);
2024-09-05 16:10:29 +02:00
2022-04-26 08:43:13 +02:00
if (r != 0) {
tries++;
2024-05-22 13:31:10 +02:00
if (r == r_ErrorNotConnected) ReOpenDev();
2022-04-26 08:43:13 +02:00
Sleep(500);
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::IssueEPD,0);
2022-04-26 08:43:13 +02:00
token = BeginIssueEPD(epdComsHandle, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndIssueEPD, token);
2022-04-26 08:43:13 +02:00
}
2024-05-22 13:31:10 +02:00
if (r)
2024-05-29 16:08:18 +02:00
goto error;
EPDIssued = 1;
2024-09-05 16:10:29 +02:00
2024-08-30 13:57:04 +02:00
2024-05-22 13:31:10 +02:00
step = 6;
2022-04-26 08:43:13 +02:00
if (isMK3) {
2024-08-30 13:57:04 +02:00
r = DisCon(Control); //stops protected session if control is EndSessionCOntrol
2022-04-26 08:43:13 +02:00
}
2024-05-22 13:31:10 +02:00
step = 7;
2022-04-26 08:43:13 +02:00
return r;
error:
2024-05-22 13:31:10 +02:00
ErrorStep = step;
Error = r;
2022-04-26 08:43:13 +02:00
return r;
}
2022-08-24 11:42:03 +02:00
2022-04-26 08:43:13 +02:00
WORD Epd3Base::Epd3U::EPDReadExtraStatus()
{
if (port == 0) return 1;
2024-05-29 16:08:18 +02:00
uint32_t r;
2022-04-26 08:43:13 +02:00
//byBatADC = bySupplyADC = 0;
/*CommitRV = ReadA2ConfigStatus(
&byBatADC,
&bySupplyADC,
&byStatus3,
&byStatus4);
if (CommitRV == 1) CommitRV = Commit3();*/
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::ReadBaselineCounts,0);
2022-04-26 08:43:13 +02:00
token = BeginReadBaselineCounts(epdComsHandle, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndSetRV();// Commit3(epdComsHandle); SetCommitReturnValue(r);
if (!r) r = EndReadBaselineCounts(epdComsHandle, token, Counts, 10, &utc, &countsRead);
2024-09-05 16:10:29 +02:00
r = SetEndReturnValue(r);
2024-05-29 16:08:18 +02:00
if (!r) decodeBaseCounters(countsRead);
2022-04-26 08:43:13 +02:00
//if (CommitRV == 1) CommitRV = ReadCounts(&D1, &D2, &D3, &D4, &CountsClock);
//if (CommitRV == 1) CommitRV = Commit3();
//if (CommitRV == 1) CommitRV = ReadBaseCounts(&BaseD1, &BaseD2, &BaseD3, &BaseD4, &BaseCountsClock);
//if (CommitRV == 1) CommitRV = Commit3();
return r;
}
2022-08-24 11:42:03 +02:00
2022-04-26 08:43:13 +02:00
WORD Epd3Base::Epd3U::WriteCal()
{
uint32_t r = 0;
if (port == 0) return 0;
if (K6 > 2000)
{
r = 0;
return 0;
}
if (EpdType == EpdTypes::Mk2Neutron)
{
Password = 9;
2024-09-04 13:05:16 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::MfrLogin_R2,0);
2022-04-26 08:43:13 +02:00
token = BeginMfrLogin_R2(epdComsHandle, Password, nullptr);
2024-09-05 16:10:29 +02:00
uint32_t r = CommitAndEnd2RV(EndMfrLogin_R2,token);
//Commit3(epdComsHandle); SetCommitReturnValue(r); if (!r ) r = EndMfrLogin_R2(epdComsHandle, token); SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteSensitivities_R2,0);
2022-04-26 08:43:13 +02:00
token = BeginWriteSensitivities_R2(epdComsHandle, nullptr, (uint16_t)K1, (uint16_t)K2, (uint16_t)K3, (uint16_t)K4, (uint16_t)K5, (uint16_t)K6);
2024-09-05 16:10:29 +02:00
r = CommitAndEnd2RV(EndWriteSensitivities_R2, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndWriteSensitivities_R2(epdComsHandle, token); SetEndReturnValue(r);
2022-04-26 08:43:13 +02:00
if (r != 0)
goto error;
}
return r;
error:
return r;
}
2022-08-24 11:42:03 +02:00
2022-04-26 08:43:13 +02:00
int Epd3Base::Epd3U::GetAll(bool Closeconnection)
{
2024-05-29 16:08:18 +02:00
int rv = 0, step = 1;
2022-04-26 08:43:13 +02:00
rv = ReadDoses();
2024-05-29 16:08:18 +02:00
step=2;
2022-04-26 08:43:13 +02:00
if (!rv) rv = ReadAlarmTresholds();
2024-09-05 16:10:29 +02:00
if (Closeconnection) EndCom(isConnected );
2022-04-26 08:43:13 +02:00
return rv;
}
// Main entry point deissue for MK3
2024-05-22 13:31:10 +02:00
int Epd3Base::Epd3U::GetAllDeissue(bool reconnect)
2022-04-26 08:43:13 +02:00
{
int rv = 0;
2024-05-22 13:31:10 +02:00
int step = 0;
2024-09-04 13:05:16 +02:00
ResetStepReturnValues();
2024-05-22 13:31:10 +02:00
step = 1;
2022-04-26 08:43:13 +02:00
rv = ReadDoses(); //0 = success
2024-05-28 08:09:23 +02:00
if (rv) goto error;
2022-04-26 08:43:13 +02:00
//rv = ReadAlarmTresholds(); //0 = success
2024-05-29 16:08:18 +02:00
2024-05-22 13:31:10 +02:00
step = 2;
2022-04-26 08:43:13 +02:00
rv = EPDReadExtraStatus();
2024-05-28 08:09:23 +02:00
if (rv) goto error;
2024-05-29 16:08:18 +02:00
2024-05-22 13:31:10 +02:00
step = 3;
2022-04-26 08:43:13 +02:00
rv = DeIssue(); //does close
2024-09-04 13:05:16 +02:00
2024-05-28 08:09:23 +02:00
if (rv) goto error;
EndCom(isConnected);
2024-05-22 13:31:10 +02:00
return rv;
2024-05-22 13:31:10 +02:00
error:
EndCom(isConnected);
2024-05-22 13:31:10 +02:00
Error = rv;
ErrorStep = step;
2022-04-26 08:43:13 +02:00
return rv;
}
2024-08-28 13:05:03 +02:00
// main issue routine
2024-05-29 16:08:18 +02:00
int Epd3Base::Epd3U::IssueAndCheck(float gain, float ChirpRate)
2022-04-26 08:43:13 +02:00
{
int rv = 0;
2024-05-16 15:56:07 +02:00
int step = 0;
DWORD wrv = 0;
int rv1 = -1, rv2 = -1;
ResetStepReturnValues();
2024-05-29 16:08:18 +02:00
if (!isConnected) rv = ReOpenDev();
2024-05-28 08:09:23 +02:00
if (rv) goto error;
2024-05-16 15:56:07 +02:00
2024-08-28 13:05:03 +02:00
step = 1;
rv = SetTime();
//synctime
OutputDebugStringW(L"**** Prepare ****\n");
2024-08-28 13:05:03 +02:00
step = 2;
rv = PrepareForIssue(); //Set epd on, clear doses and alarms
if (rv) goto error;
rv = ReOpenDev();
rv = ReadStatusOnly();
wrv= WaitForSingleObject(hCompletion, 2000);
if (wrv == WAIT_OBJECT_0) rv = 0;
else if (wrv == WAIT_TIMEOUT) {
rv = 1;
}
//rv1 = StepReturnValues[CurrentStep][1];
//rv2 = StepReturnValues[CurrentStep][2];
2024-08-28 13:05:03 +02:00
step = 3;
2022-04-26 08:43:13 +02:00
if (isNG) {
2024-05-22 13:31:10 +02:00
step = 1;
2022-04-26 08:43:13 +02:00
float kx = gain;
rv = ReadCal();
if (rv != 0 || K6 != 1310) { rv = 1; goto error; }
if (K3 != kx || K4 != kx)
{
2024-05-22 13:31:10 +02:00
step = 2;
2022-04-26 08:43:13 +02:00
K3 = K4 = kx;
rv = WriteCal();
if (rv != 0) goto error;
}
}
2024-08-28 13:05:03 +02:00
2024-05-22 13:31:10 +02:00
step = 3;
2024-09-09 11:24:35 +02:00
if (!isConnected) rv = ReOpenDev();
2024-05-29 16:08:18 +02:00
rv = SetChirp(ChirpRate);
2024-09-05 16:10:29 +02:00
if (rv == r_ErrorNotConnected)
{
rv = ReOpenDev();
rv = SetChirp(ChirpRate);
}
2024-05-28 08:09:23 +02:00
if (rv) goto error;
2024-05-22 13:31:10 +02:00
step = 5;
2024-05-28 08:09:23 +02:00
rv = Issue(true); // data already loaded
if (rv) goto error;
2024-05-22 13:31:10 +02:00
//debug
/*rv = 1; EPDIssued = 0; goto error;*/
EndCom(isConnected);
2022-04-26 08:43:13 +02:00
return rv;
2022-04-26 08:43:13 +02:00
error:
EndCom(isConnected);
2024-05-22 13:31:10 +02:00
Error = rv;
ErrorStep = step;
2022-04-26 08:43:13 +02:00
return rv;
2022-08-24 11:42:03 +02:00
}
int Epd3Base::Epd3U::WriteConfig(void)
{
2024-05-29 16:08:18 +02:00
if (port == 0 || WriteConfig32 == 0) return 1;
2022-08-24 11:42:03 +02:00
int32_t r = 0;
ECLen = 32;
2024-09-11 15:44:51 +02:00
DebugWrite("**** WriteCfg v %d.%d ****\n", HardVersion, HardVersionMinor);
2024-09-05 16:10:29 +02:00
// Become admin
SetFunctionReturnValue(eFunctions::WriteAccessLevelAdmin,0);
2024-05-29 16:08:18 +02:00
token = BeginWriteAccessLevel(epdComsHandle, AccessLevel_t::Admin, EC, ECLen, nullptr);
2024-09-05 16:10:29 +02:00
r = CommitAndEnd2RV(EndWriteAccessLevel,token);
2022-08-30 09:10:33 +02:00
if (!r) {
displayIds = new QuickAccessDisplay_t[6]{
{ 0,0x0021 },
{ 1,0x0022 },
{ 2,0x0031 },
{ 3,0x0032 },
{ 4,0x0051 },
{ 5,0x0062 }
};
numDisplays = 6;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteQuickAccessDisplays_R3,1);
2022-08-30 09:10:33 +02:00
token = BeginWriteQuickAccessDisplays_R3(epdComsHandle, displayIds, numDisplays, nullptr);
2024-09-05 16:10:29 +02:00
r = CommitAndEnd2RV(EndWriteQuickAccessDisplays_R3, token);
2022-08-30 09:10:33 +02:00
}
if (!r) {
2022-09-06 08:37:42 +02:00
//Unmanaged%20HtmlFiles/_display_ids.html
2022-08-30 09:10:33 +02:00
numItems = 9;
if (HardVersionMinor > 0) {
enables = new DisplayAttributeMap_t[9]{
{ 0,0x3FFF,0xFFFF },
{ 1,0x3FFF,0xFF01 }, //{ 1,0x0FFF,0xFFE1 }
{ 2,0x3FFF,0xFE0F },
{ 3,0x3FFF,0xFE0F },
{ 4,0x3FFF,0xFE01 },
{ 5,0x3FFF,0xFF0B },
{ 6,0x3FFF,0xFFF9 },
{ 7,0x3FFF,0xFFD3 },
{ 8,0x3FFF,0xFFFF }
};
}
else {
enables = new DisplayAttributeMap_t[9]{
{ 0,0x0FFF, 0xFFFF },
{ 1,0x0FFF,0xFFE1 },
{ 2,0x0FFF,0xFE07 },
{ 3,0x0FFF,0xFE07 },
{ 4,0x0FFF,0xFE01 },
{ 5,0x0FFF,0xFF0B },
{ 6,0x0FFF,0xFFF9 },
{ 7,0x0FFF,0xFFD3 },
{ 8,0x0FFF,0xFFFF }
};
}
2022-09-06 08:37:42 +02:00
// 0x1 Operation Menu Back /0x2 On / Off 0x4 Clear Dose 0x8 Toggle Telemtry 0x10 Responder Trigger
// 1 0 0 0 0
2022-08-30 09:10:33 +02:00
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteDisplayEnables_R3,1);
2022-08-30 09:10:33 +02:00
token = BeginWriteDisplayEnables_R3(epdComsHandle, enables, numItems, nullptr);
2024-09-05 16:10:29 +02:00
r = CommitAndEnd2RV(EndWriteDisplayEnables_R3, token);
2022-08-30 09:10:33 +02:00
}
if (!r) {
uint8_t numMenus = 9;
uint16_t permissions[9] = {
0x0000 ,
0x0016 ,
2024-09-05 16:10:29 +02:00
0x0000 ,
2022-08-30 09:10:33 +02:00
0x0000 ,
0x0000 ,
0x0000 ,
0x0000 ,
0x0004 ,
2022-09-06 14:17:43 +02:00
0x0000
2022-08-30 09:10:33 +02:00
};
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteDisplayEnablePermissions_R3,1);
2022-08-30 09:10:33 +02:00
token = BeginWriteDisplayEnablePermissions_R3(epdComsHandle, AccessLevel_t::Admin, permissions, numDisplays, nullptr);
2024-09-05 16:10:29 +02:00
r = CommitAndEnd2RV(EndWriteDisplayEnablePermissions_R3, token);
2022-08-30 09:10:33 +02:00
}
2022-09-06 13:08:23 +02:00
if (!r) {
//AlarmConfiguration
uint8_t alarmConfigLen = 14;
alarmConfigIds = new AlarmConfig_t[14]{
2024-09-05 16:10:29 +02:00
{ (AlarmIds)6,0,0x0000,0x1884,60 },
{ (AlarmIds)8,0,0x0000,0x9884,60 },
{ (AlarmIds)5,0,0x0000,0x9CA4,60 },
{ (AlarmIds)4,0,0x0000,0x9CC7,60 },
{ (AlarmIds)9,0,0x0000,0x9CA5,60 },
2022-09-06 13:08:23 +02:00
{ (AlarmIds)7,0,0x0000,0x1884,60 },
2024-09-05 16:10:29 +02:00
{ (AlarmIds)0,0,0x0000,0x9CC1,60 },
{ (AlarmIds)1,0,0x0000,0x1884,60 },
{ (AlarmIds)2,0,0x0000,0x9CC7,60 },
{ (AlarmIds)3,0,0x0000,0x1885,60 },
{ (AlarmIds)0,1,0x0000,0x9CC1,60 },
{ (AlarmIds)1,1,0x0000,0x1884,60 },
{ (AlarmIds)2,1,0x0000,0x9CC7,60 },
{ (AlarmIds)3,1,0x0000,0x1885,60 }
2022-09-06 13:08:23 +02:00
};
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteAlarmConfiguration_R3,1);
2022-09-06 13:08:23 +02:00
token = BeginWriteAlarmConfiguration_R3(epdComsHandle, alarmConfigIds, alarmConfigLen, nullptr);
2024-09-05 16:10:29 +02:00
r = CommitAndEnd2RV(EndWriteAlarmConfiguration_R3, token);
2022-09-06 13:08:23 +02:00
}
2024-08-30 13:57:04 +02:00
2024-09-09 11:24:35 +02:00
//constexpr int maxbatch= 2;
//int s[maxbatch];
//int rv[maxbatch];
//int batchstep;
2024-09-06 16:00:41 +02:00
2022-09-06 14:17:43 +02:00
if (!r) {
2024-09-06 16:00:41 +02:00
//OffModeDisplay
2022-09-06 14:17:43 +02:00
dutyCycle = (OffModeDutyCycle)0;
offModeDispId = (OffModeDisplayId_t)1;
2024-09-09 11:24:35 +02:00
SetFunctionReturnValue(eFunctions::WriteOffModeDisplay_R3,1);
token = BeginWriteOffModeDisplay_R3(epdComsHandle, dutyCycle, offModeDispId, nullptr);
r = CommitAndEnd2RV(EndWriteOffModeDisplay_R3, token);
2022-09-06 14:17:43 +02:00
uint8_t OnOfenabled = 0;
2024-09-09 11:24:35 +02:00
SetFunctionReturnValue(eFunctions::WriteSwitchOnFromButton_R3, 0);
token = BeginWriteSwitchOnFromButton_R3(epdComsHandle, OnOfenabled, nullptr);
r = CommitAndEnd2RV(EndWriteSwitchOnFromButton_R3, token);
2024-09-06 16:00:41 +02:00
SetFunctionReturnValue(eFunctions::WriteAccessLevelOpen, 0);
token = BeginWriteAccessLevel(epdComsHandle, AccessLevel_t::Open,nullptr,0, nullptr);
r = CommitAndEnd2RV(EndWriteAccessLevel, token);
Sleep(200);
r = DisconnectAndConnect();
2024-09-06 16:00:41 +02:00
Error = r;
2022-09-06 14:17:43 +02:00
}
2024-09-06 16:00:41 +02:00
2022-08-24 11:42:03 +02:00
return r;
}
int Epd3Base::Epd3U::SetChirp(float Sensitivity)
{
uint32_t r = 1;
uint8_t enable = 0;
2024-05-22 13:31:10 +02:00
2022-08-24 11:42:03 +02:00
if (Sensitivity > 0.001F) {
enable = 1;
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteChirpSensitivity,0);
2024-05-29 16:08:18 +02:00
token = BeginWriteChirpSensitivity(epdComsHandle, Sensitivity, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndWriteChirpSensitivity , token);
2022-08-24 11:42:03 +02:00
}
2024-05-28 08:09:23 +02:00
if (r) goto error;
2022-08-24 11:42:03 +02:00
2024-05-28 08:09:23 +02:00
if (!r) {
2024-09-05 16:10:29 +02:00
SetFunctionReturnValue(eFunctions::WriteChirpEnable_R3,0);
2024-05-28 08:09:23 +02:00
token = BeginWriteChirpEnable_R3(epdComsHandle, enable, nullptr);
2024-09-04 13:05:16 +02:00
r = CommitAndEnd2RV(EndWriteChirpEnable_R3, token);
2024-05-28 08:09:23 +02:00
}
if (r) goto error;
2022-08-24 11:42:03 +02:00
2024-05-28 08:09:23 +02:00
return r;
error:
2022-08-24 11:42:03 +02:00
return r;
}