2019-02-04 11:48:08 +01:00
|
|
|
#include "stdafx.h"
|
2021-05-28 17:06:41 +02:00
|
|
|
#pragma unmanaged
|
2019-02-04 11:48:08 +01:00
|
|
|
#include "EpdBase.h"
|
2021-05-03 13:27:51 +02:00
|
|
|
#include "TimeFunctions.h"
|
2021-05-03 09:56:58 +02:00
|
|
|
#define DiscoveryTimeslotPeriod 500
|
2020-02-18 14:06:52 +01:00
|
|
|
#define DiscoveryExpirationPeriod 6000
|
|
|
|
|
#define RxRetryCount 5
|
|
|
|
|
#define TxRetryCount 5
|
2021-05-12 12:35:50 +02:00
|
|
|
#pragma unmanaged
|
2026-08-02 16:00:16 +02:00
|
|
|
|
|
|
|
|
void EpdBase::Epd2U::CancelAll()
|
|
|
|
|
{
|
|
|
|
|
SetEvent(hCancel);
|
|
|
|
|
//Cancel(epdComsHandle);
|
|
|
|
|
}
|
|
|
|
|
void EpdBase::Epd2U::test()
|
|
|
|
|
{
|
|
|
|
|
const char* msg = "Processing step test...";
|
|
|
|
|
if (progressCallback) {
|
|
|
|
|
progressCallback(StepTest, EPDStepResult); // Triggers the callback
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-04 11:48:08 +01:00
|
|
|
EpdBase::Epd2U::Epd2U(int comport)
|
|
|
|
|
{
|
|
|
|
|
port = comport;
|
2024-10-14 10:01:06 +02:00
|
|
|
CommsInitialized = 0;
|
2021-06-02 13:54:22 +02:00
|
|
|
isBG = isNG = VersionOK = hasAlarm = false;
|
2021-05-27 16:13:53 +02:00
|
|
|
maxDiscoverTime = 10000;
|
|
|
|
|
hWaitTimer = CreateWaitableTimer(NULL, TRUE, NULL);
|
2026-08-02 16:00:16 +02:00
|
|
|
hCancel = CreateWaitableTimer(NULL, TRUE, NULL);
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) return;
|
2019-02-04 11:48:08 +01:00
|
|
|
SetAutoCommit(0);
|
|
|
|
|
Error = 123;
|
|
|
|
|
//SetTimeouts(port, 20, 1000, 1000);
|
2019-02-25 09:12:08 +01:00
|
|
|
}
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD EpdBase::Epd2U::WriteConfig()
|
2020-03-11 13:23:29 +01:00
|
|
|
{
|
2024-05-16 15:56:07 +02:00
|
|
|
if (port == 0 ) return 1;
|
2020-03-11 13:23:29 +01:00
|
|
|
return WriteDisplayConfig(00,2,40,10, 2,displayConfig, 56);
|
|
|
|
|
}
|
2021-04-16 10:38:48 +02:00
|
|
|
DWORD EpdBase::Epd2U::StartCom()
|
2019-02-25 09:12:08 +01:00
|
|
|
{
|
2020-02-18 14:06:52 +01:00
|
|
|
DWORD rv;
|
|
|
|
|
ErrorReason = 0;
|
2025-12-04 06:35:41 +01:00
|
|
|
ErrorSource = 0;
|
2020-02-18 14:06:52 +01:00
|
|
|
int mx = 10;
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) {
|
|
|
|
|
CommsInitialized = 1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2022-04-08 15:41:46 +02:00
|
|
|
if (CommsInitialized == 0)
|
2020-02-18 14:06:52 +01:00
|
|
|
do {
|
2025-12-04 06:35:41 +01:00
|
|
|
mx--;
|
|
|
|
|
InitRv = InitComms(port, 9600, 8, 0, 0); //1=success
|
2020-02-18 14:06:52 +01:00
|
|
|
if (InitRv == 0) {
|
2022-04-08 15:41:46 +02:00
|
|
|
rv = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2025-12-04 06:35:41 +01:00
|
|
|
Sleep(400); //DeinitComms(port);
|
2020-02-18 14:06:52 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SetRetryCounts(RxRetryCount, TxRetryCount);
|
|
|
|
|
SetDiscoveryTimeslotPeriod(port, DiscoveryTimeslotPeriod);
|
2021-05-26 16:20:40 +02:00
|
|
|
SetDiscoveryTimeslotCount(port, 1);
|
2020-02-18 14:06:52 +01:00
|
|
|
SetDiscoveryExpirationPeriod(port, DiscoveryExpirationPeriod);
|
|
|
|
|
}
|
|
|
|
|
} while (InitRv == 0 && mx > 0);
|
2022-04-08 15:41:46 +02:00
|
|
|
|
|
|
|
|
if (InitRv == 0) { ErrorReason = 1; CommsInitialized = 0; }
|
|
|
|
|
else { ErrorReason = 0; CommsInitialized = 1; }
|
|
|
|
|
isBG = isNG = VersionOK = hasAlarm = false;
|
|
|
|
|
return ErrorReason;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-05-28 17:06:41 +02:00
|
|
|
void EpdBase::Epd2U::EndCom()
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2022-05-04 07:53:20 +02:00
|
|
|
if (port > 0 && CommsInitialized == 1) {
|
|
|
|
|
DeinitComms(port);
|
2025-12-04 06:35:41 +01:00
|
|
|
|
2022-05-04 07:53:20 +02:00
|
|
|
Sleep(300);
|
|
|
|
|
}
|
2020-02-18 14:06:52 +01:00
|
|
|
CommsInitialized = 0;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-05-28 17:06:41 +02:00
|
|
|
EpdBase::Epd2U::~Epd2U()
|
|
|
|
|
{
|
|
|
|
|
EndCom();
|
|
|
|
|
}
|
2026-08-02 16:00:16 +02:00
|
|
|
|
|
|
|
|
bool EpdBase::Epd2U::isCancelled()
|
|
|
|
|
{
|
|
|
|
|
return WaitForSingleObject(hCancel, 0) == WAIT_OBJECT_0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-05-04 07:53:20 +02:00
|
|
|
int EpdBase::Epd2U::StartDiscover( int EpdTimeoutms)
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2026-08-02 16:00:16 +02:00
|
|
|
ResetEvent(hCancel);
|
|
|
|
|
EPDStep = StepDiscovering;
|
|
|
|
|
|
2022-05-04 07:53:20 +02:00
|
|
|
maxDiscoverTime = EpdTimeoutms;
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) {
|
|
|
|
|
DeviceCount = 1;
|
|
|
|
|
DeviceIDs[0] = 768;
|
|
|
|
|
return 1;
|
2021-05-04 12:59:51 +02:00
|
|
|
}
|
|
|
|
|
DiscRV = 0;
|
2021-05-27 16:13:53 +02:00
|
|
|
ConnectTries = 0; ConnectTimerFired = 0;
|
2022-02-24 09:01:32 +01:00
|
|
|
if (CommsInitialized == 1 && hWaitTimer != nullptr) {
|
2021-05-12 12:35:50 +02:00
|
|
|
FlushDiscoveryCache(port);
|
|
|
|
|
FlushBuffers(port);
|
2022-02-24 09:01:32 +01:00
|
|
|
|
2021-05-27 16:13:53 +02:00
|
|
|
Error = 0;
|
2021-05-04 12:59:51 +02:00
|
|
|
int maxtries = 100; DeviceCount = 0; DiscRV = 1; DWORD wo = 1; // ongeveer 43 tries in 10 seconden
|
2022-02-24 09:01:32 +01:00
|
|
|
CancelWaitableTimer(hWaitTimer);
|
2021-05-27 16:13:53 +02:00
|
|
|
LARGE_INTEGER wt; //100 nanoseconds *10000 = millisec
|
|
|
|
|
//union { LARGE_INTEGER li; FILETIME ft; LONGLONG ll; } t1, t2;
|
|
|
|
|
//wt.QuadPart = -300000000LL;
|
2022-05-04 10:51:37 +02:00
|
|
|
INT64 t = maxDiscoverTime; t *= (INT64)-10000;
|
2022-05-04 07:53:20 +02:00
|
|
|
wt.QuadPart = t; // Int32x32To64(maxDiscoverTime, -10000); //15 seconden proberen
|
2022-02-24 09:01:32 +01:00
|
|
|
SetWaitableTimer(hWaitTimer, &wt, 0, NULL, NULL, 0);
|
2026-08-02 16:00:16 +02:00
|
|
|
while (DeviceCount == 0 && wo != 0 && !isCancelled()) //tries-- > 0 &&
|
2021-05-04 12:59:51 +02:00
|
|
|
{
|
2021-05-27 16:13:53 +02:00
|
|
|
ConnectTries++;
|
2021-05-04 12:59:51 +02:00
|
|
|
DiscRV = Discover(port, DeviceIDs, MaxDevices, &DeviceCount);
|
|
|
|
|
if (DiscRV == 0) {
|
|
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
}
|
2026-08-02 16:00:16 +02:00
|
|
|
else {
|
|
|
|
|
HANDLE handles[2];
|
|
|
|
|
handles[0] = hWaitTimer;
|
|
|
|
|
handles[1] = hCancel;
|
|
|
|
|
|
|
|
|
|
wo = WaitForMultipleObjects(2, handles, false, 100);
|
|
|
|
|
if (wo == 0) { ConnectTimerFired = 1; DiscRV = 1; EPDStepResult = EpdStepResults::OK; }
|
|
|
|
|
else if (wo == 1) { //Cancelled
|
|
|
|
|
DiscRV = 0; EPDStepResult = EpdStepResults::Error; }
|
|
|
|
|
else {
|
|
|
|
|
DiscRV = 0; EPDStepResult = EpdStepResults::Error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-18 14:06:52 +01:00
|
|
|
}
|
2021-05-27 16:13:53 +02:00
|
|
|
CancelWaitableTimer(hWaitTimer);
|
2026-08-02 16:00:16 +02:00
|
|
|
|
2020-02-05 16:27:38 +01:00
|
|
|
}
|
2026-08-02 16:00:16 +02:00
|
|
|
if (progressCallback) progressCallback(EPDStep, EPDStepResult);
|
2019-02-27 07:22:39 +01:00
|
|
|
return DiscRV;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-06-02 13:54:22 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="DeviceID"></param>
|
|
|
|
|
/// <returns>0 OK</returns>
|
2021-05-28 17:06:41 +02:00
|
|
|
int EpdBase::Epd2U::Open(DWORD DeviceID)
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2021-06-02 13:54:22 +02:00
|
|
|
int rv = 0;
|
2019-02-04 11:48:08 +01:00
|
|
|
CurrentDeviceID = DeviceID;
|
2022-04-08 15:41:46 +02:00
|
|
|
if (port > 0 && CommsInitialized==1) {
|
2021-03-26 17:20:57 +01:00
|
|
|
ConRV = Connect(DeviceID);
|
|
|
|
|
if (ConRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
else {
|
|
|
|
|
OpenRV = OpenDevice(port, CurrentDeviceID);
|
2021-06-02 13:54:22 +02:00
|
|
|
if (OpenRV == 0) rv=Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2021-03-26 17:20:57 +01:00
|
|
|
}
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-06-02 13:54:22 +02:00
|
|
|
else { OpenRV = ConRV = 1; rv = 0; }
|
|
|
|
|
return rv;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2024-10-14 07:51:22 +02:00
|
|
|
void EpdBase::Epd2U::Close(WORD doEndCom)
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2022-04-08 15:41:46 +02:00
|
|
|
if (port > 0 && CurrentDeviceID>0) CloseDevice();
|
2021-06-03 08:37:02 +02:00
|
|
|
CurrentDeviceID = 0;
|
2022-04-08 15:41:46 +02:00
|
|
|
FlushBuffers(port);
|
2024-10-14 07:51:22 +02:00
|
|
|
if (doEndCom) EndCom();
|
2021-06-03 08:37:02 +02:00
|
|
|
}
|
2024-10-14 07:51:22 +02:00
|
|
|
int EpdBase::Epd2U::CloseAndSignal(WORD EndSessionControl, WORD duration, WORD doEndCom)
|
2021-06-03 08:37:02 +02:00
|
|
|
{
|
|
|
|
|
int rv = 0;
|
|
|
|
|
WORD r;
|
|
|
|
|
Sleep(250);
|
|
|
|
|
r = EndSession(EndSessionControl, duration);
|
|
|
|
|
if (r == 1) rv = 0; else rv = 1;
|
2024-10-14 07:51:22 +02:00
|
|
|
Close( doEndCom);
|
2021-06-03 08:37:02 +02:00
|
|
|
return rv;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
|
|
|
|
void EpdBase::Epd2U::DecodeFunctionFlags()
|
|
|
|
|
{
|
2019-02-21 10:11:58 +01:00
|
|
|
EpdType = (FunctionFlags & 0x1F00) >> 8;
|
2021-05-20 16:13:23 +02:00
|
|
|
//0=BG 3=Neutron 4=BG Mk3 7=Neutron Mk4
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
|
|
|
|
void EpdBase::Epd2U::DecodeStatus()
|
|
|
|
|
{
|
2022-04-26 08:43:13 +02:00
|
|
|
hasAlarm = hasFault = false;
|
2019-02-04 11:48:08 +01:00
|
|
|
DetectorsOn = (OperatingStatus & 1) != 0;
|
|
|
|
|
EPDIssued = (OperatingStatus & 4) != 0;
|
|
|
|
|
EPDLocked = (OperatingStatus & 0x10)!=0;
|
|
|
|
|
EPDTesting = (OperatingStatus & 0x20) != 0;
|
|
|
|
|
EPDProcSec = (OperatingStatus & 0x40) != 0;
|
|
|
|
|
EPDFaulty = (OperatingStatus & 0x80) != 0;
|
|
|
|
|
|
|
|
|
|
EPDNewFault = (ErrorStatus & 1) != 0;
|
|
|
|
|
EPDComFault = (ErrorStatus & 2) != 0;
|
|
|
|
|
EPDCalFault = (ErrorStatus & 4) != 0;
|
|
|
|
|
EPDDetFault = (ErrorStatus & 8) != 0;
|
|
|
|
|
EPDEprFault = (ErrorStatus & 0x10) != 0;
|
|
|
|
|
EPDTrhFault = (ErrorStatus & 0x20) != 0;
|
|
|
|
|
EPDOthFault = (ErrorStatus & 0x80) != 0;
|
|
|
|
|
|
|
|
|
|
AlarmDoseHP101G = (AlarmStatus & 1) != 0;
|
|
|
|
|
AlarmDoseHP102G = (AlarmStatus & 2) != 0;
|
|
|
|
|
AlarmDoseHP07N = (AlarmStatus & 4) != 0;
|
|
|
|
|
AlarmRateHP101G = (AlarmStatus & 8) != 0;;
|
|
|
|
|
AlarmRateHP102G = (AlarmStatus & 0x10) != 0;
|
|
|
|
|
AlarmRateHP07N = (AlarmStatus & 0x20) != 0;
|
|
|
|
|
|
|
|
|
|
//OtherAlarm
|
|
|
|
|
OtherAlarmRateHp101G = (OtherAlarms & 1) != 0;
|
|
|
|
|
OtherAlarmRateHp102G = (OtherAlarms & 2) != 0;
|
|
|
|
|
OtherAlarmRateHp07N = (OtherAlarms & 4) != 0;
|
|
|
|
|
OtherAlarmReturn = (OtherAlarms & 8) != 0;
|
|
|
|
|
OtherAlarmBatLow = (OtherAlarms & 0x10) != 0;
|
|
|
|
|
OtherAlarmCarrier = (OtherAlarms & 0x20) != 0;
|
|
|
|
|
OtherAlarmBatVolt = (OtherAlarms & 0x40) != 0;
|
|
|
|
|
|
2022-04-12 14:28:14 +02:00
|
|
|
//New fields
|
|
|
|
|
eDosDose07Alarm = AlarmDoseHP07N;
|
|
|
|
|
eDosDose07Warning = eDosDose07Alarm;
|
|
|
|
|
eDosDose10Warning = AlarmDoseHP101G;
|
|
|
|
|
eDosDose10Alarm = AlarmRateHP102G;
|
2026-01-07 14:16:45 +01:00
|
|
|
eDosRate07Alarm = OtherAlarmRateHp07N || AlarmRateHP07N;
|
2022-04-12 14:28:14 +02:00
|
|
|
eDosRate07Warning = eDosRate07Alarm;
|
2026-01-07 14:16:45 +01:00
|
|
|
eDosRate10Warning = OtherAlarmRateHp101G || AlarmRateHP101G;
|
|
|
|
|
eDosRate10Alarm = OtherAlarmRateHp102G || AlarmRateHP102G;
|
|
|
|
|
eDosBatteryWarning = OtherAlarmBatLow || OtherAlarmBatVolt;
|
2022-04-12 14:28:14 +02:00
|
|
|
|
2021-06-02 13:54:22 +02:00
|
|
|
if (!VersionOK) OtherAlarms &= 0x7f;
|
2022-04-26 08:43:13 +02:00
|
|
|
|
2022-04-12 14:28:14 +02:00
|
|
|
eDosDoseAlarm = eDosDose07Alarm || eDosDose10Alarm;
|
|
|
|
|
eDosRateAlarm = eDosRate07Alarm || eDosRate10Alarm;
|
|
|
|
|
|
2022-04-26 08:43:13 +02:00
|
|
|
hasAlarm = (eDosRateAlarm || eDosDoseAlarm);
|
|
|
|
|
hasFault = ((OtherAlarms & 0xf8) != 0) || ((OperatingStatus & 0x80) != 0) || (ErrorStatus != 0);
|
|
|
|
|
|
2026-01-07 14:16:45 +01:00
|
|
|
StatusDecoded = true;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-06-02 13:54:22 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>0 = ok</returns>
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD EpdBase::Epd2U::ReadStatus()
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2021-06-02 13:54:22 +02:00
|
|
|
int rv = 0;
|
2026-08-02 16:00:16 +02:00
|
|
|
EPDStep = StepReadStatus;
|
|
|
|
|
EPDStepResult = EpdStepResults::Started;
|
2020-02-05 14:21:53 +01:00
|
|
|
Error = 0; ReadStatusRV = 0;
|
2020-02-06 09:37:51 +01:00
|
|
|
memset(WearerID, 0, WearerIDLength + 1);
|
|
|
|
|
memset(WearerName, 0, WearerNameLength + 1);
|
2019-02-04 11:48:08 +01:00
|
|
|
|
2021-04-16 10:38:48 +02:00
|
|
|
IssueCount = OperatingStatus = ErrorStatus = AlarmStatus = OtherAlarms = EEPROMBadSectors = 0;
|
|
|
|
|
RealTime = EpdClock = OffTime = EpdID = 0;
|
2019-02-04 11:48:08 +01:00
|
|
|
ErrorSource = ErrorReason = ErrorData = 0;
|
2024-05-22 13:31:10 +02:00
|
|
|
HardVersion = HardVersionMinor= SoftVersion = FunctionFlags = 0;
|
2019-02-04 11:48:08 +01:00
|
|
|
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) {
|
|
|
|
|
EpdID = 4567;
|
|
|
|
|
EpdType = 0;
|
|
|
|
|
FunctionFlags = 0x000;
|
2021-06-02 13:54:22 +02:00
|
|
|
return 0;
|
2021-03-26 17:20:57 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-21 16:22:20 +02:00
|
|
|
RealTime = UnixTimeNow();
|
2019-02-14 15:56:23 +01:00
|
|
|
CommitRV = ReadEpdStatus(&EpdClock, &RealTime, &IssueCount, &OffTime, &OperatingStatus, &ErrorStatus, &AlarmStatus, &OtherAlarms, &EEPROMBadSectors);
|
2026-01-07 14:16:45 +01:00
|
|
|
StatusDecoded = false;
|
2021-03-30 15:13:22 +02:00
|
|
|
if (port == 0) {
|
|
|
|
|
EpdClock = 123; ErrorStatus = 0;
|
|
|
|
|
};
|
2022-04-12 14:28:14 +02:00
|
|
|
ErrorStatus &= 0xff;
|
|
|
|
|
OperatingStatus &= 0xff;
|
|
|
|
|
//RealTime The number of seconds since January 1st, 1970 according to your system time
|
2020-02-18 14:06:52 +01:00
|
|
|
if (CommitRV == 1) CommitRV = Commit();
|
2021-05-21 16:22:20 +02:00
|
|
|
|
2020-02-06 09:37:51 +01:00
|
|
|
if (CommitRV == 1) CommitRV = ReadEpdID(
|
2019-02-04 11:48:08 +01:00
|
|
|
&EpdID,
|
2020-02-06 09:37:51 +01:00
|
|
|
&HardVersion,
|
2019-02-04 11:48:08 +01:00
|
|
|
&SoftVersion,
|
|
|
|
|
&FunctionFlags);
|
2020-02-06 09:37:51 +01:00
|
|
|
if (CommitRV == 1) CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) {
|
2019-02-04 11:48:08 +01:00
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2020-02-06 09:37:51 +01:00
|
|
|
ReadStatusRV = ErrorReason;
|
2021-06-02 13:54:22 +02:00
|
|
|
rv = ErrorReason;
|
2026-08-02 16:00:16 +02:00
|
|
|
EPDStepResult = EpdStepResults::Error;
|
2021-06-02 13:54:22 +02:00
|
|
|
return rv;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2026-08-02 16:00:16 +02:00
|
|
|
EPDStepResult = EpdStepResults::OK;
|
2021-05-27 16:13:53 +02:00
|
|
|
CurrentDeviceID = EpdID;
|
2019-02-04 11:48:08 +01:00
|
|
|
time_t t = RealTime;
|
|
|
|
|
TimeFunctions::UnixTimeToSystemTime(t, &tRealTime);
|
|
|
|
|
DecodeStatus();
|
|
|
|
|
DecodeFunctionFlags();
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-02 13:54:22 +02:00
|
|
|
byte ff = (FunctionFlags >> 8) & 0x0f;
|
|
|
|
|
isBG = ff == 0;
|
|
|
|
|
isNG = ff == 3;
|
|
|
|
|
VersionOK = (isBG && SoftVersion >= 11) || (isNG && SoftVersion >= 3);
|
|
|
|
|
|
2022-04-20 16:56:49 +02:00
|
|
|
if (CommitRV == 1) {
|
|
|
|
|
if (EPDIssued == 1) {
|
|
|
|
|
CommitRV = ReadWearer(
|
|
|
|
|
WearerID,
|
|
|
|
|
WearerIDLength,
|
|
|
|
|
WearerName,
|
|
|
|
|
WearerNameLength);
|
|
|
|
|
if (CommitRV == 1) CommitRV = Commit();
|
2022-04-26 08:43:13 +02:00
|
|
|
|
2022-04-20 16:56:49 +02:00
|
|
|
if (CommitRV == 0) {
|
|
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
rv = ReadStatusRV = ErrorReason;
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2022-04-26 08:43:13 +02:00
|
|
|
else memset(WearerID, 0xb, WearerIDLength);
|
|
|
|
|
rv = 0;
|
|
|
|
|
for (int i = 0; i < WearerIDLength; i++)
|
|
|
|
|
if (WearerID[i] == 0xb) WearerID[i] = '0'; else WearerID[i] |= 0x30;
|
|
|
|
|
}
|
2026-08-02 16:00:16 +02:00
|
|
|
if (progressCallback) progressCallback(EPDStep, EPDStepResult);
|
2021-06-02 13:54:22 +02:00
|
|
|
return rv;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-06-01 16:35:24 +02:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>0 ok</returns>
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD EpdBase::Epd2U::EPDReadExtraStatus()
|
2019-02-12 16:01:47 +01:00
|
|
|
{
|
2021-05-31 15:20:16 +02:00
|
|
|
int rv = 0;
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) return 1;
|
|
|
|
|
|
2019-02-14 15:56:23 +01:00
|
|
|
byBatADC = bySupplyADC = 0;
|
|
|
|
|
/*CommitRV = ReadA2ConfigStatus(
|
2019-02-12 16:01:47 +01:00
|
|
|
&byBatADC,
|
|
|
|
|
&bySupplyADC,
|
|
|
|
|
&byStatus3,
|
|
|
|
|
&byStatus4);
|
2019-02-14 15:56:23 +01:00
|
|
|
if (CommitRV == 1) CommitRV = Commit();*/
|
|
|
|
|
if (CommitRV == 1) CommitRV = ReadCounts(&D1, &D2, &D3, &D4, &CountsClock);
|
2019-02-12 16:01:47 +01:00
|
|
|
if (CommitRV == 1) CommitRV = Commit();
|
2019-02-14 15:56:23 +01:00
|
|
|
if (CommitRV == 1) CommitRV = ReadBaseCounts(&BaseD1, &BaseD2, &BaseD3, &BaseD4, &BaseCountsClock);
|
|
|
|
|
if (CommitRV == 1) CommitRV = Commit();
|
2021-06-01 16:35:24 +02:00
|
|
|
if (CommitRV == 1) rv = 0;
|
|
|
|
|
else {
|
2019-02-14 15:56:23 +01:00
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2021-05-31 15:20:16 +02:00
|
|
|
rv = ErrorReason;
|
|
|
|
|
}
|
|
|
|
|
return rv;
|
2019-02-12 16:01:47 +01:00
|
|
|
}
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD EpdBase::Epd2U::EPDReadConfig()
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) return 1;
|
|
|
|
|
|
2019-02-04 11:48:08 +01:00
|
|
|
ReadConfigRV = ReadConfig(
|
|
|
|
|
&CountDownTime,
|
|
|
|
|
&ReturnTime,
|
|
|
|
|
&ChirpRate,
|
|
|
|
|
&TeleBaudSetting,
|
|
|
|
|
&SelfTestInterval,
|
|
|
|
|
&BatteryLoadTestInt,
|
|
|
|
|
&GeneralControl,
|
|
|
|
|
&CommsTimeout,
|
|
|
|
|
&InhibitTimeout,
|
|
|
|
|
&MinTxInterval,
|
|
|
|
|
&MaxTxIntervals,
|
|
|
|
|
&RandomiseWindow,
|
|
|
|
|
&DoseIncThresh);
|
|
|
|
|
if (ReadConfigRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
return CommitRV;
|
|
|
|
|
}
|
2021-03-26 17:20:57 +01:00
|
|
|
|
2021-06-02 13:54:22 +02:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>0=ok</returns>
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD EpdBase::Epd2U::WriteCal()
|
2019-02-12 16:01:47 +01:00
|
|
|
{
|
2021-06-02 13:54:22 +02:00
|
|
|
int rv = 1;
|
|
|
|
|
CommitRV = 0;
|
|
|
|
|
if (port == 0 ) return 0;
|
|
|
|
|
if (isBG) return 1;
|
|
|
|
|
if (K6 > 2000) return 1;
|
2019-02-12 16:01:47 +01:00
|
|
|
Password = 9;
|
|
|
|
|
//((BYTE *)&Password)[0] = 9;
|
|
|
|
|
|
|
|
|
|
CommitRV = MFRLogin(Password);
|
|
|
|
|
if (CommitRV == 1) CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 1) CommitRV = MFRWriteCalFactors(K1, K2, K3, K4, K5, K6);
|
|
|
|
|
if (CommitRV == 1) CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2021-06-02 13:54:22 +02:00
|
|
|
else rv = 0; //ok
|
|
|
|
|
return rv;
|
2019-02-12 16:01:47 +01:00
|
|
|
}
|
2021-06-01 16:35:24 +02:00
|
|
|
|
2021-06-02 13:54:22 +02:00
|
|
|
WORD EpdBase::Epd2U::ReadCal()
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
|
|
|
|
ReadCalibrationDataRV = ReadCalibrationData(
|
|
|
|
|
&K1,
|
|
|
|
|
&K2,
|
|
|
|
|
&K3,
|
|
|
|
|
&K4,
|
|
|
|
|
&K5,
|
|
|
|
|
&K6,
|
|
|
|
|
&SG,
|
|
|
|
|
&BC,
|
|
|
|
|
&FB,
|
|
|
|
|
&HG);
|
|
|
|
|
CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2021-05-28 17:06:41 +02:00
|
|
|
if (CommitRV == 1) return 0; else return 123;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-06-02 13:54:22 +02:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>0 Success</returns>
|
|
|
|
|
WORD EpdBase::Epd2U::ReadTresHolds()
|
|
|
|
|
{
|
|
|
|
|
int rv =0;
|
|
|
|
|
if (port == 0) {
|
|
|
|
|
Hp10THDose1 = Hp10THDose2 = Hp10THDose2 = 123;
|
|
|
|
|
Hp10Rate1On = Hp10Rate2On = Hp07RateOn = Hp10Rate1Off = Hp10Rate2Off = Hp07RateOff = 124;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
Hp10THDose1 = Hp10THDose2 = Hp07THDose = 0;
|
|
|
|
|
ReadDoseTresholdRV = ReadAlarmDoseThresholds(&Hp10THDose1, &Hp10THDose2, &Hp07THDose);
|
|
|
|
|
CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) rv = Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
|
|
|
|
|
if (rv == 0) {
|
|
|
|
|
ReadAlarmRateThresholdsRV = ReadAlarmRateThresholds(
|
|
|
|
|
&Hp10Rate1On,
|
|
|
|
|
&Hp10Rate2On,
|
|
|
|
|
&Hp07RateOn,
|
|
|
|
|
&Hp10Rate1Off,
|
|
|
|
|
&Hp10Rate2Off,
|
|
|
|
|
&Hp07RateOff);
|
|
|
|
|
CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) rv = Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
}
|
|
|
|
|
if (rv==0) rv = ReadCal();
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
2021-06-01 16:35:24 +02:00
|
|
|
|
2022-03-17 08:57:22 +01:00
|
|
|
WORD EpdBase::Epd2U::ClearAlarms()
|
|
|
|
|
{
|
|
|
|
|
int rv = 0;
|
|
|
|
|
if (port == 0) return 0;
|
|
|
|
|
if (CommitRV) CommitRV = ClearFaultFlags();
|
|
|
|
|
if (CommitRV) CommitRV = ClearLatchedAlarms();
|
|
|
|
|
if (CommitRV) rv = 0; else rv = 1;
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-01 16:35:24 +02:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>0 OK</returns>
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD EpdBase::Epd2U::ReadDoses()
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2022-04-12 14:28:14 +02:00
|
|
|
Hp10FTime = Hp07FTime = 0UL;
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) {
|
|
|
|
|
Hp10Dose = Hp07Dose = Hp10Total = Hp07Total = Knocks = Resets = QualityData = 21;
|
|
|
|
|
Hp10Peak = Hp07Peak = Hp10Time = Hp07Time = 1000;
|
2022-04-12 14:28:14 +02:00
|
|
|
eDosDose07Warning = eDosDose07Alarm = eDosDose10Warning = eDosDose10Alarm = eDosRate07Warning = eDosRate07Alarm = eDosRate10Warning = eDosRate10Alarm = eDosBatteryWarning = eDosDoseAlarm = eDosRateAlarm = 0;
|
2021-03-26 17:20:57 +01:00
|
|
|
ErrorSource = ErrorReason = ErrorData = 0;
|
2021-04-16 10:38:48 +02:00
|
|
|
K1 = 1; K2 = 2; K3 = 3; K4 = 4; K5 = 5; K6 = 6;
|
|
|
|
|
SG = 7; BC = 8; FB = 9; HG = 10;
|
2021-03-26 17:20:57 +01:00
|
|
|
return 1;
|
|
|
|
|
}
|
2019-02-04 11:48:08 +01:00
|
|
|
ReadDosesQualityRV = ReadPeaksRV = CommitRV = 0;
|
2019-02-01 17:35:18 +01:00
|
|
|
ReadDosesQualityRV = ReadDosesQuality(
|
|
|
|
|
&Hp10Dose,
|
|
|
|
|
&Hp07Dose,
|
|
|
|
|
&Hp10Total,
|
|
|
|
|
&Hp07Total,
|
|
|
|
|
&Knocks,
|
|
|
|
|
&Resets,
|
2019-02-04 11:48:08 +01:00
|
|
|
&QualityData);
|
|
|
|
|
|
|
|
|
|
if (ReadDosesQualityRV == 0) {
|
|
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-12 14:28:14 +02:00
|
|
|
QualityData &= 0x7f;
|
|
|
|
|
|
2019-02-01 17:35:18 +01:00
|
|
|
ReadPeaksRV = ReadPeaks(
|
|
|
|
|
&Hp10Peak,
|
|
|
|
|
&Hp07Peak,
|
2022-04-12 14:28:14 +02:00
|
|
|
&Hp10Time, //EpdClock of Occurence
|
2019-02-04 11:48:08 +01:00
|
|
|
&Hp07Time);
|
|
|
|
|
if (ReadPeaksRV == 0) {
|
|
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2019-02-11 11:34:52 +01:00
|
|
|
|
2022-04-12 14:28:14 +02:00
|
|
|
TimeFunctions::EPD2PeakTimeToFiletime(EpdClock, Hp10Time, (LPFILETIME)&Hp10FTime);
|
|
|
|
|
TimeFunctions::EPD2PeakTimeToFiletime(EpdClock, Hp07Time, (LPFILETIME)&Hp07FTime);
|
|
|
|
|
|
2019-02-11 11:34:52 +01:00
|
|
|
ReadCalibrationData(
|
|
|
|
|
&K1,
|
|
|
|
|
&K2,
|
|
|
|
|
&K3,
|
|
|
|
|
&K4,
|
|
|
|
|
&K5,
|
|
|
|
|
&K6,
|
|
|
|
|
&SG,
|
|
|
|
|
&BC,
|
|
|
|
|
&FB,
|
|
|
|
|
&HG);
|
|
|
|
|
CommitRV = Commit();
|
|
|
|
|
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2021-06-01 16:35:24 +02:00
|
|
|
return CommitRV==1 ? 0 : 1;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD EpdBase::Epd2U::PrepareForIssue()
|
2019-04-03 13:13:47 +02:00
|
|
|
{
|
2021-05-28 17:06:41 +02:00
|
|
|
int rv = 0;
|
|
|
|
|
if (port == 0) return 0;
|
2024-05-16 15:56:07 +02:00
|
|
|
|
2026-08-02 16:00:16 +02:00
|
|
|
EPDStep = StepPrepareIssue;
|
|
|
|
|
EPDStepResult = EpdStepResults::Started;
|
|
|
|
|
|
2020-03-11 13:23:29 +01:00
|
|
|
CommitRV = WriteConfig();
|
2024-05-16 15:56:07 +02:00
|
|
|
CommitRV = 0;
|
2022-03-17 08:57:22 +01:00
|
|
|
ClearAlarms();
|
2024-05-16 15:56:07 +02:00
|
|
|
Commit();
|
|
|
|
|
//if (CommitRV) CommitRV = Commit();
|
2020-03-11 13:23:29 +01:00
|
|
|
if (CommitRV) CommitRV = ClearDose();
|
2019-04-03 13:13:47 +02:00
|
|
|
if (CommitRV) CommitRV = ClearTotalDose();
|
|
|
|
|
if (CommitRV) CommitRV = ClearPeakRates();
|
|
|
|
|
if (CommitRV) CommitRV = Commit();
|
2021-05-28 17:06:41 +02:00
|
|
|
if (CommitRV) rv = 0; else rv = 1;
|
2026-08-02 16:00:16 +02:00
|
|
|
EPDStepResult = EpdStepResults::OK;
|
|
|
|
|
if (progressCallback) {
|
|
|
|
|
progressCallback(EPDStep, EPDStepResult);
|
|
|
|
|
}
|
2021-05-28 17:06:41 +02:00
|
|
|
return rv;
|
2019-04-03 13:13:47 +02:00
|
|
|
}
|
2021-06-01 16:35:24 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// DeIssue and close
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2024-10-14 07:51:22 +02:00
|
|
|
WORD EpdBase::Epd2U::DeIssue(WORD doEndCom)
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2021-05-31 15:20:16 +02:00
|
|
|
int rv = 0;
|
2019-02-04 11:48:08 +01:00
|
|
|
ClearDoseRV = ClearTotalDoseRV = ClearPeakRatesRV = DeIssueEpdRV = 0;
|
2021-03-26 17:20:57 +01:00
|
|
|
if (port == 0) return 1;
|
2019-02-04 11:48:08 +01:00
|
|
|
if (CommitRV) CommitRV = ClearDose();
|
|
|
|
|
if (CommitRV) CommitRV = ClearTotalDose();
|
|
|
|
|
if (CommitRV) CommitRV = ClearPeakRates();
|
2020-10-08 13:48:36 +02:00
|
|
|
if (CommitRV) CommitRV = Commit();
|
|
|
|
|
if (CommitRV) CommitRV = ClearFaultFlags();
|
|
|
|
|
if (CommitRV) CommitRV = ClearLatchedAlarms();//Hp10Rate1; Hp10Rate2; Hp07Rate; ReturnForRead
|
|
|
|
|
if (CommitRV) CommitRV = Commit();
|
|
|
|
|
CommitRV = ClearFailFlag();
|
2021-05-31 15:20:16 +02:00
|
|
|
if (CommitRV && EPDIssued) {
|
|
|
|
|
CommitRV = DeIssueEpd();
|
|
|
|
|
if (CommitRV) CommitRV = Commit();
|
|
|
|
|
}
|
|
|
|
|
if (CommitRV && DetectorsOn ) {
|
2019-02-04 11:48:08 +01:00
|
|
|
CommitRV = EpdOff();
|
|
|
|
|
CommitRV= Commit();
|
2021-06-02 13:54:22 +02:00
|
|
|
if (!VersionOK) Sleep(1000);// Versie < .. Commit & Sleep
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-03 08:37:02 +02:00
|
|
|
if (CommitRV ) {
|
2024-10-14 07:51:22 +02:00
|
|
|
CloseAndSignal(EndSessionControl, 12, doEndCom);
|
2021-05-31 15:20:16 +02:00
|
|
|
rv = 0;
|
|
|
|
|
}
|
2019-02-04 11:48:08 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FlushBuffers(port);
|
2021-06-02 13:54:22 +02:00
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2024-10-14 07:51:22 +02:00
|
|
|
CloseAndSignal(EndSessionControl, 40,doEndCom);
|
2021-05-31 15:20:16 +02:00
|
|
|
rv = ErrorReason;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-05-31 15:20:16 +02:00
|
|
|
return rv;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-05-28 17:06:41 +02:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>O = OK</returns>
|
2024-10-14 07:51:22 +02:00
|
|
|
WORD EpdBase::Epd2U::Issue(WORD doEndCom)
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
2021-06-03 08:37:02 +02:00
|
|
|
int rv=0;
|
2019-02-04 11:48:08 +01:00
|
|
|
IssueEpdRV = WriteAlarmDoseThresholdsRV = WriteAlarmRateThresholdsRV = WriteWearerNameRV = OnRV = CommitRV = 0;
|
2021-05-28 17:06:41 +02:00
|
|
|
if (port == 0) return 0;
|
2021-04-16 10:38:48 +02:00
|
|
|
WORD OKRV = SetFailFlag(); // all actions have been completed
|
2019-02-04 11:48:08 +01:00
|
|
|
if (OKRV) OKRV = Commit();
|
2021-05-21 16:22:20 +02:00
|
|
|
if (OKRV) OKRV = BaseLineCounts();
|
2019-02-04 11:48:08 +01:00
|
|
|
if (OKRV) OKRV = WriteAlarmDoseThresholds(Hp10THDose1, Hp10THDose2, Hp07THDose);
|
|
|
|
|
if (OKRV) OKRV = WriteAlarmRateThresholds(Hp10Rate1On, Hp10Rate2On, Hp07RateOn, Hp10Rate1Off, Hp10Rate2Off, Hp07RateOff);
|
|
|
|
|
if (OKRV) OKRV = Commit();
|
|
|
|
|
if (OKRV) OKRV = IssueEpd(WearerID, WearerIDLength);
|
|
|
|
|
if (OKRV) OKRV = Commit();
|
2021-04-16 10:38:48 +02:00
|
|
|
if (OKRV) OKRV = WriteWearerName(WearerName,(WORD)strlen((char *)WearerName));
|
2019-02-11 11:34:52 +01:00
|
|
|
if (OKRV) OKRV = Commit();
|
2021-06-03 08:37:02 +02:00
|
|
|
|
|
|
|
|
if (OKRV == 0)
|
2019-02-14 15:56:23 +01:00
|
|
|
{
|
2021-06-03 08:37:02 +02:00
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2021-05-28 17:06:41 +02:00
|
|
|
rv = 1;
|
2019-02-14 15:56:23 +01:00
|
|
|
}
|
2024-09-13 15:31:27 +02:00
|
|
|
else
|
|
|
|
|
EPDIssued = 1;
|
2019-02-14 15:56:23 +01:00
|
|
|
ClearFailFlag(); // all actions have been completed
|
2021-06-03 08:37:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if (OKRV)
|
|
|
|
|
{
|
|
|
|
|
if (!DetectorsOn) {
|
|
|
|
|
OKRV = EpdOn();
|
|
|
|
|
OKRV = Commit();
|
|
|
|
|
if (!VersionOK) Sleep(1500);
|
|
|
|
|
}
|
2024-10-14 07:51:22 +02:00
|
|
|
CloseAndSignal(EndSessionControl, 12, doEndCom);
|
2021-06-03 08:37:02 +02:00
|
|
|
rv = 0;
|
2021-05-21 16:22:20 +02:00
|
|
|
}
|
2021-06-03 08:37:02 +02:00
|
|
|
else
|
2019-02-04 11:48:08 +01:00
|
|
|
{
|
|
|
|
|
FlushBuffers(port);
|
2019-02-14 15:56:23 +01:00
|
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
2024-10-14 07:51:22 +02:00
|
|
|
CloseAndSignal(EndSessionControl, 40, doEndCom);
|
2021-06-03 08:37:02 +02:00
|
|
|
rv = 1;
|
2019-02-04 11:48:08 +01:00
|
|
|
}
|
2021-05-28 17:06:41 +02:00
|
|
|
return rv;
|
2021-05-27 16:13:53 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-14 07:51:22 +02:00
|
|
|
//main exit function
|
|
|
|
|
//does endcom at end
|
2021-06-01 16:35:24 +02:00
|
|
|
int EpdBase::Epd2U::GetAllDeissue()
|
|
|
|
|
{
|
|
|
|
|
int rv = 0;
|
|
|
|
|
rv = ReadDoses(); //0 = success
|
|
|
|
|
//rv = ReadTresHolds(); //tresholds not needed, only doses
|
|
|
|
|
rv = EPDReadExtraStatus();
|
2024-10-14 07:51:22 +02:00
|
|
|
rv = DeIssue(true); //does close
|
2021-06-01 16:35:24 +02:00
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-14 07:51:22 +02:00
|
|
|
|
|
|
|
|
//main get dos function
|
|
|
|
|
//does endcom at end
|
2021-06-01 16:35:24 +02:00
|
|
|
int EpdBase::Epd2U::GetAll(bool Closeconnection)
|
|
|
|
|
{
|
|
|
|
|
int rv = 0;
|
|
|
|
|
rv = ReadDoses(); //0 = success
|
|
|
|
|
rv = ReadTresHolds(); //0 = success Tresholds needed
|
2024-10-14 07:51:22 +02:00
|
|
|
if (Closeconnection) Close(1);
|
2021-06-01 16:35:24 +02:00
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 16:13:53 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// discover, connect and read status
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tokenSourceTimeout"></param>
|
|
|
|
|
/// <returns>0=success 1=connect error, 2 = no devices, 3= error reading status</returns>
|
2022-05-04 07:53:20 +02:00
|
|
|
int EpdBase::Epd2U::ConnectAndStatus(int tokenSourceTimeoutms)
|
2021-05-27 16:13:53 +02:00
|
|
|
{
|
|
|
|
|
WORD dllStatus;
|
|
|
|
|
int rv = 1;
|
2024-05-29 16:08:18 +02:00
|
|
|
if (CommsInitialized == 0) StartCom();
|
2022-02-24 09:01:32 +01:00
|
|
|
if (CommsInitialized == 0) rv = 1;
|
|
|
|
|
else {
|
2022-05-04 07:53:20 +02:00
|
|
|
dllStatus = StartDiscover(tokenSourceTimeoutms);
|
2022-02-24 09:01:32 +01:00
|
|
|
if (dllStatus != 1) rv = 1; //Connect error
|
|
|
|
|
else if (DeviceCount < 1) rv = 2; //TO
|
2022-04-20 16:56:49 +02:00
|
|
|
else if (ReadStatus() != 0) rv = 1; //Read Error
|
2022-02-24 09:01:32 +01:00
|
|
|
else rv = 0;
|
|
|
|
|
}
|
2026-08-02 16:00:16 +02:00
|
|
|
|
2021-05-27 16:13:53 +02:00
|
|
|
return rv;
|
2021-06-02 13:54:22 +02:00
|
|
|
}
|
|
|
|
|
|
2024-10-14 07:51:22 +02:00
|
|
|
// main EPD-issue function
|
|
|
|
|
// does endcom at the end
|
2021-06-02 13:54:22 +02:00
|
|
|
int EpdBase::Epd2U::IssueAndCheck(float gain)
|
|
|
|
|
{
|
2022-08-30 09:10:33 +02:00
|
|
|
//chirp not supported
|
2021-06-02 13:54:22 +02:00
|
|
|
int rv = 0;
|
|
|
|
|
if (isNG) {
|
|
|
|
|
int kx = (int)gain;
|
|
|
|
|
rv = ReadCal();
|
|
|
|
|
if (rv != 0 || K6 != 1310) { rv = 1; goto error; }
|
|
|
|
|
if (K3 != kx || K4 != kx)
|
|
|
|
|
{
|
|
|
|
|
K3 = K4 = kx;
|
|
|
|
|
rv = WriteCal();
|
|
|
|
|
if (rv != 0) goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
rv = PrepareForIssue();
|
2024-10-14 07:51:22 +02:00
|
|
|
rv = Issue(true); // data already loaded
|
2021-06-02 13:54:22 +02:00
|
|
|
return rv;
|
|
|
|
|
error:
|
|
|
|
|
return rv;
|
2019-02-01 09:54:48 +01:00
|
|
|
}
|