eDosStation/EpdBase3/Epd3Base.cpp
2026-07-28 16:36:22 +02:00

2011 lines
57 KiB
C++

#include "pch.h"
#include "pch.h"
#pragma unmanaged
#include "Epd3Base.h"
#include "TimeFunctions.h"
#pragma unmanaged
#define noDeissueWithClear
#define ProtectSession
#if _DEBUG
#define DebugWrite(f,...) snprintf(current->DiagnosticsWrite, DiagnosticsWriteSize, f ,__VA_ARGS__); OutputDebugStringA(current->DiagnosticsWrite);
#else
#define DebugWrite(f,...) ;
#endif
constexpr int SleepAfterClear = 1000;
//-102 = permission
Epd3Base::Epd3U* current;
void Epd3Base::Epd3U::ResetStepReturnValues()
{
CurrentStep = -1;
HasStepError = 0;
for (int i = MaxSteps - 1; i >= 0; --i) for (int j = 0; j < 4; j++) StepReturnValues[i][j] = 0;
}
int Epd3Base::Epd3U::SetFunctionReturnValue(enum eFunctions f, BYTE CanIgnore)
{
if (CurrentStep < -1) CurrentStep = -1;
if (CurrentStep < MaxSteps - 1) {
++CurrentStep;
if (CurrentStep == 0) HasStepError = 0;
StepReturnValues[CurrentStep][0] = f;
StepReturnValues[CurrentStep][1] = -1;
StepReturnValues[CurrentStep][2] = -1;
StepReturnValues[CurrentStep][3] = CanIgnore;
}
return CurrentStep;
}
void Epd3Base::Epd3U::SetCommitReturnValue(int step, int32_t rv)
{
if (CurrentStep >= 0 && CurrentStep < MaxSteps)
StepReturnValues[step][1] = rv;
}
void Epd3Base::Epd3U::SetCommitReturnValue(int32_t rv)
{
SetCommitReturnValue(CurrentStep, rv);
}
uint32_t Epd3Base::Epd3U::SetEndReturnValue(int step, int32_t rv)
{
if (step >= 0 && step < MaxSteps) {
StepReturnValues[step][2] = rv;
if (rv != 0) {
HasStepError = 1;
if (StepReturnValues[step][3]) rv = 0; //if canIngore set rv ok
Error = GetErrorCode();
}
}
return rv;
}
uint32_t Epd3Base::Epd3U::SetEndReturnValue(int32_t rv)
{
return SetEndReturnValue(CurrentStep, rv);
}
int32_t Epd3Base::Epd3U::CommitAndSetRV()
{
int32_t r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
return r;
}
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;
}
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);
r= SetEndReturnValue(r);
return r;
}
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;
}
void WINAPI completion(CommsHandle hComms, CompletionToken token)
{
SetEvent(current->hCompletion);
}
void WINAPI discovery(CommsHandle hComms, DiscoveryId const discovered[], int32_t count)
{
if (count > 0 && discovered != nullptr)
{
memcpy(&current->Epd, &discovered[0], sizeof(DiscoveryId));
current->CurrentDeviceID = discovered[0].Id;
current->DeviceCount = count;
current->isMK3 = (current->Epd.Gen == EpdGeneration::Mk3);
current->EpdID = current->Epd.Id;
}
else {
current->EpdID = 0;
current->CurrentDeviceID = 0;
current->DeviceCount = 0;
}
SetEvent(current->hCompletion);
}
void WINAPI connectcallback(CommsHandle hComms, DiscoveryId ID)
{
current->isConnected = 1;
current->CurrentDeviceID = ID.Id;
current->DeviceCount = 1;
}
void WINAPI disconnectcallback(CommsHandle hComms, DiscoveryId ID)
{
OutputDebugStringA("**** Disconnectb ****\n");
current->isConnected = 0;
current->CurrentDeviceID = 0;
current->DeviceCount = 0;
SetEvent(current->hCompletion);
}
Epd3Base::Epd3U::Epd3U(int _comport)
{
port = _comport;
comPort[3] = 48 + _comport;
CommsInitialized = 0;
epdComsHandle = nullptr;
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;
EPDFaulty = false;
EPDTimeFault = 0;
hasAlarm = hasFault = 0;
ErrorSource = ErrorReason = ErrorData = 0;
HardVersion = HardVersionMinor = SoftVersion = FunctionFlags = 0;
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);
if (hCancel == 0) hCancel = CreateEvent(NULL, TRUE, FALSE, NULL);
}
Epd3Base::Epd3U::~Epd3U()
{
EndCom(isConnected);
if (hCompletion != 0) { CloseHandle(hCompletion); hCompletion = 0; }
if (hCancel != 0) { CloseHandle(hCancel); hCancel = 0; }
//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);
DebugWrite( "**** DisconnectAndConnect rv=%d tries %d ****\n", rv, tries);
Sleep(100);
}
return rv;
}
void Epd3Base::Epd3U::Cancel()
{
SetEvent(current->hCancel);
}
DWORD Epd3Base::Epd3U::StartCom()
{
ErrorReason = 0;
ConnectRetries = 0;
OpenRetries = 0;
int step = 1;
int mx = 10;
epdComsHandle = nullptr;
if (port == 0) {
CommsInitialized = 1;
return 1;
}
if (CommsInitialized == 0 || epdComsHandle == nullptr) {
step = 2;
SetFunctionReturnValue(fCreateReaderInterface, 0);
epdComsHandle = CreateReaderInterface();
if (!epdComsHandle ) step = 3;
while (epdComsHandle == nullptr && ++ConnectRetries < 4) {
Sleep(200);
epdComsHandle = CreateReaderInterface(); //try again;
}
SetCommitReturnValue(0);
if (epdComsHandle) SetEndReturnValue(0); else SetEndReturnValue(-1);
if (epdComsHandle != nullptr) {
step = 4;
SetFunctionReturnValue(fOpenReader, 0);
Dll3RV = OpenReader(epdComsHandle, comPort); //-6 = r_OperationFailed
if (Dll3RV) step = 5;
while (Dll3RV && ++OpenRetries < 4 ) { //retry
Sleep(200);
Dll3RV = OpenReader(epdComsHandle, comPort);
}
SetCommitReturnValue(0);
if (!Dll3RV) SetEndReturnValue(0); else SetEndReturnValue(-1);
if (Dll3RV == 0)
{
step = 7;
CommsInitialized = 1;
Dll3RV = SetMultipleDiscoveryMode(epdComsHandle, false);
Dll3RV = SetResponseTimeout(epdComsHandle, ResponseTimeout);
}
}
else {
Dll3RV = r_FunctionFail;
}
}
if (Dll3RV) goto error;
return Dll3RV;
error:
ErrorStep = step;
Error = Dll3RV;
return Dll3RV;
}
void Epd3Base::Epd3U::EndCom(bool doDiscon)
{
int rv;
if (CommsInitialized == 1 || CurrentDeviceID != 0) {
if (CommsInitialized == 1) {
DebugWrite( "**** EndCom(%d) is Connected=%d ****\n", doDiscon, isConnected);
if (epdComsHandle != nullptr) {
if (doDiscon && isConnected) { DisCon(0); }
//Dll3RV = CloseReader(epdComsHandle); // not necessary if followed by DestroyReaderInterface
//if (Dll3RV) {
// rv = 1;
//}
SetFunctionReturnValue(eFunctions::fDestroyReaderInterface,0);
Dll3RV = DestroyReaderInterface(epdComsHandle);
SetCommitReturnValue(0);
SetEndReturnValue(Dll3RV);
if (Dll3RV) rv = 1;
}
}
Epd.Id = 0;
CurrentDeviceID = 0;
CommsInitialized = 0;
epdComsHandle = nullptr;
}
}
/// <summary>
///
/// </summary>
/// <param name="tokentimeout"></param>
/// <returns>rv=1 ,ook bij timeout <>1 voor error</returns>
int Epd3Base::Epd3U::StartDiscover(int tokentimeout)
{
ResetEvent(current->hCancel);
EPDStep = EPDStepStartDiscover;
DiscoverStep = 0;
DiscoverError = DiscoverErrorNone;
int32_t rv = 1;
int32_t rv2 = 0;
Error = 0;
if (port == 0) {
DeviceCount = 1;
isBG = 1;
DeviceIDs[0] = 768;
return 0;
}
Dll3RV = SetConnectCallback(epdComsHandle, connectcallback);
Dll3RV = SetDisconnectCallback(epdComsHandle, disconnectcallback);
current = this;
//Dll3RV = SetDiscoveryCacheTimeout(epdComsHandle, tokentimeout);
DeviceCount = 0;
ResetEvent(hCompletion);
ConnectTimerFired = 0;
isConnected = 0;
DiscoverStep = 1;
Dll3RV = StartDiscovery(epdComsHandle, discovery);
if (Dll3RV == 0) {
HANDLE handles[2];
handles[0] = hCompletion; // Index 0: Completion event
handles[1] = hCancel;
Dll3RV = WaitForMultipleObjects(2, handles, false , tokentimeout);
if (Dll3RV == WAIT_OBJECT_0)
rv = 1; //ok was set
else if (Dll3RV == WAIT_OBJECT_0+1) {
DiscoverError = DiscoverErrorCancel;
rv = 1; //cancel
rv2 = StopDiscovery(epdComsHandle);
}
else if (Dll3RV == WAIT_TIMEOUT) {
rv = 1;
ConnectTimerFired = 1;
DiscoverError = DiscoverErrorTimeout;
rv2 = StopDiscovery(epdComsHandle);
}
else {
rv = 2;
DiscoverError = DiscoverErrorOther;
rv2 = StopDiscovery(epdComsHandle);
}
}
if (DiscoverError == DiscoverErrorNone && DeviceCount > 0 && Epd.Id >0) {
Dll3RV = Connect3(epdComsHandle, Epd, true);
if (Dll3RV != 0) {
DiscoverError = DiscoverErrorConnecting;
rv = 2;
} else
EPDStep = EPDStepConnected;
}
return rv;
}
int Epd3Base::Epd3U::OpenDev(DiscoveryId DeviceID)
{
CurrentDeviceID = DeviceID.Id;
if (epdComsHandle != nullptr)
{
Dll3RV = Connect3(epdComsHandle, DeviceID, true);
SetDisconnectCallback(epdComsHandle, disconnectcallback);
OutputDebugStringA("**** Connect EPD ****\n");
}
else { Dll3RV = r_InvalidCommsHandle; }
return Dll3RV;
}
int Epd3Base::Epd3U::ReOpenDev()
{
if (epdComsHandle != nullptr)
{
//SetDisconnectCallback(epdComsHandle, disconnectcallback);
Dll3RV = Connect3(epdComsHandle, Epd, true);
OutputDebugStringA("**** ReOpen ****\n");
}
else {
OutputDebugStringA("**** ReOpen no epdComsHandle ****\n");
Dll3RV = r_InvalidCommsHandle;
} //no handle ..
return Dll3RV;
}
//
int Epd3Base::Epd3U::DisCon(UINT16 alarm)
{
// 5432109876543210
constexpr UINT16 ca = 0b1001110011000111;
int rv = 0;
int step = 0;
DebugWrite( "**** Discon(%hu) ****\n", alarm);
if (CurrentDeviceID != 0) {
ResetEvent(hCompletion);
current = this;
step = 1;
Dll3RV = SetDisconnectCallback(epdComsHandle, disconnectcallback);
if (alarm) {
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);
}
SetFunctionReturnValue(fDisconnectAndNotify,0);
Dll3RV = DisconnectAndNotify(epdComsHandle, ca, 12); //1.2 secon
SetCommitReturnValue(0); SetEndReturnValue(Dll3RV);
Sleep(1200);
} else {
SetFunctionReturnValue(fDisconnect,0);
Dll3RV = Disconnect(epdComsHandle);
SetCommitReturnValue(0); SetEndReturnValue(Dll3RV);
}
if (Dll3RV) { rv = Dll3RV; goto error; }
step = 2;
Dll3RV = WaitForSingleObject(hCompletion, 3000);
switch (Dll3RV) {
case WAIT_OBJECT_0:
rv = 0; break;
case WAIT_TIMEOUT:
rv = 0;
current->CurrentDeviceID = 0;
current->DeviceCount = 0;
break;
default: rv = 3; break;
}
}
return rv;
error:
return rv;
}
void Epd3Base::Epd3U::CloseDev(bool CloseAll)
{
if (epdComsHandle != nullptr) {
DisCon(0);
if (CloseAll) {
//CloseReader(epdComsHandle);
DestroyReaderInterface(epdComsHandle);
epdComsHandle = nullptr;
}
}
}
BYTE checkStatus(OpStatusFlags status, OpStatusFlags flag)
{
if (((uint32_t)status & (uint32_t)flag) == (uint32_t)flag) return 1; else return 0;
}
BYTE checkStatus(FaultStatusFlags status, FaultStatusFlags flag)
{
if (((uint32_t)status & (uint32_t)flag) == (uint32_t)flag) return 1; else return 0;
}
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;
}
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()
{
if (StatusDecoded) {
return;
}
eDosDose07Warning = eDosDose07Alarm = eDosDose10Warning = eDosDose10Alarm = eDosRate07Warning = eDosRate07Alarm = eDosRate10Warning = eDosRate10Alarm = eDosBatteryWarning = eDosDoseAlarm = eDosRateAlarm = 0;
AlarmDoseHP07N = AlarmRateHP07N = AlarmDoseHP101G = AlarmDoseHP102G = AlarmRateHP101G = AlarmRateHP102G= 0;
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);
EPDFaulty = checkStatus(epd3status.FaultStatus, FaultStatusFlags::EpdFaulty);
EPDNewFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::ErrorLogged);
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);
EPDTimeFault = checkStatus(epd3status.FaultStatus, FaultStatusFlags::TimeInvalid);
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);
eDosRate07Warning = checkStatus(status, DoseAlarmFlags::RateWarning);// | checkStatus(status, DoseAlarmFlags::LatchedRateWarning);
eDosRate07Alarm = checkStatus(status, DoseAlarmFlags::RateAlarm) ; // checkStatus(status, DoseAlarmFlags::LatchedRateAlarm)
AlarmDoseHP07N = checkStatus(status, DoseAlarmFlags::DoseAlarm);
AlarmRateHP07N = checkStatus(status, DoseAlarmFlags::RateAlarm);; // | checkStatus(status, DoseAlarmFlags::LatchedRateAlarm);
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;
}
}
OtherAlarmReturn = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::ReturnForRead);
OtherAlarmBatLow = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::LowBattery);
OtherAlarmCarrier = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::TelemetryAlert);
OtherAlarmBatVolt = checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::LowBattery);
eDosDoseAlarm = (eDosDose10Alarm || eDosDose07Alarm) && checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::DoseAlarm);
eDosRateAlarm = (eDosRate07Alarm || eDosRate10Alarm) && checkStatus(epd3status.AlarmStatus, AlarmStatusFlags::RateAlarm);
hasAlarm = eDosDoseAlarm || eDosRateAlarm;
hasFault = ((uint32_t)epd3status.FaultStatus & ~(uint32_t)FaultStatusFlags::ErrorLogged) != 0;
eDosBatteryWarning = OtherAlarmBatLow | OtherAlarmBatVolt;
StatusDecoded = true;
}
int Epd3Base::Epd3U::SetTime() //Only R3
{
int r = 0;
if (Epd.Gen == EpdGeneration::Mk3)
{
SetFunctionReturnValue(WriteRTC_R3,1);
utc = TimeFunctions::NowToEpd3Time();
token = BeginWriteRTC_R3(epdComsHandle, utc, nullptr);
r = CommitAndEnd2RV(EndWriteRTC_R3, token);
}
return r;
}
void WINAPI ReadStatusCompletion(CommsHandle hComms, CompletionToken token)
{
int rv = EndReadStatus(current->epdComsHandle, token, &current->epd3status);
rv = current->SetEndReturnValue(rv);
current->StatusDecoded = false;
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...
DebugWrite("**** ReadStatusCompletion %04x ****\n", current->OperatingStatus);
SetEvent(current->hCompletion);
}
int Epd3Base::Epd3U::ReadStatusOnly()
{
int rv = 0;
ResetEvent(hCompletion);
SetFunctionReturnValue(eFunctions::ReadStatus, 0);
current->StatusDecoded = false;
token = BeginReadStatus(epdComsHandle, ReadStatusCompletion);
rv = CommitAndSetRV();
return rv;
}
/// <summary>
///
/// </summary>
/// <returns>0 = ok</returns>
int Epd3Base::Epd3U::ReadStatus(bool onlyStatus)
{
int rv; //0=ok
//constexpr int maxbatch = 2;
//int batchstep;
//int s[maxbatch];
//int r[maxbatch];
int step = 0;
uint8_t length = 0;
countsRead = 0; utc = 0; seconds = 0;
memset(WearerID, 0, WearerIDLength + 1);
memset(WearerName, 0, WearerNameLength + 1);
rv = SetResponseTimeout(epdComsHandle, ResponseTimeout);
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;
HardVersion = HardVersionMinor = SoftVersion = FunctionFlags = 0;
memset(&epd3status, 0, sizeof(StatusData_t));
int rv2;
/*step = 1;
SetFunctionReturnValue(eFunctions::EpdOnOff, 0);
token = BeginEpdOnOff(epdComsHandle, 1, nullptr);
rv = CommitAndEnd2RV(EndEpdOnOff, token);*/
step = 2;
SetFunctionReturnValue(eFunctions::ReadStatus,0);
token = BeginReadStatus(epdComsHandle, nullptr);
rv2 = CommitAndSetRV();
//batchstep = 0; //ReadStatus
//r = Commit3(epdComsHandle); SetCommitReturnValue(r);
if (!rv)
rv = EndReadStatus(epdComsHandle, token, &epd3status);
rv2 = SetEndReturnValue(rv);
current->StatusDecoded = false;
if (rv != 0)
goto error;
IssueCount = epd3status.IssueCount;
OperatingStatus = epd3status.OperatingStatus;
AlarmStatus = epd3status.AlarmStatus;
ErrorStatus = epd3status.FaultStatus;
OtherAlarms = epd3status.OtherBits;
DecodeStatus(); //Alarm status...
if (onlyStatus) goto exitroutine;
uint32_t EpdID32 ;
uint32_t capabilities;
MarkNumber_t MarkNumber;
VersionNumber_t VersionNumber;
step = 3;
//batchstep = 1; //ReadEpdIdentities
EpdID32 = 0;
MarkNumber.Major = 0;
MarkNumber.Minor=0;
VersionNumber.Major = 0;
SetFunctionReturnValue(ReadEpdIdentities,0);
token = BeginReadEpdIdentities(epdComsHandle, nullptr);
rv = CommitAndSetRV();
if (!rv) rv = EndReadEpdIdentities(epdComsHandle, token, &EpdID32, (EpdTypes*)&EpdType, &capabilities, &MarkNumber, &VersionNumber, NULL, 0);
rv = SetEndReturnValue(rv);
if (rv != 0) goto error;
EpdID = EpdID32;
isBG = (EpdType == EpdTypes::Mk2BetaGamma) || (EpdType == EpdTypes::Mk3BetaGamma);
isNG = (EpdType == EpdTypes::Mk2Neutron) || (EpdType == EpdTypes::Mk3Neutron);
HardVersion = MarkNumber.Major;
HardVersionMinor = MarkNumber.Minor;
SoftVersion = VersionNumber.Major;
VersionOK = true;
step = 4;
SetFunctionReturnValue(ReadCounts,0);
token = BeginReadCounts(epdComsHandle, nullptr, 0, nullptr);
rv = CommitAndSetRV();
if (!rv) rv = EndReadCounts(epdComsHandle, token, Counts, MaxCounts, &countsRead, &utc, &seconds);
rv2= SetEndReturnValue(rv);
if (rv)
goto error;
decodeCounters(countsRead); //HG,SG ..
//Times
//1601-01-01T00:00:00Z.
//MK2 .. some utc... but no real time clock
step = 6;
//batchstep = 3;
if (utc == 0) {
SetFunctionReturnValue(ReadRTC,0);
token = BeginReadRTC(epdComsHandle, nullptr);
rv = CommitAndSetRV();
if (!rv)
rv = EndReadRTC(epdComsHandle, token, &utc); //EpdClock for MK2
rv2= SetEndReturnValue(rv);
if (rv)
goto error;
EpdClock = utc;
utc = TimeFunctions::NowToEpd3Time();
}
else {
EpdClock = utc;
}
FILETIME fUTC;
TimeFunctions::Epd3TimeToFileTime(utc, &fUTC);
FileTimeToSystemTime(&fUTC, &tRealTime);
step = 5;
if (EPDIssued) {
IdString_t mk3WearerID;
mk3WearerID.Length = 0;
//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:
return rv;
error:
//Cancel(epdComsHandle);
Error = rv;
ErrorStep = step;
return rv;
}
/// <summary>
/// discover, connect and read status
/// </summary>
/// <param name="tokenSourceTimeout"></param>
/// <returns>0=success 1=connect error, 2 = time out , no devices, 3= error reading status</returns>
int Epd3Base::Epd3U::ConnectAndStatus(int tokenSourceTimeout)
{
WORD dllStatus;
int rv = 1;
EPDStep = EPDConnectAndStatus;
Error = 0; ErrorStep = 0; hasAlarm = hasFault = 0;
ResetStepReturnValues();
if (CommsInitialized == 0) StartCom();
if (CommsInitialized) {
SetFunctionReturnValue(fStartDiscover,0);
dllStatus = StartDiscover(tokenSourceTimeout);
SetCommitReturnValue(0);
if (dllStatus==1) SetEndReturnValue(0); else SetEndReturnValue(dllStatus);
if (dllStatus != 1) rv = 1; //Connect error
else if (DeviceCount < 1) {
rv = 2;
Error = r_OperationTimeout;
}
else if (isMK3 && ReadStatus(false) != 0) rv = 3; //Read Error
else rv = 0;
}
else rv = 1;
return rv;
}
/// <summary>
/// K1 = K2 = K3 = K4 = K4 = K6 (*100000 )
/// </summary>
/// <param name="count"></param>
void Epd3Base::Epd3U::decodeSensitivities(int count) {
// Neutron
// An1Sens10N = 14,
// Fn1Sens10N = 15,
// Fn2Sens10N = 16,
//float Kx = 0;
K1 = K2 = K3 = K4 = K4 = K6 = 0.0F;
//SensitivityId sid = SensitivityId::Hg1Sens10G;
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;
case SensitivityId::An1Sens10N:
K4 = sensitivities[ix].value * 100000; break;
case SensitivityId::Fn1Sens10N:
K3 = sensitivities[ix].value * 100000; break;
default:
// sid = (SensitivityId)sensitivities[ix].id;
//Kx = sensitivities[ix].value * 100000;
break;
}
}
}
void Epd3Base::Epd3U::decodeGains(int count) {
// Neutron
// An1Sens10N = 14,
// Fn1Sens10N = 15,
// Fn2Sens10N = 16,
//float Kx = 0;
GainAn = GainFn = 0.0F;
//SensitivityId sid = SensitivityId::Hg1Sens10G;
for (int ix = count - 1; ix >= 0; ix--) {
switch ((SensitivityId)gains[ix].id)
{
case SensitivityId::An1Sens10N:
GainAn = gains[ix].value ; break;
case SensitivityId::Fn1Sens10N:
GainFn = gains[ix].value ; 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::Epd3TimeToFileTime(Hp07Time, (LPFILETIME)&Hp07FTime);
//FileTimeToSystemTime(&Hp07FTime, &st07);
break;
case MeasurementId::Meas_Hp10:
case MeasurementId::Meas_Hp10G:
Hp10Peak = peakRates[ix].value;
Hp10Time = peakRates[ix].timestamp;
TimeFunctions::Epd3TimeToFileTime(Hp10Time, (LPFILETIME)&Hp10FTime);
//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
default:
break;
}
}
}
/// <summary>
/// Read K1 = K2 = K3 = K4 = K4 = K6
/// </summary>
/// <returns></returns>
WORD Epd3Base::Epd3U::ReadCal()
{
int r = 0, r2=0;
Error = 0;
SetFunctionReturnValue(ReadSensitivities,0);
token = BeginReadSensitivities(epdComsHandle, nullptr, 0, nullptr);
r2 = CommitAndSetRV();
//r = Commit3(epdComsHandle); SetCommitReturnValue(r);
r = EndReadSensitivities(epdComsHandle, token, sensitivities, MaxSensitivities, &numSensitivities);
r = SetEndReturnValue(r);
if (r != 0)
goto error;
decodeSensitivities(numSensitivities);
SetFunctionReturnValue(ReadGains, 0);
token = BeginReadGains(epdComsHandle, nullptr, 0, nullptr);
r2 = CommitAndSetRV();
//r = Commit3(epdComsHandle); SetCommitReturnValue(r);
r = EndReadGains(epdComsHandle, token, gains, MaxGains, &numGains);
decodeGains(numGains); //GainAn en GainFn
r = SetEndReturnValue(r);
if (r != 0)
goto error;
return r;
error:
Error = r;
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 {
SetFunctionReturnValue(ReadDetectorThresholds,0);
token = BeginReadDetectorThresholds_R3(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
r = EndReadDetectorThresholds_R3(epdComsHandle, token, dTresholds, MaxTresholds, &numTresholds);
r = SetEndReturnValue(r);
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;
return r_OK;
}
numDoses = 0; utc = 0;
SetFunctionReturnValue(eFunctions::fReadDoses,0);
token = BeginReadDoses(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
if (!r) r = EndReadDoses(epdComsHandle, token, doses, MaxDoses, &numDoses, &utc);
r = SetEndReturnValue(r);
if (r != 0)
goto error;
decodeDoses(numDoses);
SetFunctionReturnValue(eFunctions::ReadTotalDoses,0);
token = BeginReadTotalDoses(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
if (!r) r = EndReadTotalDoses(epdComsHandle, token, totdoses, MaxDoses, &numtotDoses, &utc);
r = SetEndReturnValue(r);
if (r != 0)
goto error;
decodetotDoses(numtotDoses);
SetFunctionReturnValue(eFunctions::ReadQualityData,0);
token = BeginReadQualityData(epdComsHandle, nullptr);
r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
if (!r) r = EndReadQualityData(epdComsHandle, token, &quality);
r = SetEndReturnValue(r);
if (r != 0)
goto error;
Knocks = quality.Knocks;
Resets = quality.PowerCycles;
SetFunctionReturnValue(eFunctions::ReadPeakRates,0);
token = BeginReadPeakRates(epdComsHandle, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
if (!r) r = EndReadPeakRates(epdComsHandle, token, peakRates, MaxPeakRates, &numRates);
r= SetEndReturnValue(r);
if (r != 0)
goto error;
decodePeakRates(numRates);
r = ReadSensitivitiesAndTresholds(); //K1 .. K6, SG , BC ,FB , HG
if (r != 0)
goto error;
return r;
error:
Error = r;
return r;
}
/// <summary>
///
/// </summary>
/// <returns>0 success</returns>
int Epd3Base::Epd3U::ClearDoses()
{
//constexpr int maxbatch = 3;
int rv;
//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;
//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:
Error = rv;
return rv;
}
int Epd3Base::Epd3U::ClearAlarms()
{
constexpr int maxbatch = 2;
int rv;
int r[maxbatch];
int s[maxbatch];
int batchstep = 0;
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;
}
WORD Epd3Base::Epd3U::PrepareForIssue()
{
int rv = 0;
int step = 0;
if (port == 0) return 0;
/*if (DetectorsOn) {
token = BeginEpdOnOff(epdComsHandle, 0, nullptr);
rv = Commit3(epdComsHandle);
if (!rv) rv = EndEpdOnOff(epdComsHandle, token);
rv = ReOpenDev();
}
if (rv != 0)
goto error;*/
/* gebeurt bij clearalrms
SetFunctionReturnValue(eFunctions::ClearLatchedAlarms,0);
token = BeginEpdOnOff(epdComsHandle, 1, nullptr);
rv = CommitAndEnd2RV(EndEpdOnOff, token);
*/
step = 2;
if (WriteConfig32) {
rv = WriteConfig();
if (rv != 0)
goto error;
}
step = 3;
if (!isConnected)
rv = ReOpenDev();
step = 5;
rv = ClearAlarms();
if (rv != 0)
goto error;
step = 4;
rv = ClearDoses();
if (rv != 0)
goto error;
OutputDebugStringA("**** After clear ****\n");
Disconnect(epdComsHandle);
Sleep(SleepAfterClear);
return rv;
error:
DebugWrite("**** After clear step %d error %d ****\n", step, rv);
ErrorStep = step;
Error = rv;
return rv;
}
WORD Epd3Base::Epd3U::ReadAlarmConfig() {
//Alleen MK3 ? leeg bij MK2
SetFunctionReturnValue(eFunctions::ReadAlarmConfiguration,0);
token = BeginReadAlarmConfiguration(epdComsHandle, nullptr, 0, nullptr);
int32_t r = CommitAndSetRV();
if (!r) { r = EndReadAlarmConfiguration(epdComsHandle, token, alarmConfig, MaxAlarmConfig, &numAlarm); SetEndReturnValue(r); }
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;
SetResponseTimeout(epdComsHandle, ResponseTimeout);
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10N; else measID = (uint8_t)MeasurementId::Meas_Hp07;
hp07tresholds.MeasId = measID;
SetFunctionReturnValue(eFunctions::ReadAlarmThresholds,0);
token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)hp07tresholds.MeasId, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
if (!r) { r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds); r = SetEndReturnValue(r); }
decodeTreshold(&hp07tresholds);
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10G; else measID = (uint8_t)MeasurementId::Meas_Hp10;
hp10tresholds.MeasId = measID;
SetFunctionReturnValue(eFunctions::ReadAlarmThresholds,0);
token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, nullptr, 0, nullptr);
r = Commit3(epdComsHandle);
SetCommitReturnValue(r);
if (!r) { r = EndReadAlarmThresholds(epdComsHandle, token, &hp10tresholds); r= SetEndReturnValue(r); }
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);
SetFunctionReturnValue(eFunctions::WriteAlarmThresholds,0);
token = BeginWriteAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, (uint8_t)hp10tresholds.NumberThresholds, hp10tresholds.Thresholds, nullptr);
r = CommitAndEnd2RV(EndWriteAlarmThresholds, token);
if (r != 0)
goto error;
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10N; else measID = (uint8_t)MeasurementId::Meas_Hp07;
hp07tresholds.MeasId = measID;
encodeTreshold(&hp07tresholds);
hp07tresholds.NumberThresholds = 4;
SetFunctionReturnValue(eFunctions::WriteAlarmThresholds,0);
token = BeginWriteAlarmThresholds(epdComsHandle, (uint8_t)hp07tresholds.MeasId, (uint8_t)hp07tresholds.NumberThresholds, hp07tresholds.Thresholds, nullptr);
r = CommitAndEnd2RV(EndWriteAlarmThresholds, token);
if (r != 0)
goto error;
SetFunctionReturnValue(eFunctions::WriteRateOffPercentage,0);
token = BeginWriteRateOffPercentage(epdComsHandle, RatePct, 2, nullptr);
r = CommitAndEnd2RV(EndWriteRateOffPercentage, token);
if (r != 0)
goto error;
return r;
error:
return r;
}
WORD Epd3Base::Epd3U::DeIssue()
{
int r = 1;
if (port == 0) return 0;
if (CurrentDeviceID == 0) return 0;
if (EPDIssued)
{
#if DeissueWithClear
ErrorStep = 2;
r = ClearDoses();
ErrorStep = 1;
r = ClearAlarms();
//needed after clear alarms
Sleep(2000);
#endif
SetFunctionReturnValue(eFunctions::DeissueEPD, 0);
token = BeginDeissueEPD(epdComsHandle, nullptr);
r = CommitAndEnd2RV(EndDeissueEPD, token);
Sleep(100);
}
SetFunctionReturnValue(eFunctions::EpdOnOff,0);
token = BeginEpdOnOff(epdComsHandle, 0, nullptr);
r = CommitAndEnd2RV(EndEpdOnOff, token);
Sleep(100);
if (r) goto error;
return r;
error:
Error = r;
return r;
}
WORD Epd3Base::Epd3U::WriteWearer() {
int32_t r = 0;
int step = 0;
SetFunctionReturnValue(eFunctions::SetBaselineCounters,0);
token = BeginSetBaselineCounters(epdComsHandle, nullptr);
r = CommitAndEnd2RV(EndSetBaselineCounters, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndSetBaselineCounters(epdComsHandle, token); SetEndReturnValue(r);
if (r != 0)
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);
SetFunctionReturnValue(eFunctions::WriteWearerId,0);
token = BeginWriteWearerId(epdComsHandle, mk3WearerID, nullptr);
r = CommitAndEnd2RV(EndWriteWearerId, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndWriteWearerId(epdComsHandle, token); SetEndReturnValue(r);
if (r != 0)
goto error;
mk3WearerID.IdType = (uint16_t)WearerIdType::WearerId_Primary;
mk3WearerID.Length = 13;
memcpy(mk3WearerID.Utf8String, WearerID, 13);
SetFunctionReturnValue(eFunctions::WriteWearerId,0);
token = BeginWriteWearerId(epdComsHandle, mk3WearerID, nullptr);
r = CommitAndEnd2RV(EndWriteWearerId, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndWriteWearerId(epdComsHandle, token); SetEndReturnValue(r);
if (r != 0)
goto error;
return r;
error:
Error = r;
return r;
}
/// <summary>
///
/// </summary>
/// <returns>0 Success</returns>
WORD Epd3Base::Epd3U::Issue(bool PrepareDone) //normaal is preparedone=tru
{
int r = 0;
int step = 0;
int tries = 0;
UINT16 Control = 0;
if (port == 0) return r;
r = 0;
if (!PrepareDone) {
r = PrepareForIssue();
if (r)
goto error;
}
step = 1;
if (!isConnected) r = ReOpenDev();
if (r)
goto error;
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
step = 2;
r = WriteAlarmTresholds();
if (r != 0)
goto error;
step = 3;
if (!isConnected)
ReOpenDev();
step = 4;
r = WriteWearer();
if (r != 0)
goto error;
tries = 1;
SetFunctionReturnValue(eFunctions::IssueEPD,0);
token = BeginIssueEPD(epdComsHandle, nullptr);
r = CommitAndEnd2RV(EndIssueEPD, token);
if (r != 0) {
tries++;
if (r == r_ErrorNotConnected) ReOpenDev();
Sleep(500);
SetFunctionReturnValue(eFunctions::IssueEPD,0);
token = BeginIssueEPD(epdComsHandle, nullptr);
r = CommitAndEnd2RV(EndIssueEPD, token);
}
if (r)
goto error;
EPDIssued = 1;
step = 6;
if (isMK3) {
r = DisCon(Control); //stops protected session if control is EndSessionCOntrol
}
step = 7;
return r;
error:
ErrorStep = step;
Error = r;
return r;
}
WORD Epd3Base::Epd3U::EPDReadExtraStatus()
{
if (port == 0) return 1;
uint32_t r;
//byBatADC = bySupplyADC = 0;
/*CommitRV = ReadA2ConfigStatus(
&byBatADC,
&bySupplyADC,
&byStatus3,
&byStatus4);
if (CommitRV == 1) CommitRV = Commit3();*/
SetFunctionReturnValue(eFunctions::ReadBaselineCounts,0);
token = BeginReadBaselineCounts(epdComsHandle, nullptr);
r = CommitAndSetRV();// Commit3(epdComsHandle); SetCommitReturnValue(r);
if (!r) r = EndReadBaselineCounts(epdComsHandle, token, Counts, 10, &utc, &countsRead);
r = SetEndReturnValue(r);
if (!r) decodeBaseCounters(countsRead);
//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;
}
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;
SetFunctionReturnValue(eFunctions::MfrLogin_R2,0);
token = BeginMfrLogin_R2(epdComsHandle, Password, nullptr);
uint32_t r = CommitAndEnd2RV(EndMfrLogin_R2,token);
//Commit3(epdComsHandle); SetCommitReturnValue(r); if (!r ) r = EndMfrLogin_R2(epdComsHandle, token); SetEndReturnValue(r);
if (r != 0)
goto error;
SetFunctionReturnValue(eFunctions::WriteSensitivities_R2,0);
token = BeginWriteSensitivities_R2(epdComsHandle, nullptr, (uint16_t)K1, (uint16_t)K2, (uint16_t)K3, (uint16_t)K4, (uint16_t)K5, (uint16_t)K6);
r = CommitAndEnd2RV(EndWriteSensitivities_R2, token);
//r = Commit3(epdComsHandle); SetCommitReturnValue(r); r = EndWriteSensitivities_R2(epdComsHandle, token); SetEndReturnValue(r);
if (r != 0)
goto error;
} else
if (EpdType == EpdTypes::Mk3Neutron)
{
//Password = 9;
//SetFunctionReturnValue(eFunctions::MfrLogin_R2, 0);
//token = BeginMfrLogin_R2(epdComsHandle, Password, nullptr);
//uint32_t r = CommitAndEnd2RV(EndMfrLogin_R2, token);
////Commit3(epdComsHandle); SetCommitReturnValue(r); if (!r ) r = EndMfrLogin_R2(epdComsHandle, token); SetEndReturnValue(r);
//if (r != 0)
// goto error;
SetFunctionReturnValue(eFunctions::WriteAccessLevelAdmin, 0);
token = BeginWriteAccessLevel(epdComsHandle, AccessLevel_t::Admin, EC, ECLen, nullptr);
r = CommitAndEnd2RV(EndWriteAccessLevel, token);
SetFunctionReturnValue(eFunctions::WriteGains_R3, 0);
numGains = 2;
gains[0].id = (uint16_t) SensitivityId::An1Sens10N; //K4
gains[0].value = GainAn;
gains[1].id = (uint16_t)SensitivityId::Fn1Sens10N; //K3
gains[1].value = GainFn;
token = BeginWriteGains(epdComsHandle, gains, numGains, nullptr);
r = CommitAndEnd2RV(EndWriteGains, token);
if (r != 0)
goto error;
}
return r;
error:
return r;
}
//main get dose function
//close com at end
int Epd3Base::Epd3U::GetAll(bool Closeconnection)
{
int rv = 0, step = 1;
rv = ReadDoses();
step=2;
if (!rv) rv = ReadAlarmTresholds();
if (Closeconnection) EndCom(isConnected );
return rv;
}
// Main entry point deissue for MK3
// close com at then
int Epd3Base::Epd3U::GetAllDeissue(bool reconnect)
{
int rv = 0;
int step = 0;
ResetStepReturnValues();
step = 1;
rv = ReadDoses(); //0 = success
if (rv) goto error;
//rv = ReadAlarmTresholds(); //0 = success
step = 2;
rv = EPDReadExtraStatus();
if (rv) goto error;
step = 3;
rv = DeIssue(); //does close
EndCom(isConnected);
if (rv) goto error;
return rv;
error:
Error = rv;
ErrorStep = step;
return rv;
}
// main issue routine
// cloise com at end
int Epd3Base::Epd3U::IssueAndCheck(float gain, float ChirpRate)
{
int rv = 0;
int step = 0;
DWORD wrv = 0;
int rv1 = -1, rv2 = -1;
OutputDebugStringW(L"**** IssueAndCheck start ****\n");
ResetStepReturnValues();
if (!isConnected) rv = ReOpenDev();
if (rv)
goto error;
step = 1;
OutputDebugStringW(L"**** IssueAndCheck step 1 settime ****\n");
rv = SetTime();
//synctime
OutputDebugStringW(L"**** Prepare IssueAndCheck ****\n");
step = 2;
rv = PrepareForIssue(); //Set epd on, clear doses and alarms
if (rv)
goto error;
if (!isConnected)
rv = ReOpenDev();
rv = ReadStatusOnly();
if (rv)
rv2=1;
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];
step = 3;
if (isNG) {
step = 1;
float kx = gain/100;
rv = ReadCal();
if (rv != 0 ) { //K6 test op 1310 || K6 != 1310 ??
rv = 1;
goto error;
}
//K3 = Fn1Sens10N K4 = An1Sens10N
if (GainAn != kx || GainFn!= kx)
{
step = 2;
GainAn=GainFn = kx;
rv = WriteCal();
if (rv != 0)
goto error;
}
}
step = 3;
if (!isConnected) rv = ReOpenDev();
rv = SetChirp(ChirpRate);
if (rv == r_ErrorNotConnected)
{
rv = ReOpenDev();
rv = SetChirp(ChirpRate);
}
if (rv)
goto error;
OutputDebugStringW(L"**** step 5 issue ****\n");
step = 5;
rv = Issue(true); // data already loaded
EndCom(isConnected);
if (rv)
goto error;
return rv;
error:
Error = rv;
ErrorStep = step;
return rv;
}
int Epd3Base::Epd3U::WriteConfig(void)
{
if (port == 0 || WriteConfig32 == 0) return 1;
int32_t r = 0;
ECLen = 32;
DebugWrite("**** WriteCfg v %d.%d ****\n", HardVersion, HardVersionMinor);
// Become admin
SetFunctionReturnValue(eFunctions::WriteAccessLevelAdmin,0);
token = BeginWriteAccessLevel(epdComsHandle, AccessLevel_t::Admin, EC, ECLen, nullptr);
r = CommitAndEnd2RV(EndWriteAccessLevel,token);
if (!r) {
displayIds = new QuickAccessDisplay_t[6]{
{ 0,0x0021 },
{ 1,0x0022 },
{ 2,0x0031 },
{ 3,0x0032 },
{ 4,0x0051 },
{ 5,0x0062 }
};
numDisplays = 6;
SetFunctionReturnValue(eFunctions::WriteQuickAccessDisplays_R3,1);
token = BeginWriteQuickAccessDisplays_R3(epdComsHandle, displayIds, numDisplays, nullptr);
r = CommitAndEnd2RV(EndWriteQuickAccessDisplays_R3, token);
if (r != 0)
Error = r;
}
if (!r) {
//Unmanaged%20HtmlFiles/_display_ids.html
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 }
};
}
// 0x1 Operation Menu Back /0x2 On / Off 0x4 Clear Dose 0x8 Toggle Telemtry 0x10 Responder Trigger
// 1 0 0 0 0
SetFunctionReturnValue(eFunctions::WriteDisplayEnables_R3,1);
token = BeginWriteDisplayEnables_R3(epdComsHandle, enables, numItems, nullptr);
r = CommitAndEnd2RV(EndWriteDisplayEnables_R3, token);
if (r != 0)
Error = r;
}
if (!r) {
uint8_t numMenus = 9;
uint16_t permissions[9] = {
0x0000 ,
0x0016 ,
0x0000 ,
0x0000 ,
0x0000 ,
0x0000 ,
0x0000 ,
0x0004 ,
0x0000
};
SetFunctionReturnValue(eFunctions::WriteDisplayEnablePermissions_R3,1);
token = BeginWriteDisplayEnablePermissions_R3(epdComsHandle, AccessLevel_t::Admin, permissions, numDisplays, nullptr);
r = CommitAndEnd2RV(EndWriteDisplayEnablePermissions_R3, token);
if (r != 0)
Error = r;
}
if (!r) {
//AlarmConfiguration
if (isBG) {
const uint8_t alarmConfigLen = 14;
alarmConfigIds = new AlarmConfig_t[alarmConfigLen]{
{ (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 },
{ (AlarmIds)7,0,0x0000,0x1884,60 },
{ (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 }
};
SetFunctionReturnValue(eFunctions::WriteAlarmConfiguration_R3, 1);
token = BeginWriteAlarmConfiguration_R3(epdComsHandle, alarmConfigIds, alarmConfigLen, nullptr);
r = CommitAndEnd2RV(EndWriteAlarmConfiguration_R3, token);
}
}
//constexpr int maxbatch= 2;
//int s[maxbatch];
//int rv[maxbatch];
//int batchstep;
if (!r) {
//OffModeDisplay
dutyCycle = (OffModeDutyCycle)0;
offModeDispId = (OffModeDisplayId_t)1;
SetFunctionReturnValue(eFunctions::WriteOffModeDisplay_R3,1);
token = BeginWriteOffModeDisplay_R3(epdComsHandle, dutyCycle, offModeDispId, nullptr);
r = CommitAndEnd2RV(EndWriteOffModeDisplay_R3, token);
if (r != 0)
Error = r;
uint8_t OnOfenabled = 0;
SetFunctionReturnValue(eFunctions::WriteSwitchOnFromButton_R3, 0);
token = BeginWriteSwitchOnFromButton_R3(epdComsHandle, OnOfenabled, nullptr);
r = CommitAndEnd2RV(EndWriteSwitchOnFromButton_R3, token);
if (r != 0)
Error = r;
SetFunctionReturnValue(eFunctions::WriteAccessLevelOpen, 0);
token = BeginWriteAccessLevel(epdComsHandle, AccessLevel_t::Open,nullptr,0, nullptr);
r = CommitAndEnd2RV(EndWriteAccessLevel, token);
if (r != 0)
Error = r;
Sleep(200);
r = DisconnectAndConnect();
if (r != 0)
Error = r;
Error = r;
}
else
Error = r;
return r;
}
int Epd3Base::Epd3U::SetChirp(float Sensitivity)
{
uint32_t r = 1;
uint8_t enable = 0;
if (Sensitivity > 0.001F) {
enable = 1;
SetFunctionReturnValue(eFunctions::WriteChirpSensitivity,0);
token = BeginWriteChirpSensitivity(epdComsHandle, Sensitivity, nullptr);
r = CommitAndEnd2RV(EndWriteChirpSensitivity , token);
}
if (r) goto error;
if (!r) {
SetFunctionReturnValue(eFunctions::WriteChirpEnable_R3,0);
token = BeginWriteChirpEnable_R3(epdComsHandle, enable, nullptr);
r = CommitAndEnd2RV(EndWriteChirpEnable_R3, token);
}
if (r) goto error;
return r;
error:
return r;
}