eDosStation/EpdBaseClr/EpdBaseClr.cpp

1329 lines
34 KiB
C++
Raw Normal View History

2019-02-01 17:35:18 +01:00
#include "stdafx.h"
#include "EpdBaseClr.h"
2021-05-28 17:06:41 +02:00
#pragma managed
#include "../EpdBase3/Epd3Base.h" // or "Epd3Base.h" if on include path
2026-10-14 12:44:18 +02:00
#include <filesystem>
#include <fstream>
#include <msclr/marshal_cppstd.h>
typedef void (*ProgressCallback)(int percentage, const char* message);
2026-07-28 16:36:22 +02:00
void EpdBaseClr::Epd2::OnCancelRequested()
{
if (epd3 != nullptr) epd3->CancelAll();
2026-08-02 16:00:16 +02:00
if (epd != nullptr) epd->CancelAll();
2026-07-28 16:36:22 +02:00
}
2026-08-02 16:00:16 +02:00
2024-09-05 16:10:29 +02:00
bool EpdBaseClr::Epd2::HasStepError()
{
return (bool)epd3->HasStepError;
}
2026-08-29 13:56:11 +02:00
int EpdBaseClr::Epd2::SetEndNotifyAlarm(UInt16 NotifyAlarm, UINT16 NotifyAlarmDuration)
{
if (epd3) {
epd3->EndNotifyAlarm = NotifyAlarm;
epd3->EndNotifyAlarmDuration = NotifyAlarmDuration;
}
return 0;
}
2026-09-21 17:47:14 +02:00
2026-10-14 12:44:18 +02:00
//#include <filesystem>
//#include <fstream>
//#include <msclr/marshal_cppstd.h> // Required for String^ to std::string conversion
int EpdBaseClr::Epd2::SetDebugLog(System::String^ path)
{
namespace fs = std::filesystem;
// Convert managed System::String^ to standard std::string
std::string nativePath;
if (!System::String::IsNullOrEmpty(path)) {
nativePath = msclr::interop::marshal_as<std::string>(path);
}
bool hasPath = !nativePath.empty();
fs::path logDir = nativePath;
// Main logFile
if (hasPath) {
if (logFile) {
delete logFile;
}
logFile = new std::ofstream(logDir / "epdclr.log", std::ios::out | std::ios::app);
LogMessage("Epd2 log open");
}
else {
if (logFile) {
delete logFile;
logFile = nullptr;
}
}
// epd3 log file
if (epd3) {
if (hasPath) {
epd3->logFile.open(logDir / "epdbase3.log", std::ios::out | std::ios::app);
}
else if (epd3->logFile.is_open()) {
epd3->logFile.close();
}
}
// epd2 log file
if (epd) {
if (hasPath) {
epd->logFile.open(logDir / "epdbase.log", std::ios::out | std::ios::app);
}
else if (epd->logFile.is_open()) {
epd->logFile.close();
}
}
return 0;
}
2026-09-21 17:47:14 +02:00
/// <summary>
///
/// </summary>
/// <param name="ResponseTimeout">Standaard dll rsponse timeout</param>
/// <param name="DiscoveryCacheTimeout">Standard dll discovery cache timeout</param>
/// <param name="SleepAfterClear">After Clear dose, clear peak wait ms</param>
/// <param name="SleepBeforeReconnect">Before a failed reconnect, wait ms</param>
/// <param name="SleepAfterDisconnect">After final disconnect wait before stopping interface </param>
/// <param name="DoDisconnectAfterClear">After clear dose, peaks do a disconnect</param>
/// <param name="DoDisconnectBeforeReconnect">Before a reconnect, do a disconnect</param>
/// <returns></returns>
int EpdBaseClr::Epd2::OtherParam(int ResponseTimeout, int DiscoveryCacheTimeout,int ReconnectRetries, int SleepAfterClear, int SleepBeforeReconnect, int SleepAfterDisconnect, bool DoDisconnectAfterClear, bool DoDisconnectBeforeReconnect, bool DoProtectSession, bool DoUserprofile)
2026-09-21 17:47:14 +02:00
{
if (epd3) {
epd3->ResponseTimeout = ResponseTimeout;
epd3->DiscoveryCacheTimeout = DiscoveryCacheTimeout;
epd3->ReconnectRetries = ReconnectRetries;
epd3->SleepAfterClear = SleepAfterClear;
epd3->SleepBeforeReconnect = SleepBeforeReconnect;
epd3->SleepAfterDisconnect = SleepAfterDisconnect ;
epd3->DoDisconnectAfterClear = DoDisconnectAfterClear;
epd3->DoDisconnectBeforeReconnect = DoDisconnectBeforeReconnect;
epd3->DoProtectSession = DoProtectSession;
epd3->DoUserProfile = DoUserprofile;
2026-09-21 17:47:14 +02:00
}
return 0;
}
2026-09-02 09:21:22 +02:00
int EpdBaseClr::Epd2::SetReleaseLogging(bool doLog )
{
if (epd3) {
epd3->SetReleaseLogging( doLog);
}
return 0;
}
2024-09-04 13:05:16 +02:00
int EpdBaseClr::Epd2::GetSteps()
{
int nsteps = (int)epd3->CurrentStep + 1;
StepMaxTime = 0;
2024-09-04 13:05:16 +02:00
if (nsteps>0) {
StepReturnValues = gcnew System::Collections::Generic::List<cStepValues^>(nsteps);
cStepValues^ x;
for (int i = 0; i<nsteps; i++)
{
x = gcnew cStepValues();
x->func = (Int32)epd3->StepReturnValues[i][0];
x->commitrv = epd3->StepReturnValues[i][1];
x->endrv = epd3->StepReturnValues[i][2];
2026-09-04 18:50:13 +02:00
x->commitms = epd3->StepReturnValues[i][4];
x->endms = epd3->StepReturnValues[i][5];
2026-10-29 10:53:53 +01:00
x->commitcode = (Int16)epd3->StepReturnValues[i][6];
x->endcode = epd3->StepReturnValues[i][7];
x->retry = epd3->StepReturnValues[i][8];
2024-09-04 13:05:16 +02:00
StepReturnValues->Add(x);
}
int tm;
if (nsteps>0) {
tm = epd3->StepReturnValues[nsteps - 1][5];
if (tm && StepMaxTime < tm) StepMaxTime = tm;
tm = epd3->StepReturnValues[nsteps - 1][4];
if (tm && StepMaxTime < tm) StepMaxTime = tm;
2024-09-04 13:05:16 +02:00
}
}
else {
if (StepReturnValues != nullptr) StepReturnValues->Clear();
StepMaxTime = 0;
}
2024-09-04 13:05:16 +02:00
return nsteps;
}
int EpdBaseClr::Epd2::GetErrors()
{
2026-10-22 16:13:39 +02:00
if (epd3->errorm009 > 0 || epd3->errorm007 > 0 || epd3->errorm102 > 0 || epd3->errorm200 > 0 || epd3->errorm202 > 0 || epd3->error_other > 0) {
ErrorReturnValues = gcnew System::Collections::Generic::Dictionary<int, int>(5);
ErrorReturnValues->Add(-9, epd3->errorm009);
ErrorReturnValues->Add(-7, epd3->errorm007);
ErrorReturnValues->Add(-102, epd3->errorm102);
2026-10-22 16:13:39 +02:00
ErrorReturnValues->Add(-200, epd3->errorm200);
ErrorReturnValues->Add(-202, epd3->errorm202);
ErrorReturnValues->Add(-999, epd3->error_other);
}
else if (ErrorReturnValues != nullptr) ErrorReturnValues->Clear();
return 1;
}
2026-08-02 16:00:16 +02:00
void EpdBaseClr::Epd2::OnProgress(EpdSteps step, EpdStepResults result)
{
// Handle the progress info here (e.g., print or log it)
2026-08-02 16:00:16 +02:00
System::Console::WriteLine("Step: " + ((int)step).ToString() + ", Result: " + ((int)result).ToString());
if (_EpdProgress) {
2026-08-17 12:14:32 +02:00
_EpdProgress(this, step, result);
Sleep(100);
2026-08-02 16:00:16 +02:00
}
}
2022-04-20 16:56:49 +02:00
EpdBaseClr::Epd2::Epd2(int port, bool OnlyMK2)
2019-02-01 17:35:18 +01:00
{
2021-05-26 16:20:40 +02:00
EpdID = 0;
2021-05-31 15:20:16 +02:00
isMK3 = EPDIssued = isBG = 0;
2022-04-20 16:56:49 +02:00
onlyMK2 = OnlyMK2;
2021-03-26 17:20:57 +01:00
epd = new EpdBase::Epd2U(port);
2024-05-16 15:56:07 +02:00
if (!OnlyMK2) {
epd3 = new Epd3Base::Epd3U(port);
if (epd3) epd3->WriteConfig32 = 0;
}
else epd3 = nullptr;
2019-02-01 17:35:18 +01:00
this->InitRV = epd->InitRv;
2021-06-03 08:37:02 +02:00
Hp10Name = gcnew String(tHp10);
Hp07Name = gcnew String(tHp07);
isTitleNG = false;
2026-09-21 17:47:14 +02:00
SelftestMinutes = 0;
BatNoLoad_mV = BatLoad_mV = Cpu_mV = MaxBaud= 0;
progressDelegate = gcnew ProgressCallbackDelegate(this,&Epd2::OnProgress);
IntPtr ip = System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(progressDelegate);
/* epd3->postgre
epd3->ProgressCallback = static_cast<ProgressCallback>(ip.ToPointer());
epd3.prog*/
if (epd3 != nullptr) {
epd3->progressCallback = static_cast<Epd3Base::Epd3U::ProgressCallback>(ip.ToPointer());
epd3->test();
}
2026-08-02 16:00:16 +02:00
if (epd != nullptr) {
epd->progressCallback = static_cast<EpdBase::Epd2U::ProgressCallback>(ip.ToPointer());
epd->test();
}
StepMaxTime = 0;
2019-02-01 17:35:18 +01:00
}
2019-02-04 11:48:08 +01:00
EpdBaseClr::Epd2::~Epd2()
{
2021-05-26 16:20:40 +02:00
if (epd != nullptr) {
2021-05-28 17:06:41 +02:00
epd->EndCom();
delete epd;
epd = nullptr;
}
if (epd3 != nullptr) {
2024-09-05 16:10:29 +02:00
epd3->EndCom(true);
2021-05-28 17:06:41 +02:00
delete epd3;
epd3 = nullptr;
2021-05-26 16:20:40 +02:00
}
2019-02-04 11:48:08 +01:00
this->!Epd2();
2026-10-14 12:44:18 +02:00
if (logFile) {
if (logFile->is_open()) {
logFile->close();
}
delete logFile;
logFile = nullptr;
}
2019-02-04 11:48:08 +01:00
}
2019-02-04 11:48:08 +01:00
EpdBaseClr::Epd2::!Epd2()
{
}
2021-06-02 13:54:22 +02:00
int EpdBaseClr::Epd2::SetFeedbackSound(byte sound, UINT16 sound3)
{
epd->EndSessionControl = sound;
2022-04-20 16:56:49 +02:00
if (epd3!=nullptr) epd3->EndSessionControl = sound3;
return 0;
}
2021-05-12 12:35:50 +02:00
/// <summary>
/// find Epd
/// </summary>
/// <param name="reinit"></param>
2021-05-26 16:20:40 +02:00
/// <returns>0 = success </returns>
2021-05-12 12:35:50 +02:00
int EpdBaseClr::Epd2::Connect(bool reinit, int EPDTimeout)
2019-02-01 17:35:18 +01:00
{
2021-05-26 16:20:40 +02:00
int rv = 1;
2020-02-05 14:21:53 +01:00
ConnectError = 0;
2021-05-26 16:20:40 +02:00
EpdID= 0;
2020-02-18 14:06:52 +01:00
DeviceCount = 0;
2021-03-26 17:20:57 +01:00
DiscRV = 0;
if (epd != nullptr) {
if (epd->CommsInitialized == 0) epd->StartCom();
2025-12-04 06:35:41 +01:00
if (epd->CommsInitialized == 1) {
DiscRV = epd->StartDiscover(EPDTimeout);
if (DiscRV == 1)
{
DeviceCount = epd->DeviceCount;
if (epd->DeviceCount > 0) {
EpdID = epd->DeviceIDs[0]; rv = 0;
}
else rv = 1; //Nothing discoverd
}
else {
rv = 2; //discover failed
ConnectError = epd->Error;
2021-05-26 16:20:40 +02:00
}
2021-03-26 17:20:57 +01:00
}
else {
2025-12-04 06:35:41 +01:00
rv = 3; //start com failed.
2021-03-26 17:20:57 +01:00
ConnectError = epd->Error;
}
2020-02-05 14:21:53 +01:00
}
2021-05-26 16:20:40 +02:00
return rv;
2019-02-01 17:35:18 +01:00
}
2019-02-04 11:48:08 +01:00
int EpdBaseClr::Epd2::Close()
{
//EpdID= 0;
2022-04-20 16:56:49 +02:00
if (epd != nullptr) epd->EndCom();
2024-09-05 16:10:29 +02:00
if (epd3 != nullptr) epd3->EndCom(true);
2019-02-04 11:48:08 +01:00
return 0;
}
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::DecodeStatus(Epd3Base::Epd3U* epd)
2020-02-18 14:06:52 +01:00
{
2024-05-29 16:08:18 +02:00
epd->DecodeStatus(); // set hasAlarm
2020-02-18 14:06:52 +01:00
//OperatingStatus
DetectorsOn = epd->DetectorsOn;
EPDIssued = epd->EPDIssued;
EPDLocked = epd->EPDLocked;
EPDTesting = epd->EPDTesting;
EPDProcSec = epd->EPDProcSec;
EPDFaulty = epd->EPDFaulty;
2025-01-09 12:47:42 +01:00
EPDTimeFault = epd->EPDTimeFault;
2026-09-04 20:29:47 +02:00
EPDDetectorTestRequested = epd->EPDDetectorTestRequested;
EPDDetectorTestPassed = epd->EPDDetectorTestPassed;
2020-02-18 14:06:52 +01:00
EPDNewFault = epd->EPDNewFault;
EPDComFault = epd->EPDComFault;
EPDCalFault = epd->EPDCalFault;
EPDDetFault = epd->EPDDetFault;
EPDEprFault = epd->EPDEprFault;
EPDTrhFault = epd->EPDTrhFault;
EPDOthFault = epd->EPDOthFault;
AlarmDoseHP101G = epd->AlarmDoseHP101G;
AlarmDoseHP102G = epd->AlarmDoseHP102G;
AlarmDoseHP07N = epd->AlarmDoseHP07N;
AlarmRateHP101G = epd->AlarmRateHP101G;
AlarmRateHP102G = epd->AlarmRateHP102G;
AlarmRateHP07N = epd->AlarmRateHP07N;
OtherAlarmRateHp101G = epd->OtherAlarmRateHp101G;
OtherAlarmRateHp102G = epd->OtherAlarmRateHp102G;
OtherAlarmRateHp07N = epd->OtherAlarmRateHp07N;
OtherAlarmReturn = epd->OtherAlarmReturn;
OtherAlarmBatLow = epd->OtherAlarmBatLow;
OtherAlarmCarrier = epd->OtherAlarmCarrier;
OtherAlarmBatVolt = epd->OtherAlarmBatVolt;
return 1;
}
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::DecodeStatus(EpdBase::Epd2U* epd)
{
epd->DecodeStatus();
//OperatingStatus
DetectorsOn = epd->DetectorsOn;
EPDIssued = epd->EPDIssued;
EPDLocked = epd->EPDLocked;
EPDTesting = epd->EPDTesting;
EPDProcSec = epd->EPDProcSec;
EPDFaulty = epd->EPDFaulty;
2025-01-09 12:47:42 +01:00
EPDTimeFault = 0;
2026-09-04 20:29:47 +02:00
EPDDetectorTestRequested = 0;
2020-02-18 14:06:52 +01:00
2021-05-28 17:06:41 +02:00
EPDNewFault = epd->EPDNewFault;
EPDComFault = epd->EPDComFault;
EPDCalFault = epd->EPDCalFault;
EPDDetFault = epd->EPDDetFault;
EPDEprFault = epd->EPDEprFault;
EPDTrhFault = epd->EPDTrhFault;
EPDOthFault = epd->EPDOthFault;
AlarmDoseHP101G = epd->AlarmDoseHP101G;
AlarmDoseHP102G = epd->AlarmDoseHP102G;
AlarmDoseHP07N = epd->AlarmDoseHP07N;
AlarmRateHP101G = epd->AlarmRateHP101G;
AlarmRateHP102G = epd->AlarmRateHP102G;
AlarmRateHP07N = epd->AlarmRateHP07N;
OtherAlarmRateHp101G = epd->OtherAlarmRateHp101G;
OtherAlarmRateHp102G = epd->OtherAlarmRateHp102G;
OtherAlarmRateHp07N = epd->OtherAlarmRateHp07N;
OtherAlarmReturn = epd->OtherAlarmReturn;
OtherAlarmBatLow = epd->OtherAlarmBatLow;
OtherAlarmCarrier = epd->OtherAlarmCarrier;
OtherAlarmBatVolt = epd->OtherAlarmBatVolt;
return 1;
}
2021-05-26 16:20:40 +02:00
/// <summary>
///
/// </summary>
/// <returns>0=success</returns>
2019-02-01 17:35:18 +01:00
int EpdBaseClr::Epd2::GetStatus()
{
2021-05-26 16:20:40 +02:00
int rv = 1;
2020-02-05 14:21:53 +01:00
StatusRV = epd->ReadStatus();
2021-05-27 16:13:53 +02:00
if (StatusRV != 1) GetStatusError = epd->Error; else GetStatusError= rv = 0;
2021-05-28 17:06:41 +02:00
AfterGetStatus(epd);
2021-05-27 16:13:53 +02:00
return rv;
}
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::AfterGetStatus(EpdBase::Epd2U *epd)
2021-05-27 16:13:53 +02:00
{
2021-05-28 17:06:41 +02:00
isMK3 = false;
2021-05-31 15:20:16 +02:00
EPDIssued = epd->EPDIssued;
2021-05-27 16:13:53 +02:00
WearerID = gcnew String((char*)epd->WearerID);
WearerName = gcnew String((char*)epd->WearerName);
2019-02-01 17:35:18 +01:00
isOn = (epd->DetectorsOn != 0);
2019-02-04 11:48:08 +01:00
epdType = epd->EpdType;
2021-06-02 13:54:22 +02:00
isBG = epd->isBG;
isNG = epd->isNG;
VersionOK = epd->VersionOK ;
//isBG = (epd->EpdType == 0 || epd->EpdType == 4); //MK2 BG=0 or MK3 BG=4 3=MK2 Neuruon 7=MK3 neutron
2019-02-04 11:48:08 +01:00
alarmStatus = epd->AlarmStatus;
otherAlarms = epd->OtherAlarms;
errorStatus = epd->ErrorStatus;
operatingStatus = epd->OperatingStatus;
2026-09-04 20:29:47 +02:00
EPDDetectorTestRequested = 0;
2024-05-29 16:08:18 +02:00
//hasAlarm = epd->hasAlarm; //?1
eDoshasAlarm = epd->hasAlarm;
eDosHasFault = epd->hasFault;
2026-10-14 12:44:18 +02:00
//EpdID = epd->EpdID;
//EpdID = epd3->Epd.Id; no!
2024-05-28 08:09:23 +02:00
HardVersion = epd->HardVersion / 100;
HardVersionMinor = epd->HardVersion % 100;
2021-05-27 16:13:53 +02:00
SoftVersion = epd->SoftVersion;
int VersionMajor = 1;
int VersionMinor = 5;
// Formats as "1.5"
2026-10-22 16:13:39 +02:00
HardwareVersion = String::Format("{0}.{0}", HardVersion, HardVersionMinor);
FirmwareVersion = String::Format("{0}", epd->SoftVersion);
2019-02-04 11:48:08 +01:00
FunctionFlags = epd->FunctionFlags;
2021-04-22 16:52:44 +02:00
CountsClock = epd->EpdClock;
2021-05-28 17:06:41 +02:00
DecodeStatus(epd);
2021-05-27 16:13:53 +02:00
return 0;
2019-02-01 17:35:18 +01:00
}
2024-05-29 16:08:18 +02:00
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::AfterGetStatus(Epd3Base::Epd3U* epd)
{
2021-05-31 15:20:16 +02:00
EPDIssued= epd->EPDIssued;
2021-05-28 17:06:41 +02:00
WearerID = gcnew String((char*)epd->WearerID);
WearerName = gcnew String((char*)epd->WearerName);
isOn = (epd->DetectorsOn != 0);
epdType = (int)epd->EpdType;
isBG = (epd->EpdType == EpdTypes::Mk2BetaGamma || epd->EpdType == EpdTypes::Mk3BetaGamma); //MK2 BG=0 or MK3 BG=4 3=MK2 Neuruon 7=MK3 neutron
2021-06-02 13:54:22 +02:00
isNG = epd->isNG;
VersionOK = epd->VersionOK;
2021-05-28 17:06:41 +02:00
isMK3 = epd->isMK3;
alarmStatus = (int)epd->AlarmStatus;
otherAlarms = (int)epd->OtherAlarms;
errorStatus = (int)epd->ErrorStatus;
operatingStatus = (int)epd->OperatingStatus;
2026-09-04 20:29:47 +02:00
EPDDetectorTestRequested = epd->EPDDetectorTestRequested;
2024-05-29 16:08:18 +02:00
eDoshasAlarm = epd->hasAlarm;
eDosHasFault = epd->hasFault;
EpdID = epd->Epd.Id;
2021-05-28 17:06:41 +02:00
HardVersion = epd->HardVersion;
2024-05-22 13:31:10 +02:00
HardVersionMinor = epd->HardVersionMinor;
2021-05-28 17:06:41 +02:00
SoftVersion = epd->SoftVersion;
FunctionFlags = epd->FunctionFlags;
CountsClock = epd->EpdClock;
2026-01-07 14:16:45 +01:00
//hier nodig ?
2026-10-22 16:13:39 +02:00
HardwareVersion = String::Format("{0}.{1}", epd->HardVersion, epd->HardVersionMinor);
FirmwareVersion = String::Format("{0}.{1}.{2}.{3}", epd->SoftVersion, epd->SoftVersionMinor,epd->SoftVersionPatch,epd->SoftVersionBuild);
2024-05-29 16:08:18 +02:00
DecodeStatus( epd); // zet hasAlarm
2021-05-28 17:06:41 +02:00
return 0;
}
int EpdBaseClr::Epd2::AfterGetStatus()
{
int rv = 0;
if (isMK3) rv=AfterGetStatus(epd3);
else rv=AfterGetStatus(epd);
return rv;
}
/// <summary>
///
/// </summary>
/// <returns>0 OK</returns>
int EpdBaseClr::Epd2::GetDoses()
{
int rv = 0;
if (isMK3)
rv = GetDoses(epd3);
else
rv = GetDoses(epd);
return rv;
}
int EpdBaseClr::Epd2::GetDoses(EpdBase::Epd2U* epd)
2019-02-01 17:35:18 +01:00
{
2021-05-28 17:06:41 +02:00
int rv = 1;
2019-02-01 17:35:18 +01:00
Hp10 = Hp07 = 0.0;
2019-02-04 11:48:08 +01:00
ReadDosesRV = epd->ReadDoses();
if (ReadDosesRV == 1) {
2021-06-01 16:35:24 +02:00
rv = AfterGetDoses(epd);
2020-02-05 14:21:53 +01:00
}
else {
2021-05-28 17:06:41 +02:00
rv = 1;
2020-02-05 14:21:53 +01:00
GetDosesError = epd->Error;
2019-02-04 11:48:08 +01:00
}
2021-06-01 16:35:24 +02:00
return rv;
}
int EpdBaseClr::Epd2::AfterGetDoses(Epd3Base::Epd3U* epd)
{
2024-05-29 16:08:18 +02:00
eDoshasAlarm = eDosHasFault = false;
2021-06-01 16:35:24 +02:00
int rv = 0;
rv = 0;
GetDosesError = 0;
Hp10 = (double)epd->Hp10Dose;
Hp07 = (double)epd->Hp07Dose;
Hp07Peak = (double)epd->Hp07Peak;
Hp10Peak = (double)epd->Hp10Peak;
Hp07Total = epd->Hp07Total;
Hp10Total = epd->Hp10Total;
2019-02-04 11:48:08 +01:00
2021-06-01 16:35:24 +02:00
if (epd->Hp10FTime != 0) {
//seconds since 2000 ?
//double x = (epd->EpdClock - epd->Hp10Time) * -1.0;
Hp10PeakTime = System::DateTime::FromFileTime(epd->Hp10FTime);
//Hp10PeakTime = Jan2000->AddSeconds(epd->Hp10Time);
2021-04-16 10:38:48 +02:00
}
2021-05-28 17:06:41 +02:00
else
2019-02-12 07:33:18 +01:00
Hp10PeakTime = System::Nullable<System::DateTime>();;
2021-06-01 16:35:24 +02:00
if (epd->Hp07FTime != 0) {
//double x = (epd->EpdClock - epd->Hp07Time) * -1.0;
Hp07PeakTime = System::DateTime::FromFileTime(epd->Hp07FTime);
//Hp07PeakTime = Jan2000->AddSeconds(epd->Hp07Time);
2021-04-16 10:38:48 +02:00
}
2019-02-12 07:33:18 +01:00
else
2021-06-01 16:35:24 +02:00
Hp07PeakTime = System::Nullable<System::DateTime>();
2019-02-12 07:33:18 +01:00
2019-02-11 11:34:52 +01:00
QualityData = epd->QualityData;
2023-05-23 10:41:18 +02:00
K1 = (int)epd->K1;
K2 = (int)epd->K2;
K3 = (int)epd->K3;
K4 = (int)epd->K4;
K5 = (int)epd->K5;
K6 = (int)epd->K6;
SG = (int)epd->SG;
2019-02-11 11:34:52 +01:00
BC = epd->SG;
FB = epd->FB;
HG = epd->HG;
2026-01-07 14:16:45 +01:00
//NGgain = K3;
NGgain = epd->GainAn;
2022-04-12 14:28:14 +02:00
eDosDose07Warning = epd->eDosDose07Warning;
eDosDose07Alarm= epd->eDosDose07Alarm;
eDosDose10Warning = epd->eDosDose10Warning;
eDosDose10Alarm = epd->eDosDose10Alarm;
eDosRate07Warning = epd->eDosRate07Warning;
eDosRate07Alarm = epd->eDosRate07Alarm;
eDosRate10Warning = epd->eDosRate10Warning;
eDosRate10Alarm = epd->eDosRate10Alarm;
eDosBatteryWarning = epd->eDosBatteryWarning;
2022-04-26 08:43:13 +02:00
eDoshasAlarm = epd->hasAlarm;
eDosHasFault = epd->hasFault;
2021-05-28 17:06:41 +02:00
return rv;
2019-02-04 11:48:08 +01:00
}
2021-05-28 17:06:41 +02:00
/// <summary>
///
/// </summary>
/// <param name="epd"></param>
/// <returns>0 OK</returns>
int EpdBaseClr::Epd2::GetDoses(Epd3Base::Epd3U* epd)
{
int rv = 1;
Hp10 = Hp07 = 0.0;
2024-05-29 16:08:18 +02:00
int ReadDosesRV = epd->ReadDoses(); //0 = succes
2021-05-28 17:06:41 +02:00
if (ReadDosesRV == 0) {
2021-06-01 16:35:24 +02:00
rv = AfterGetDoses(epd3);
}
2021-05-28 17:06:41 +02:00
else {
rv = 1;
GetDosesError = epd->Error;
}
return rv;
}
2022-03-17 08:57:22 +01:00
int EpdBaseClr::Epd2::ClearAlarms()
{
int rv = 0;
if (isMK3) rv = epd3->ClearAlarms();
else rv = epd->ClearAlarms();
return rv;
}
2021-05-28 17:06:41 +02:00
/// <summary>
///
/// </summary>
/// <returns>0 OK</returns>
2024-08-28 13:05:03 +02:00
//int EpdBaseClr::Epd2::SetDeIssued()
//{
// int rv = 0;
// ErrorStep = 0; ErrorRV = 0;
// if (isMK3) {
// rv = epd3->DeIssue();
// ErrorStep = epd3->ErrorStep;
// ErrorRV = epd3->Error;
// }
// else rv = epd->DeIssue();
// return rv;
//}
2022-09-06 15:44:32 +02:00
2024-08-28 13:05:03 +02:00
//int EpdBaseClr::Epd2::PrepareForIssue()
//{
// int rv = 0;
// PrepareForIssueError = 0;
// ErrorStep = 0; ErrorRV = 0;
// if (isMK3) {
// rv = epd3->PrepareForIssue();
// ErrorStep = epd3->ErrorStep;
// ErrorRV = epd3->Error;
// }
// else rv= epd->PrepareForIssue();
// if (rv != 0) PrepareForIssueError = epd->Error;
// return rv;
//}
2021-05-28 17:06:41 +02:00
/// <summary>
2024-08-28 13:05:03 +02:00
/// should not be used
2021-05-28 17:06:41 +02:00
/// </summary>
/// <returns>0 OK</returns>
2024-08-28 13:05:03 +02:00
//int EpdBaseClr::Epd2::SetIssued()
//{
// int rv = 0;
// ErrorStep = 0; ErrorRV = 0;
// if (isMK3) {
// rv=SetIssued(epd3);
// ErrorStep = epd3->ErrorStep;
// ErrorRV = epd3->Error;
// }
// else rv=SetIssued(epd);
// return rv;
//}
/// <summary>
/// BeforeSetIssued : geen interactie met epd, maar zet varibaleln
/// </summary>
/// <param name="epd"></param>
/// <returns></returns>
2021-06-02 13:54:22 +02:00
int EpdBaseClr::Epd2::BeforeSetIssued(Epd3Base::Epd3U* epd)
2021-05-28 17:06:41 +02:00
{
int rv = 0;
SetIssuedError = 0;
2023-05-23 10:41:18 +02:00
epd->Hp07THDose = (float)Hp07THDose;
2024-05-22 13:31:10 +02:00
epd->Hp10THDose1 = (float)Hp10THDose1;
epd->Hp10THDose2 = (float)Hp10THDose2;
2021-05-28 17:06:41 +02:00
2024-05-22 13:31:10 +02:00
epd->Hp10Rate1On = (float)Hp10Rate1On;
epd->Hp10Rate2On = (float)Hp10Rate2On;
epd->Hp07RateOn = (float)Hp07RateOn;
epd->Hp10Rate1Off = (float)Hp10Rate1Off;
epd->Hp10Rate2Off = (float)Hp10Rate2Off;
epd->Hp07RateOff = (float)Hp07RateOff;
2021-06-02 13:54:22 +02:00
2021-05-28 17:06:41 +02:00
memset(epd->WearerID, ' ', WearerIDLength); epd->WearerID[WearerIDLength] = 0;
2021-06-02 13:54:22 +02:00
char* str1 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerID);
2021-05-28 17:06:41 +02:00
int l = strlen(str1);
if (l > WearerIDLength) l = WearerIDLength;
2021-06-02 13:54:22 +02:00
_memccpy(epd->WearerID + WearerIDLength - l, str1, l, WearerIDLength);
2021-05-28 17:06:41 +02:00
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str1);
memset(epd->WearerName, 0, WearerNameLength + 1);
char* str2 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerName);
l = strlen(str2);
if (l > WearerNameLength) l = WearerNameLength;
_memccpy(epd->WearerName, str2, l, WearerNameLength);
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
2021-06-02 13:54:22 +02:00
return 0;
}
/// <summary>
///
/// </summary>
/// <param name="epd"></param>
/// <returns>0 success</returns>
2024-08-28 13:05:03 +02:00
//int EpdBaseClr::Epd2::SetIssued(Epd3Base::Epd3U* epd)
//{
// int rv = 0;
// rv = BeforeSetIssued(epd);
// rv = epd->Issue(false);
// if (rv != 0) SetIssuedError = epd->Error;
// return rv;
//}
2021-06-02 13:54:22 +02:00
int EpdBaseClr::Epd2::BeforeSetIssued(EpdBase::Epd2U* epd)
2021-05-28 17:06:41 +02:00
{
int rv = 0;
2020-02-05 14:21:53 +01:00
SetIssuedError = 0;
2021-05-28 17:06:41 +02:00
epd->Hp07THDose = (DWORD)(Hp07THDose * 64.0);
epd->Hp10THDose1 = (DWORD)(Hp10THDose1 * 64.0);
epd->Hp10THDose2 = (DWORD)(Hp10THDose2 * 64.0);
2021-04-16 10:38:48 +02:00
epd->Hp10Rate1On = (DWORD)(Hp10Rate1On);
epd->Hp10Rate2On = (DWORD)(Hp10Rate2On);
epd->Hp07RateOn = (DWORD)(Hp07RateOn);
2022-04-12 14:28:14 +02:00
2021-04-16 10:38:48 +02:00
epd->Hp10Rate1Off = (DWORD)(Hp10Rate1Off);
epd->Hp10Rate2Off = (DWORD)(Hp10Rate2Off);
epd->Hp07RateOff = (DWORD)(Hp07RateOff);
2021-05-28 17:06:41 +02:00
2019-02-01 17:35:18 +01:00
memset(epd->WearerID, ' ', WearerIDLength); epd->WearerID[WearerIDLength] = 0;
2021-05-28 17:06:41 +02:00
char* str1 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerID);
2019-02-01 17:35:18 +01:00
int l = strlen(str1);
if (l > WearerIDLength) l = WearerIDLength;
2021-05-28 17:06:41 +02:00
_memccpy(epd->WearerID + WearerIDLength - l, str1, l, WearerIDLength);
2019-02-01 17:35:18 +01:00
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str1);
memset(epd->WearerName, 0, WearerNameLength + 1);
char* str2 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerName);
2019-02-11 11:34:52 +01:00
l = strlen(str2);
if (l > WearerNameLength) l = WearerNameLength;
_memccpy(epd->WearerName, str2, l, WearerNameLength);
2019-02-01 17:35:18 +01:00
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
2021-05-28 17:06:41 +02:00
2021-06-02 13:54:22 +02:00
return 0;
}
2024-08-28 13:05:03 +02:00
//int EpdBaseClr::Epd2::SetIssued(EpdBase::Epd2U* epd)
//{
// int rv = 0;
// BeforeSetIssued(epd);
// rv = epd->Issue();
// if (rv != 0) SetIssuedError = epd->Error;
// return rv;
//}
2019-02-12 16:01:47 +01:00
int EpdBaseClr::Epd2::WriteCalibration()
2021-05-28 17:06:41 +02:00
{
int rv = 0;
if (isMK3) rv = WriteCalibration(epd3);
else rv = WriteCalibration(epd);
return rv;
}
int EpdBaseClr::Epd2::WriteCalibration(EpdBase::Epd2U* epd)
2019-02-12 16:01:47 +01:00
{
2019-02-14 15:56:23 +01:00
epd->K1 = K1;
epd->K2 = K2;
2019-02-12 16:01:47 +01:00
epd->K3 = K3;
epd->K4 = K4;
2019-02-14 15:56:23 +01:00
epd->K5 = K5;
epd->K6 = K6;
//epd->K1 = 903;
//epd->K2 = 613;
//epd->K5 = 13100;
//epd->K6 = 1310;
int rv = epd->WriteCal();
2019-02-12 16:01:47 +01:00
return rv;
}
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::WriteCalibration(Epd3Base::Epd3U* epd)
{
2022-02-24 09:04:31 +01:00
epd->K1 = (float)K1;
epd->K2 = (float)K2;
2021-05-28 17:06:41 +02:00
2022-02-24 09:04:31 +01:00
epd->K3 = (float)K3;
epd->K4 = (float)K4;
2021-05-28 17:06:41 +02:00
2022-02-24 09:04:31 +01:00
epd->K5 = (float)K5;
epd->K6 = (float)K6;
2021-05-28 17:06:41 +02:00
//epd->K1 = 903;
//epd->K2 = 613;
//epd->K5 = 13100;
//epd->K6 = 1310;
int rv = epd->WriteCal();
return rv;
}
/// <summary>
///
/// </summary>
/// <returns>0=success</returns>
2019-02-04 11:48:08 +01:00
int EpdBaseClr::Epd2::ReadTresholds()
2021-05-28 17:06:41 +02:00
{
int rv = 0;
if (isMK3)
rv = ReadTresholds(epd3);
else
rv = ReadTresholds(epd);
return rv;
}
2021-06-01 16:35:24 +02:00
int EpdBaseClr::Epd2::AfterReadTresholds(EpdBase::Epd2U* epd)
{
int rv = 0;
2019-02-04 11:48:08 +01:00
Hp10THDose1 = (double)epd->Hp10THDose1 / 64.0;
Hp10THDose2 = (double)epd->Hp10THDose2 / 64.0;
Hp07THDose = (double)epd->Hp07THDose / 64.0;
2021-05-28 17:06:41 +02:00
Hp10Rate1On = (double)epd->Hp10Rate1On;
Hp10Rate2On = (double)epd->Hp10Rate2On;
Hp07RateOn = (double)epd->Hp07RateOn;
2022-04-12 14:28:14 +02:00
2021-05-28 17:06:41 +02:00
Hp10Rate1Off = (double)epd->Hp10Rate1Off;
Hp10Rate2Off = (double)epd->Hp10Rate2Off;
Hp07RateOff = (double)epd->Hp07RateOff;
K1 = epd->K1;
K2 = epd->K2;
K3 = epd->K3;
K4 = epd->K4;
K5 = epd->K5;
K6 = epd->K6;
SG = epd->SG;
BC = epd->BC;
FB = epd->FB;
HG = epd->HG;
2026-01-07 14:16:45 +01:00
NGgain = K3; //EPD2
2021-06-03 08:37:02 +02:00
2021-05-28 17:06:41 +02:00
return rv;
2021-06-01 16:35:24 +02:00
2021-05-28 17:06:41 +02:00
}
/// <summary>
///
/// </summary>
/// <param name="epd"></param>
2021-06-01 16:35:24 +02:00
/// <returns>0 = Success</returns>
int EpdBaseClr::Epd2::ReadTresholds(EpdBase::Epd2U* epd)
2021-05-28 17:06:41 +02:00
{
ReadTresholdsError = 0;
2021-06-01 16:35:24 +02:00
int rv = epd->ReadTresHolds();
2021-05-28 17:06:41 +02:00
if (rv != 0) ReadTresholdsError = epd->Error;
2021-06-01 16:35:24 +02:00
rv = AfterReadTresholds(epd);
return rv;
}
int EpdBaseClr::Epd2::AfterReadTresholds(Epd3Base::Epd3U* epd)
{
int rv = 0;
Hp10THDose1 = (double)epd->Hp10THDose1;
Hp10THDose2 = (double)epd->Hp10THDose2;
Hp07THDose = (double)epd->Hp07THDose;
2019-02-04 11:48:08 +01:00
Hp10Rate1On = (double)epd->Hp10Rate1On;
2021-06-01 16:35:24 +02:00
Hp10Rate2On = (double)epd->Hp10Rate2On;
Hp07RateOn = (double)epd->Hp07RateOn;
Hp10Rate1Off = (double)epd->Hp10Rate1Off;
Hp10Rate2Off = (double)epd->Hp10Rate2Off;
Hp07RateOff = (double)epd->Hp07RateOff;
Hp10Total = (double)epd->Hp10Total;
Hp07Total = (double)epd->Hp07Total;
2022-02-24 09:04:31 +01:00
K1 = (int)epd->K1;
2024-05-22 13:31:10 +02:00
K2 = (int)epd->K2;
K3 = (int)epd->K3;
K4 = (int)epd->K4;
K5 = (int)epd->K5;
2022-02-24 09:04:31 +01:00
K6 = (int)epd->K6;
2019-02-04 11:48:08 +01:00
SG = epd->SG;
BC = epd->BC;
FB = epd->FB;
HG = epd->HG;
2026-01-07 14:16:45 +01:00
NGgain = epd->GainAn; //K3 vroeger
2020-02-05 14:21:53 +01:00
return rv;
2019-02-12 16:01:47 +01:00
}
2021-05-31 15:20:16 +02:00
/// <summary>
///
/// </summary>
2021-06-01 16:35:24 +02:00
/// <param name="epd"></param>
/// <returns>0 Success</returns>
int EpdBaseClr::Epd2::ReadTresholds(Epd3Base::Epd3U* epd)
{
int rv = 0;
ReadTresholdsError = 0;
rv= epd->ReadAlarmTresholds();
rv = epd->ReadSensitivitiesAndTresholds();
if (rv != 0) ReadTresholdsError = epd->Error;
rv = AfterReadTresholds(epd);
return rv;
}
/// <summary>
///
/// </summary>
2021-05-31 15:20:16 +02:00
/// <returns>0=Success</returns>
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::ReadExtraStatus()
{
int rv = 0;
if (isMK3) rv = ReadExtraStatus(epd3);
else rv = ReadExtraStatus(epd);
return rv;
}
int EpdBaseClr::Epd2::ReadExtraStatus(EpdBase::Epd2U* epd)
2019-02-12 16:01:47 +01:00
{
int rv = epd->EPDReadExtraStatus();
BatADC = epd->byBatADC;
SupplyADC = epd->bySupplyADC;
2019-02-14 15:56:23 +01:00
D1 = epd->D1 - epd->BaseD1;
D2 = epd->D2 - epd->BaseD2;
D3 = epd->D3 - epd->BaseD3;
D4 = epd->D4 - epd->BaseD4;
CountsClock = epd->CountsClock;
2021-04-22 16:52:44 +02:00
CountsClockBase = epd->BaseCountsClock;
2019-02-14 15:56:23 +01:00
2019-02-12 16:01:47 +01:00
return rv;
2021-05-26 16:20:40 +02:00
}
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::ReadExtraStatus(Epd3Base::Epd3U* epd)
{
int rv = epd->EPDReadExtraStatus();
BatADC = 0; //epd->byBatADC;
SupplyADC = 0; // epd->bySupplyADC;
2021-05-26 16:20:40 +02:00
2021-05-28 17:06:41 +02:00
D1 = epd->D1 - epd->BaseD1;
D2 = epd->D2 - epd->BaseD2;
D3 = epd->D3 - epd->BaseD3;
D4 = epd->D4 - epd->BaseD4;
CountsClock = epd->CountsClock;
CountsClockBase = epd->BaseCountsClock;
return rv;
}
2024-05-22 13:31:10 +02:00
int EpdBaseClr::Epd2::AfterGetDoses(EpdBase::Epd2U* epd)
2021-06-01 16:35:24 +02:00
{
2022-04-26 08:43:13 +02:00
eDoshasAlarm = eDosHasFault = false;
2022-04-12 14:28:14 +02:00
int rv = 0;
GetDosesError = 0;
Hp10 = (double)epd->Hp10Dose / 64.0;
Hp07 = (double)epd->Hp07Dose / 64.0;
Hp07Peak = (double)epd->Hp07Peak; // / niet delen door 64 !!!
Hp10Peak = (double)epd->Hp10Peak; // / niet delen door 64 !!!
Hp07Total = epd->Hp07Total / 64.0;
Hp10Total = epd->Hp10Total / 64.0;
2021-06-01 16:35:24 +02:00
if (epd->Hp10FTime != 0) {
try {
Hp10PeakTime = System::DateTime::FromFileTime(epd->Hp10FTime);
}
catch (System::Exception^ ex) {
2022-04-12 14:28:14 +02:00
Hp10PeakTime = System::Nullable<System::DateTime>();
2021-06-01 16:35:24 +02:00
}
//double x = (epd->EpdClock - epd->Hp10Time) * -1.0;
//Hp10PeakTime = System::DateTime::Now.AddSeconds(x);
}
else
Hp10PeakTime = System::Nullable<System::DateTime>();
if (epd->Hp07FTime != 0) {
try {
2022-04-12 14:28:14 +02:00
Hp07PeakTime = System::DateTime::FromFileTime(epd->Hp07FTime);
2021-06-01 16:35:24 +02:00
}
catch (System::Exception^ ex) {
Hp10PeakTime = System::Nullable<System::DateTime>();
}
//double x = (epd->EpdClock - epd->Hp07Time) * -1.0;
//Hp07PeakTime = System::DateTime::Now.AddSeconds(x);
}
else
Hp10PeakTime = System::Nullable<System::DateTime>();
QualityData = epd->QualityData;
K1 = epd->K1;
K2 = epd->K2;
K3 = epd->K3;
K4 = epd->K4;
K5 = epd->K5;
K6 = epd->K6;
SG = epd->SG;
BC = epd->SG;
FB = epd->FB;
HG = epd->HG;
2021-06-03 08:37:02 +02:00
NGgain = K3;
2022-04-12 14:28:14 +02:00
eDosDose07Warning = epd->eDosDose07Warning;
eDosDose07Alarm = epd->eDosDose07Alarm;
eDosDose10Warning = epd->eDosDose10Warning;
eDosDose10Alarm = epd->eDosDose10Alarm;
eDosRate07Warning = epd->eDosRate07Warning;
eDosRate07Alarm = epd->eDosRate07Alarm;
eDosRate10Warning = epd->eDosRate10Warning;
eDosRate10Alarm = epd->eDosRate10Alarm;
eDosBatteryWarning = epd->eDosBatteryWarning;
2022-04-26 08:43:13 +02:00
eDoshasAlarm = epd->hasAlarm;
eDosHasFault = epd->hasFault;
2021-06-01 16:35:24 +02:00
return rv;
}
2022-04-12 14:28:14 +02:00
2021-06-01 16:35:24 +02:00
/// <summary>
/// Get Doses and tresholds, and close if requested
/// </summary>
/// <param name="close"></param>
/// <returns></returns>
int EpdBaseClr::Epd2::GetAll(bool close)
{
int rv = 0;
if (!isMK3) {
2026-10-08 16:25:43 +02:00
if (epd) {
rv = epd->GetAll(close);
rv = AfterGetDoses(epd);
rv = AfterReadTresholds(epd);
}
else rv = -1;
2021-06-01 16:35:24 +02:00
}
else
{
2026-10-08 16:25:43 +02:00
if (epd3) {
rv = epd3->GetAll(close);
rv = AfterGetDoses(epd3);
rv = AfterReadTresholds(epd3);
}
else rv = -1;
2021-06-01 16:35:24 +02:00
}
return rv;
}
// Main entry point for exit
2024-05-22 13:31:10 +02:00
int EpdBaseClr::Epd2::GetAllDeissue(bool reconnect)
2021-06-01 16:35:24 +02:00
{
2024-05-22 13:31:10 +02:00
ErrorRV = ErrorStep = 0;
2021-06-01 16:35:24 +02:00
int rv = 0;
if (!isMK3) {
2026-10-08 16:25:43 +02:00
if (epd) {
rv = epd->GetAllDeissue();
rv = AfterGetDoses(epd);
rv = AfterReadTresholds(epd);
}
else rv = -1;
2021-06-01 16:35:24 +02:00
}
else
{
2026-10-08 16:25:43 +02:00
if (epd3) {
rv = epd3->GetAllDeissue(reconnect);
ErrorRV = epd3->Error;
ErrorStep = epd3->ErrorStep;
rv = AfterGetDoses(epd3);
rv = AfterReadTresholds(epd3);
}
else rv = -1;
2025-12-04 06:35:41 +01:00
2021-06-01 16:35:24 +02:00
}
return rv;
}
2021-06-02 13:54:22 +02:00
/// <summary>
/// Clear Doses, for Neutron : get and check K, Issue
/// </summary>
/// <param name="gain"></param>
/// <returns></returns>
int EpdBaseClr::Epd2::IssueAndCheck(float gain, float ChirpRate, bool WriteConfig)
2021-06-02 13:54:22 +02:00
{
int rv = 0;
if (!isMK3) {
2026-10-14 12:44:18 +02:00
LogMessage("IssueAndCheck: !isMK3 BeforeSetIssued");
2021-06-02 13:54:22 +02:00
BeforeSetIssued(epd);
2026-10-29 10:53:53 +01:00
2021-06-02 13:54:22 +02:00
rv = epd->IssueAndCheck(gain);
2026-10-14 12:44:18 +02:00
LogMessage("IssueAndCheck: !isMK3 rv={}",rv);
}
else {
2026-10-14 12:44:18 +02:00
LogMessage("IssueAndCheck: isMK3 BeforeSetIssued");
2024-09-04 13:05:16 +02:00
epd3->WriteConfig32 = WriteConfig;
2024-05-22 13:31:10 +02:00
BeforeSetIssued(epd3); //geen interactie met epd
2024-05-28 08:09:23 +02:00
rv = epd3->IssueAndCheck(gain, ChirpRate); // set step,error
EPDIssued = epd3->EPDIssued;
2026-10-14 12:44:18 +02:00
LogMessage("IssueAndCheck: isMK3 rv={}", rv);
2021-06-02 13:54:22 +02:00
}
return rv;
}
2021-05-28 17:06:41 +02:00
int EpdBaseClr::Epd2::SwitchCon()
{
int rv = 0;
if (isMK3) {
2022-04-08 15:41:46 +02:00
if (epd3->epdComsHandle != INVALID_HANDLE_VALUE) {
2026-10-08 16:25:43 +02:00
if (epd) epd->EndCom();
2022-04-26 08:43:13 +02:00
Sleep(500);
2022-03-08 16:23:49 +01:00
rv=epd3->StartCom();
2026-10-14 12:44:18 +02:00
LogMessage("SwitchCon: StartCom returned {}" , rv);
2021-05-28 17:06:41 +02:00
}
}
else {
2026-10-14 12:44:18 +02:00
int i = 0;
2021-05-28 17:06:41 +02:00
if (epd->CommsInitialized == 0) {
2026-10-14 12:44:18 +02:00
if (epd3)
epd3->EndCom(epd3->isConnected);
2022-04-26 08:43:13 +02:00
Sleep(500);
2021-05-31 15:20:16 +02:00
rv = epd->StartCom(); //0=ok
2026-10-14 12:44:18 +02:00
LogMessage("SwitchCon: StartCom returned {}", rv);
if (!rv) rv = epd->Open(EpdID);
LogMessage("SwitchCon: Open returned {}", rv);
if (!rv) rv = epd->ReadStatus();
LogMessage("SwitchCon: ReadStatus returned {}", rv);
2021-05-28 17:06:41 +02:00
}
}
return rv;
}
2021-05-27 16:13:53 +02:00
void EpdBaseClr::Epd2::InitData()
{
ConnectError = 0;
EpdID = 0;
DeviceCount = 0;
2021-05-31 15:20:16 +02:00
GetStatusError = 0; StatusRV = 0; EPDIssued = false;
2021-05-27 16:13:53 +02:00
WearerID = String::Empty;
WearerName = String::Empty;
isOn = 0;
epdType = 0;
isBG = 0;
alarmStatus = 0;
otherAlarms = 0;
errorStatus = 0;
operatingStatus = 0;
2024-05-22 13:31:10 +02:00
HardVersion = 0; HardVersionMinor = 0;
2021-05-27 16:13:53 +02:00
SoftVersion = 0;
FunctionFlags = 0;
CountsClock = 0;
ErrorStep = ErrorRV = 0;
ConnectError = 0; eDoshasAlarm = eDosHasFault = false;
ErrorEPD = EpdErrorCodes::EpdErrorNone;
2026-10-08 16:25:43 +02:00
2021-05-27 16:13:53 +02:00
}
2026-07-28 16:36:22 +02:00
//void EpdBaseClr::Epd2::OnCancelRequested()
//{
// if (cancelEvent != nullptr)
// {
// cancelEvent->Set();
// }
//}
2021-05-26 16:20:40 +02:00
/// <summary>
/// connect to Epd and read status
/// </summary>
2021-05-27 16:13:53 +02:00
/// <returns>0=success 1=Connect error 2=TO 3=StatusReadError</returns>
2021-05-26 16:20:40 +02:00
int EpdBaseClr::Epd2::ConnectAndStatus()
{
2024-05-29 16:08:18 +02:00
//0 = ok, 2=TO , anders error
2021-05-27 16:13:53 +02:00
int rv = 1;
2024-05-22 13:31:10 +02:00
int step = 0;
2026-07-28 16:36:22 +02:00
ErrorStep = ErrorRV = 0;
ConnectError = 0; eDoshasAlarm = eDosHasFault = false;
ErrorEPD = EpdErrorCodes::EpdErrorNone;
2022-04-08 15:41:46 +02:00
if (!onlyMK2) epd->EndCom(); //indien Mk2
2024-05-22 13:31:10 +02:00
2026-07-28 16:36:22 +02:00
try
{
InitData();
Sleep(100);
step = 1;
if (onlyMK2 || !epd3)
rv = epd->ConnectAndStatus(tokenSourceTimeout);
else
{
rv = epd3->ConnectAndStatus(tokenSourceTimeout);
2026-10-14 12:44:18 +02:00
2026-07-28 16:36:22 +02:00
ErrorStep = (int)epd3->EPDStep;
ErrorRV = (int)epd3->Error;
switch (epd3->DiscoverError) {
case Epd3Base::Epd3U::DiscoverErrorCodes::DiscoverErrorNone:
ErrorEPD = EpdErrorCodes::EpdErrorNone; break;
case Epd3Base::Epd3U::DiscoverErrorCodes::DiscoverErrorCancel:
ErrorEPD = EpdErrorCodes::EpdErrorCancel;
break;
case Epd3Base::Epd3U::DiscoverErrorCodes::DiscoverErrorTimeout:
ErrorEPD = EpdErrorCodes::EpdErrorTimeout;
break;
case Epd3Base::Epd3U::DiscoverErrorCodes::DiscoverErrorOther:
ErrorEPD = EpdErrorCodes::EpdErrorOther;
break;
case Epd3Base::Epd3U::DiscoverErrorCodes::DiscoverErrorConnecting:
ErrorEPD = EpdErrorCodes::EpdErrorConnecting;
break;
}
2026-10-14 12:44:18 +02:00
LogMessage("ConnectAndStatus: rv {} ErrorEPD {}", rv, (int)ErrorEPD);
2026-07-28 16:36:22 +02:00
}
}
2026-10-14 12:44:18 +02:00
catch (System::Exception^ e) {
std::string errorMsg = msclr::interop::marshal_as<std::string>(e->Message);
LogMessage("ConnectAndStatus: Exception occurred {}", errorMsg);
}
2026-07-28 16:36:22 +02:00
finally
{
2024-05-22 13:31:10 +02:00
}
2021-05-27 16:13:53 +02:00
if (rv==0) {
2022-04-08 15:41:46 +02:00
if (onlyMK2) {
DeviceCount = epd->DeviceCount;
EpdID = epd->EpdID;
if (epd3 != nullptr) epd3->Epd.Id = EpdID;
2022-04-08 15:41:46 +02:00
isMK3 = 0;
isBG = epd->isBG;
isNG = epd->isNG;
}
else {
DeviceCount = epd3->DeviceCount;
EpdID = epd3->Epd.Id;
2022-04-08 15:41:46 +02:00
isMK3 = epd3->isMK3;
isBG = epd3->isBG;
isNG = epd3->isNG;
2026-10-14 12:44:18 +02:00
epd->EpdID = epd3->Epd.Id;
2022-04-08 15:41:46 +02:00
}
2021-05-31 15:20:16 +02:00
if (isMK3) {
AfterGetStatus(epd3);
}
else {
2026-10-14 12:44:18 +02:00
2022-04-26 08:43:13 +02:00
if (!onlyMK2) rv = SwitchCon();
else rv= epd->ReadStatus();
2021-05-31 15:20:16 +02:00
AfterGetStatus(epd);
}
2021-06-03 08:37:02 +02:00
if (isTitleNG != isNG) {
if (isNG) {
Hp10Name = gcnew String(tHp10G); Hp07Name = gcnew String(tHp07N);
}
else {
Hp10Name = gcnew String(tHp10); Hp07Name = gcnew String(tHp07);
}
isTitleNG = isNG;
}
2021-05-26 16:20:40 +02:00
}
2022-05-04 10:51:37 +02:00
else {
2026-07-28 16:36:22 +02:00
if (epd3 == nullptr) ConnectError = 99;
else ConnectError = epd3->Error;
rv = ConnectError;
2024-05-22 13:31:10 +02:00
goto error;
2022-05-04 10:51:37 +02:00
}
2021-05-26 16:20:40 +02:00
return rv;
2026-07-28 16:36:22 +02:00
2024-05-22 13:31:10 +02:00
error:
ErrorStep = step;
ErrorRV = rv;
2026-10-14 12:44:18 +02:00
LogMessage("ConnectAndStatus: Error occurred step {} rv {} ErrorEPD {}", step, rv, (int)ErrorEPD);
2024-05-22 13:31:10 +02:00
return rv;
2021-05-26 16:20:40 +02:00
}
2024-05-29 16:08:18 +02:00
2021-05-26 16:20:40 +02:00
void EpdBaseClr::Epd2::WaitEpd()
{
int rv = 0; //start
2026-01-07 14:16:45 +01:00
int retriesLeft = readRetries;
2026-07-28 16:36:22 +02:00
2026-01-07 14:16:45 +01:00
do {
rv = ConnectAndStatus();
retriesLeft--;
} while (rv == 1);
2026-07-28 16:36:22 +02:00
2021-05-26 16:20:40 +02:00
if (rv == 0) {
2021-06-01 16:35:24 +02:00
if (_EpdRead != nullptr)
2026-01-07 14:16:45 +01:00
_EpdRead(this, gcnew EpdEventArgs(EpdID, EPDIssued, isBG, isMK3, retriesLeft));
2021-05-27 16:13:53 +02:00
}
else if (rv == 2 && _EpdTO != nullptr) {
2022-05-04 07:53:20 +02:00
_EpdTO(this, gcnew EpdTOEventArgs(0, 0)); // epd3->ConnectTries, epd3->ConnectTimerFired));
2021-05-27 16:13:53 +02:00
}
else if (rv > 0 && _EpdError != nullptr) {
2026-07-28 16:36:22 +02:00
_EpdError(this, gcnew EpdErrorEventArgs(rv, ErrorEPD, ErrorStep));
2021-05-26 16:20:40 +02:00
}
return;
}
2024-05-29 16:08:18 +02:00
2022-04-20 16:56:49 +02:00
System::Threading::Tasks::Task^ EpdBaseClr::Epd2::Wait(int timeout, int Retries)
2021-05-26 16:20:40 +02:00
{
if (waitTask == nullptr)
{
tokenSourceTimeout = timeout;
2026-07-28 16:36:22 +02:00
//tokenSource = gcnew System::Threading::CancellationTokenSource(tokenSourceTimeout+500);
2021-05-26 16:20:40 +02:00
readRetries = Retries;
waitTask = System::Threading::Tasks::Task::Run(gcnew Action(this, &Epd2::WaitEpd)); // System::Threading::Tasks::Task::Factory->cre(gcnew Action(this, &CCard::WaitBadge), tokenSource->Token);
}
else {
2026-07-28 16:36:22 +02:00
//tokenSource = gcnew System::Threading::CancellationTokenSource(tokenSourceTimeout +500);
2021-05-26 16:20:40 +02:00
}
return waitTask;
}
2021-05-26 16:20:40 +02:00
void EpdBaseClr::Epd2::WaitEnd()
{
if (waitTask != nullptr)
{
2022-05-04 07:53:20 +02:00
waitTask->Wait(1000);
int tries = 5;
while (tries-->0 && waitTask->Status == System::Threading::Tasks::TaskStatus::Running) {
2026-08-29 13:56:11 +02:00
if (epd3) epd3->CancelAll();
if (epd) epd->CancelAll();
2021-05-27 16:13:53 +02:00
waitTask->Wait(1000);
}
2022-05-04 07:53:20 +02:00
if (
waitTask->Status == System::Threading::Tasks::TaskStatus::RanToCompletion
|| waitTask->Status == System::Threading::Tasks::TaskStatus::Canceled
|| waitTask->Status == System::Threading::Tasks::TaskStatus::Faulted
) {
delete waitTask;
waitTask = nullptr;
}
2021-05-26 16:20:40 +02:00
Close();
}
2024-09-04 13:05:16 +02:00
}
2026-09-21 17:47:14 +02:00
int EpdBaseClr::Epd2::GetSelfTestData() {
if (epd3) return epd3->GetSelfTestData();
else {
SelftestMinutes = 0;
return SelftestMinutes;
}
}
2026-09-21 17:47:14 +02:00
int EpdBaseClr::Epd2::DoSelfTest() {
int rv = -1;
if (epd3) {
GetSelfTestData();
rv = epd3->DoSelfTest();
EPDDetectorTestRequested = epd3->EPDDetectorTestRequested;
EPDDetectorTestPassed = epd3->EPDDetectorTestPassed;
EpdID = epd3->Epd.Id;
2026-10-22 16:13:39 +02:00
HardwareVersion = String::Format("{0}.{1}", epd3->HardVersion, epd3->HardVersionMinor);
FirmwareVersion = String::Format("{0}.{1}.{2}.{3}", epd3->SoftVersion, epd3->SoftVersionMinor, epd3->SoftVersionPatch, epd3->SoftVersionBuild);
return rv;
}
else {
return 0;
}
}
int EpdBaseClr::Epd2::GetExtraEPDData() {
if (epd3) {
BatLoad_mV = epd3->vbat0;
BatNoLoad_mV = epd3->vbat1;
Cpu_mV = epd3->vcpu;
MaxBaud = epd3->Epd.MaxBaud;
}
else
{
BatLoad_mV = BatNoLoad_mV = Cpu_mV = 0;
MaxBaud = 0;
}
return 0;
2026-09-21 17:47:14 +02:00
}