testen met MK3

This commit is contained in:
Luc 2021-05-21 16:22:20 +02:00
parent f1b7a96cf2
commit d532d497c5
11 changed files with 462 additions and 142 deletions

View file

@ -164,11 +164,13 @@ WORD EpdBase::Epd2U::ReadStatus()
return 1;
}
RealTime = UnixTimeNow();
CommitRV = ReadEpdStatus(&EpdClock, &RealTime, &IssueCount, &OffTime, &OperatingStatus, &ErrorStatus, &AlarmStatus, &OtherAlarms, &EEPROMBadSectors);
if (port == 0) {
EpdClock = 123; ErrorStatus = 0;
};
if (CommitRV == 1) CommitRV = Commit();
if (CommitRV == 1) CommitRV = ReadEpdID(
&EpdID,
&HardVersion,
@ -206,6 +208,8 @@ WORD EpdBase::Epd2U::ReadStatus()
if (WearerID[i] == 0xb) WearerID[i] = '0'; else WearerID[i] |= 0x30;
}
}
return CommitRV;
}
WORD EpdBase::Epd2U::EPDReadExtraStatus()
@ -257,7 +261,7 @@ WORD EpdBase::Epd2U::TurnOff()
OffRV = EpdOff();
if (OffRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
EndSessionRV = EndSession(AlarmCtrl,10);
EndSessionRV = EndSession(EndSessionControl,10);
if (EndSessionRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
else {
@ -272,7 +276,7 @@ WORD EpdBase::Epd2U::TurnOn()
//OnRV = EpdOn();
//if (OnRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
EndSessionRV = EndSession(AlarmCtrl, 10);
EndSessionRV = EndSession(EndSessionControl, 10);
if (EndSessionRV == 0) {
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
return 0;
@ -435,7 +439,8 @@ WORD EpdBase::Epd2U::Issue()
if (port == 0) return 1;
WORD OKRV = SetFailFlag(); // all actions have been completed
if (OKRV) OKRV = Commit();
if (OKRV) OKRV = BaseLineCounts();
if (OKRV) OKRV = WriteAlarmDoseThresholds(Hp10THDose1, Hp10THDose2, Hp07THDose);
if (OKRV) OKRV = WriteAlarmRateThresholds(Hp10Rate1On, Hp10Rate2On, Hp07RateOn, Hp10Rate1Off, Hp10Rate2Off, Hp07RateOff);
if (OKRV) OKRV = Commit();
@ -443,7 +448,6 @@ WORD EpdBase::Epd2U::Issue()
if (OKRV) OKRV = Commit();
if (OKRV) OKRV = WriteWearerName(WearerName,(WORD)strlen((char *)WearerName));
if (OKRV) OKRV = Commit();
if (OKRV) OKRV = BaseLineCounts();
if (OKRV == 0)
{
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
@ -454,13 +458,12 @@ WORD EpdBase::Epd2U::Issue()
if (!DetectorsOn) {
OKRV = EpdOn(); OKRV=Commit(); Sleep(1500);
}
if (OKRV) {
else {
EndSession(EndSessionControl, 12);
Commit();
} // Continuous high tone for 1.2 seconds
else
}
if (!OKRV)
{
FlushBuffers(port);
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);

View file

@ -1,3 +1,4 @@
#include "TimeFunctions.h"
#include "stdafx.h"
#include "TimeFunctions.h"
@ -7,6 +8,30 @@ TimeFunctions::TimeFunctions()
{
}
UINT32 FileTime_to_POSIX(FILETIME ft)
{
// takes the last modified date
LARGE_INTEGER date, adjust;
date.HighPart = ft.dwHighDateTime;
date.LowPart = ft.dwLowDateTime;
// 100-nanoseconds = milliseconds * 10000
adjust.QuadPart = 11644473600000 * 10000;
// removes the diff between 1970 and 1601
date.QuadPart -= adjust.QuadPart;
// converts back from 100-nanoseconds to seconds
return (UINT32)(date.QuadPart / 10000000);
}
UINT32 UnixTimeNow() {
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
return FileTime_to_POSIX(ft);
}
void TimeFunctions::UnixTimeToFileTime(time_t t, LPFILETIME pft)
{
// Note that LONGLONG is a 64-bit value

View file

@ -10,3 +10,6 @@ public:
static void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst);
};
UINT32 FileTime_to_POSIX(FILETIME ft);
UINT32 UnixTimeNow();

View file

@ -214,6 +214,7 @@ int EpdBaseClr::Epd2::SetIssued()
_memccpy(epd->WearerName, str2, l, WearerNameLength);
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
int rv = epd->Issue();
if (rv != 1) SetIssuedError = epd->Error;
return rv;

View file

@ -7,6 +7,7 @@ MK3::Epd2::Epd2(int port)
{
b = gcnew sEpdBase();
epd = new Epd2U(port);
Jan2000 = gcnew DateTime(2000, 1, 1);
this->InitRV = epd->InitRv;
epd->StartCom();
}
@ -138,46 +139,47 @@ int MK3::Epd2::GetDoses()
{
Hp10 = Hp07 = 0.0;
int ReadDosesRV = epd->ReadDoses();
//
// if (ReadDosesRV == 1) {
// GetDosesError = 0;
// Hp10 = (double)epd->Hp10Dose / 64.0;
// Hp07 = (double)epd->Hp07Dose / 64.0;
// Hp07Peak = (double)epd->Hp07Peak / 64.0;
// Hp10Peak = (double)epd->Hp10Peak / 64.0;
//
// Hp07Total = epd->Hp07Total / 64.0;
// Hp10Total = epd->Hp10Total / 64.0;
// }
// else {
// GetDosesError = epd->Error;
// }
//
// if (epd->Hp10Time > 0) {
// double x = (epd->EpdClock - epd->Hp10Time) * -1.0;
// Hp10PeakTime = System::DateTime::Now.AddSeconds(x);
// }
// else
// Hp10PeakTime = System::Nullable<System::DateTime>();;
// if (epd->Hp07Time > 0) {
// 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;
//
if (ReadDosesRV == 1) {
GetDosesError = 0;
Hp10 = (double)epd->Hp10Dose ;
Hp07 = (double)epd->Hp07Dose ;
Hp07Peak = (double)epd->Hp07Peak ;
Hp10Peak = (double)epd->Hp10Peak ;
Hp07Total = epd->Hp07Total ;
Hp10Total = epd->Hp10Total ;
}
else {
GetDosesError = epd->Error;
}
if (epd->Hp10Time > 0) {
//seconds since 2000 ?
//double x = (epd->EpdClock - epd->Hp10Time) * -1.0;
Hp10PeakTime = Jan2000->AddSeconds(epd->Hp10Time);
}
else
Hp10PeakTime = System::Nullable<System::DateTime>();;
if (epd->Hp07Time > 0) {
//double x = (epd->EpdClock - epd->Hp07Time) * -1.0;
Hp07PeakTime = Jan2000->AddSeconds(epd->Hp07Time);
}
else
Hp07PeakTime = 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;
return ReadDosesRV;
}
@ -209,11 +211,14 @@ int MK3::Epd2::SetIssued()
epd->Hp10Rate2Off = (float)(Hp10Rate2Off);
epd->Hp07RateOff = (float)(Hp07RateOff);
epd->K3 = K3;
epd->K4 = K4;
memset(epd->WearerID, ' ', WearerIDLength); epd->WearerID[WearerIDLength] = 0;
char* str1 = (char*)(void*)Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WearerID);
int l = strlen(str1);
if (l > WearerIDLength) l = WearerIDLength;
_memccpy(epd->WearerID + WearerIDLength - l, str1, l, WearerIDLength);
_memccpy(epd->WearerID + WearerIDLength - l, str1, l, WearerIDLength-l);
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str1);
memset(epd->WearerName, 0, WearerNameLength + 1);
@ -224,7 +229,8 @@ int MK3::Epd2::SetIssued()
Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)str2);
int rv = epd->Issue();
if (rv != 1) SetIssuedError = epd->Error;
if (rv != 0)
SetIssuedError = epd->Error;
return rv;
}

View file

@ -7,18 +7,24 @@ using namespace System;
namespace MK3 {
public ref class sEpdBase
{
public:
DateTime^ RealTime;
unsigned int CurrentDeviceID;
};
public ref class Epd2
{
private:
DateTime^ Jan2000;
public:
Epd2U* epd;
sEpdBase^ b;
DateTime^ RealTime;
String^ WearerName;
String^ WearerID;
bool Issued;
@ -37,7 +43,6 @@ namespace MK3 {
int ReadDosesRV;
int DeviceCount = 0;
double Hp07;
double Hp10;
double Hp07Peak;

View file

@ -213,6 +213,17 @@ void MK3::Epd2U::SetTime() //Only R3
WORD MK3::Epd2U::ReadStatus()
{
int32_t r;
if (port == 0) {
EpdID = 4567;
EpdType = EpdTypes::Mk2BetaGamma;
isBG = 1;
FunctionFlags = 0x000;
Epd.Gen = EpdGeneration::None;
Epd.MaxBaud = 0;
Epd.Id = EpdID;
return 1;
}
OperatingStatus = (OpStatusFlags)0U;
AlarmStatus = (AlarmStatusFlags)0U;
ErrorStatus = (FaultStatusFlags)0;
@ -247,23 +258,12 @@ WORD MK3::Epd2U::ReadStatus()
r = EndReadEpdIdentities(epdComsHandle, token, &EpdID32, (EpdTypes*)&EpdType, &capabilities, &MarkNumber, &VersionNumber, NULL, 0);
EpdID = EpdID32;
isBG = (EpdType == EpdTypes::Mk2BetaGamma || EpdType == EpdTypes::Mk3BetaGamma);
DecodeStatus();
memset(WearerID, 0, WearerIDLength + 1);
memset(WearerID, 0, WearerIDLength + 1);
memset(WearerName, 0, WearerNameLength + 1);
if (port == 0) {
EpdID = 4567;
EpdType = EpdTypes::Mk2BetaGamma;
isBG = 1;
FunctionFlags = 0x000;
Epd.Gen = EpdGeneration::None;
Epd.MaxBaud = 0;
Epd.Id = EpdID;
return 1;
}
uint8_t length = 0;
countsRead = 0; utc = 0; seconds = 0;
@ -304,13 +304,19 @@ WORD MK3::Epd2U::ReadStatus()
token = BeginReadRTC(epdComsHandle, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadRTC(epdComsHandle, token, &utc);
r = EndReadRTC(epdComsHandle, token, &utc); //EpdClock for MK2
EpdClock = utc;
utc = TimeFunctions::NowToEpdTime(true);
}
else {
EpdClock = utc;
}
FILETIME fUTC;
TimeFunctions::EpdTimeToFileTime(utc, &fUTC, Epd.Gen== EpdGeneration::Mk2);
FileTimeToSystemTime(&fUTC, &tRealTime);
//CommitRV = ReadEpdStatus(&EpdClock, &RealTime, &IssueCount, &OffTime, &OperatingStatus, &ErrorStatus, &AlarmStatus, &OtherAlarms, &EEPROMBadSectors);
//if (port == 0) {
@ -352,7 +358,17 @@ WORD MK3::Epd2U::ReadStatus()
// else {
// }
//}
return CommitRV;
//werkt niet voor MK2
//ResetEvent(Ev1);
//token = BeginReadMeasurandIds_R3(epdComsHandle, completion);
//r = Commit(epdComsHandle);
//r = WaitForSingleObject(Ev1, 10000); // no time-out interval
//r = EndReadMeasurandIds_R3(epdComsHandle, token, mIDs, MAX_MEASUREMENTS, &nmIDs);
return r;
}
void MK3::Epd2U::decodeSensitivities(int count) {
@ -362,10 +378,27 @@ void MK3::Epd2U::decodeSensitivities(int count) {
{
case SensitivityId::Hg1Sens10G: K1 = sensitivities[ix].value; break;
case SensitivityId::Sg1Sens10G: K2 = sensitivities[ix].value; break;
case SensitivityId::Hg1Sens07G: K3 = sensitivities[ix].value; break;
case SensitivityId::Sg1Sens07G: K4 = sensitivities[ix].value; break;
case SensitivityId::Hg1Sens07G: K3 = sensitivities[ix].value; break; //Neutr=FN
case SensitivityId::Sg1Sens07G: K4 = sensitivities[ix].value; break; //Neutr=AN
case SensitivityId::Fb1Sens07B: K5 = sensitivities[ix].value; break;
case SensitivityId::Sg2Sens07B: K6 = sensitivities[ix].value; break;
default: break;
}
}
}
void MK3::Epd2U::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;
}
}
}
@ -430,6 +463,7 @@ void MK3::Epd2U::decodeBaseCounters(int count)
}
}
void MK3::Epd2U::decodeTreshold(Mk3AlarmThresholds_t* th)
{
float* pThDose = nullptr, * pThRate = nullptr, * pTHDoseWarning = nullptr, * pTHRateWarning = nullptr;
@ -456,22 +490,18 @@ void MK3::Epd2U::decodeTreshold(Mk3AlarmThresholds_t* th)
{
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_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 MK3::Epd2U::encodeTreshold(Mk3AlarmThresholds_t* th)
{
//th.MeasId
float* pThDose , *pThRate , *pTHDoseWarning,* pTHRateWarning;
pThDose = &Hp07THDose;
pTHDoseWarning = &Hp07THDose;
pThRate = &Hp07RateOn;
pTHRateWarning = &Hp07RateOff;
th->NumberThresholds = 4;
switch ((MeasurementId)th->MeasId) {
case MeasurementId::Meas_Hp07:
case MeasurementId::Meas_Hp10N:
@ -479,29 +509,113 @@ void MK3::Epd2U::encodeTreshold(Mk3AlarmThresholds_t* th)
pTHDoseWarning = &Hp07THDose;
pThRate = &Hp07RateOn;
pTHRateWarning = &Hp07RateOff;
RatePct[0].MeasId = th->MeasId;
RatePct[0].Value = 85; // (int)(Hp07RateOff * 100.0 / Hp07RateOn);
break;
case MeasurementId::Meas_Hp10:
case MeasurementId::Meas_Hp10G:
pThDose = &Hp10THDose1;
pThDose = &Hp10THDose2;
pThRate = &Hp10Rate2On;
pTHDoseWarning = &Hp10THDose1;
pTHRateWarning = &Hp10Rate1Off;
pTHRateWarning = &Hp10Rate1On;
RatePct[1].MeasId = th->MeasId;
RatePct[1].Value = 85; // (int)(Hp10Rate2Off * 100.0 / Hp10Rate2On);
break;
default:
pThDose = &Hp07THDose;
pTHDoseWarning = &Hp07THDose;
pThRate = &Hp07RateOn;
pTHRateWarning = &Hp07RateOff;
}
th->NumberThresholds = 4;
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 = *pThDose;
th->Thresholds[2].Value = *pTHDoseWarning;
th->Thresholds[3].Id = (uint16_t)ThresholdId::Thres_RateWarning;
th->Thresholds[3].Value = *pThRate;
th->Thresholds[3].Value = *pTHRateWarning;
}
void MK3::Epd2U::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
}
}
}
WORD MK3::Epd2U::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;
ResetEvent(Ev1);
//token = BeginReadDoses(epdComsHandle, new uint8_t[]{ 0, 1 }, 2 , completion);
token = BeginReadCalibrationData_R2(epdComsHandle, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
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 {
ResetEvent(Ev1);
token = BeginReadDetectorThresholds_R3(epdComsHandle,nullptr,0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadDetectorThresholds_R3(epdComsHandle, token, dTresholds, MaxTresholds, &numTresholds);
ResetEvent(Ev1);
token = BeginReadSensitivities(epdComsHandle,nullptr,0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadSensitivities(epdComsHandle, token, sensitivities,MaxSensitivities,&numSensitivities);
decodeSensitivities(numSensitivities);
}
return 0;
}
WORD MK3::Epd2U::ReadDoses()
{
int32_t r = 1;
if (port == 0) {
Hp10Dose = Hp07Dose = Hp10Total = Hp07Total = 0.0;
Knocks = Resets = QualityData = 21;
@ -516,15 +630,20 @@ WORD MK3::Epd2U::ReadDoses()
numDoses = 0; utc = 0;
ResetEvent(Ev1);
//token = BeginReadDoses(epdComsHandle, new uint8_t[]{ 0, 1 }, 2 , completion);
token = BeginReadDoses(epdComsHandle, nullptr, 0, completion);
int32_t r = Commit(epdComsHandle);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadDoses(epdComsHandle, token, doses, MaxDoses, &numDoses, &utc);
decodeDoses(numDoses);
ResetEvent(Ev1);
//token = BeginReadDoses(epdComsHandle, new uint8_t[]{ 0, 1 }, 2 , completion);
token = BeginReadTotalDoses(epdComsHandle, nullptr, 0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadTotalDoses(epdComsHandle, token, totdoses, MaxDoses, &numtotDoses, &utc);
decodetotDoses(numtotDoses);
ResetEvent(Ev1);
token = BeginReadQualityData(epdComsHandle, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
@ -539,14 +658,14 @@ WORD MK3::Epd2U::ReadDoses()
r = EndReadPeakRates(epdComsHandle, token, peakRates, MaxPeakRates, &numRates);
decodePeakRates(numRates);
ResetEvent(Ev1);
token = BeginReadSensitivities(epdComsHandle, nullptr, 0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadSensitivities(epdComsHandle, token, sensitivities, MaxSensitivities, &numSensitivities);
decodeSensitivities(numSensitivities);
ReadSensitivitiesAndTresholds();
//ResetEvent(Ev1);
//token = BeginReadSensitivities(epdComsHandle, nullptr, 0, completion);
//r = Commit(epdComsHandle);
//r = WaitForSingleObject(Ev1, 10000); // no time-out interval
//r = EndReadSensitivities(epdComsHandle, token, sensitivities, MaxSensitivities, &numSensitivities);
//decodeSensitivities(numSensitivities);
//ReadDosesQualityRV = ReadDosesQuality(
// &Hp10Dose,
@ -591,27 +710,36 @@ WORD MK3::Epd2U::ReadDoses()
// &HG);
//CommitRV = Commit();
//if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
return 0;
return 1;
}
void MK3::Epd2U::ClearDoses()
{
int32_t r = 1;
ResetEvent(Ev1);
token = BeginClearDose(epdComsHandle, completion);
int32_t r = Commit(epdComsHandle);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndClearDose(epdComsHandle, token);
if (r != 0)
goto error;
ResetEvent(Ev1);
token = BeginClearTotalDose(epdComsHandle, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndClearTotalDose(epdComsHandle, token);
if (r != 0)
goto error;
ResetEvent(Ev1);
token = BeginClearPeakRates(epdComsHandle, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndClearPeakRates(epdComsHandle, token);
if (r != 0)
goto error;
error: return ;
}
void MK3::Epd2U::ClearAlarms()
{
@ -655,54 +783,120 @@ WORD MK3::Epd2U::ReadAlarmTresholds() {
bool isNeutron = (EpdType == EpdTypes::Mk2Neutron || EpdType == EpdTypes::Mk3Neutron);
uint8_t measID;
// Start CheckEverything
ResetEvent(Ev1);
hp07tresholds.MeasId = (uint8_t)0;
token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
int32_t r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
decodeTreshold(&hp07tresholds);
ResetEvent(Ev1);
hp07tresholds.MeasId = (uint8_t)1;
token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
decodeTreshold(&hp07tresholds);
ResetEvent(Ev1);
hp07tresholds.MeasId = (uint8_t)2;
token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
decodeTreshold(&hp07tresholds);
ResetEvent(Ev1);
hp07tresholds.MeasId = (uint8_t)3;
token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId, nullptr, 0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
decodeTreshold(&hp07tresholds);
// End CheckEverything
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10N; else measID = (uint8_t)MeasurementId::Meas_Hp07;
ResetEvent(Ev1);
token = BeginReadAlarmThresholds(epdComsHandle, measID,nullptr,0, completion);
int32_t r = Commit(epdComsHandle);
hp07tresholds.MeasId = measID;
token = BeginReadAlarmThresholds(epdComsHandle, hp07tresholds.MeasId,nullptr,0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp07tresholds);
decodeTreshold(&hp07tresholds);
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10G; else measID = (uint8_t)MeasurementId::Meas_Hp10;
hp10tresholds.MeasId = measID;
ResetEvent(Ev1);
token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)MeasurementId::Meas_Hp10, nullptr, 0, completion);
token = BeginReadAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, nullptr, 0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndReadAlarmThresholds(epdComsHandle, token, &hp10tresholds);
decodeTreshold(&hp10tresholds);
return r;
}
WORD MK3::Epd2U::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_Hp10N; else measID = (uint8_t)MeasurementId::Meas_Hp07;
hp07tresholds.MeasId = measID;
encodeTreshold(&hp07tresholds);
ResetEvent(Ev1);
token = BeginWriteAlarmThresholds(epdComsHandle, (uint8_t)hp07tresholds.MeasId, (uint8_t)hp07tresholds.NumberThresholds, hp07tresholds.Thresholds, completion);
int32_t r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndWriteAlarmThresholds(epdComsHandle, token);
if (isNeutron) measID = (uint8_t)MeasurementId::Meas_Hp10G; else measID = (uint8_t)MeasurementId::Meas_Hp10;
hp10tresholds.MeasId = measID;
encodeTreshold(&hp10tresholds);
ResetEvent(Ev1);
token = BeginWriteAlarmThresholds(epdComsHandle,(uint8_t) hp10tresholds.MeasId, (uint8_t)hp10tresholds.NumberThresholds, hp10tresholds.Thresholds, completion);
token = BeginWriteAlarmThresholds(epdComsHandle, (uint8_t)hp10tresholds.MeasId, (uint8_t)hp10tresholds.NumberThresholds, hp10tresholds.Thresholds, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
if (r != 0)
goto error;
r = EndWriteAlarmThresholds(epdComsHandle, token);
return r;
}
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);
ResetEvent(Ev1);
hp07tresholds.NumberThresholds = 2;
token = BeginWriteAlarmThresholds(epdComsHandle, (uint8_t)hp07tresholds.MeasId, (uint8_t)hp07tresholds.NumberThresholds, hp07tresholds.Thresholds, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
if (r != 0)
goto error;
r = EndWriteAlarmThresholds(epdComsHandle, token);
if (r != 0)
goto error;
ResetEvent(Ev1);
token = BeginWriteRateOffPercentage(epdComsHandle, RatePct, 2, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
if (r != 0)
goto error;
r = EndWriteRateOffPercentage(epdComsHandle, token);
if (r != 0)
goto error;
error:
return r;
}
WORD MK3::Epd2U::DeIssue()
{
int32_t r = 1;
if (!EPDIssued) return 0;
ClearDoseRV = ClearTotalDoseRV = ClearPeakRatesRV = DeIssueEpdRV = 0;
if (port == 0) return 1;
ClearDoses();
@ -710,20 +904,23 @@ WORD MK3::Epd2U::DeIssue()
ResetEvent(Ev1);
token = BeginDeissueEPD(epdComsHandle, completion);
int32_t r = Commit(epdComsHandle);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndDeissueEPD(epdComsHandle, token);
if (r != 0)
goto error;
ResetEvent(Ev1);
token = BeginEpdOnOff(epdComsHandle,0, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndEpdOnOff(epdComsHandle, token);
if (r != 0)
goto error;
EndCom();
return 0;
error:
return r;
}
WORD MK3::Epd2U::WriteWearer() {
ResetEvent(Ev1);
@ -754,20 +951,27 @@ WORD MK3::Epd2U::WriteWearer() {
return 0;
}
WORD MK3::Epd2U::Issue()
{
uint32_t r;
IssueEpdRV = WriteAlarmDoseThresholdsRV = WriteAlarmRateThresholdsRV = WriteWearerNameRV = OnRV = CommitRV = 0;
if (port == 0) return 1;
//WORD OKRV = SetFailFlag(); // all actions have been completed
//if (OKRV) OKRV = Commit();
ClearAlarms();
WriteAlarmTresholds();
WriteWearer();
token = BeginIssueEPD(epdComsHandle, completion);
int32_t r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndIssueEPD(epdComsHandle, token);
//ClearAlarms();
r= WriteAlarmTresholds();
if (r != 0)
goto error;
r= WriteWearer();
if (r != 0)
goto error;
r=WriteCal();
if (r != 0)
goto error;
if (r != 0)
goto error;
if (!DetectorsOn) {
token = BeginEpdOnOff(epdComsHandle, 1, completion);
int32_t r = Commit(epdComsHandle);
@ -776,6 +980,12 @@ WORD MK3::Epd2U::Issue()
// OKRV = EpdOn(); OKRV = Commit();
Sleep(1500);
}
token = BeginIssueEPD(epdComsHandle, completion);
r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
r = EndIssueEPD(epdComsHandle, token);
if (r != 0)
goto error;
EndCom();
//if (OKRV) OKRV = WriteAlarmDoseThresholds(Hp10THDose1, Hp10THDose2, Hp07THDose);
@ -812,13 +1022,13 @@ WORD MK3::Epd2U::Issue()
//Close();
////DeinitComms(port);
//return OKRV;
return 0;
error:
return r;
}
WORD MK3::Epd2U::EPDReadExtraStatus()
{
if (port == 0) return 1;
@ -845,13 +1055,15 @@ WORD MK3::Epd2U::EPDReadExtraStatus()
WORD MK3::Epd2U::WriteCal()
{
if (port == 0) return 1;
uint32_t r = 0;
if (port == 0) return 0;
if (K6 > 2000)
{
CommitRV = 0;
r = 0;
return 0;
}
if (EpdType == EpdTypes::Mk2Neutron)
{
Password = 9;
@ -859,16 +1071,23 @@ WORD MK3::Epd2U::WriteCal()
token = BeginMfrLogin_R2(epdComsHandle, Password, completion);
uint32_t r = Commit(epdComsHandle);
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
if (r != 0)
goto error;
r = EndMfrLogin_R2(epdComsHandle, token);
if (r != 0)
goto error;
token = BeginWriteSensitivities_R2(epdComsHandle, completion, (uint16_t)K1, (uint16_t)K2, (uint16_t)K3, (uint16_t)K4, (uint16_t)K5, (uint16_t)K6);
r = Commit(epdComsHandle);
if (r != 0)
goto error;
r = WaitForSingleObject(Ev1, 10000); // no time-out interval
if (r != 0)
goto error;
r = EndWriteSensitivities_R2(epdComsHandle, token);
//if (CommitRV == 1) CommitRV = MFRWriteCalFactors(K1, K2, K3, K4, K5, K6);
//if (CommitRV == 1) CommitRV = Commit();
//if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
if (r != 0)
goto error;
}
return CommitRV;
return r;
error:
return r;
}

View file

@ -14,6 +14,7 @@
#define MaxAlarmConfig 10
#define MaxTresholds 10
namespace MK3
{
class Epd2U
@ -213,20 +214,26 @@ namespace MK3
BYTE byStatus3;
BYTE byStatus4;
MeasurementId mIDs[MAX_MEASUREMENTS];
uint8_t nmIDs = 0;
MeasValue_t doses[MaxDoses];
MeasValue_t totdoses[MaxDoses];
PeakRate_t peakRates[MaxPeakRates];
AlarmConfig_t alarmConfig[MaxAlarmConfig];
CalSensitivity_t sensitivities[MaxSensitivities];
Counter_t Counts[MaxCounts];
uint8_t countsRead;
uint32_t seconds;
uint8_t numDoses, numRates, numSensitivities;
uint8_t numDoses, numtotDoses, numRates, numSensitivities, numTresholds;
uint16_t numAlarm;
uint32_t utc;
Mk3QualityData_t quality;
Mk3AlarmThresholds_t hp07tresholds;
Mk3RatePercentage_t RatePct[2];
Mk3AlarmThresholds_t hp10tresholds;
DetectorThreshold_t dTresholds[MaxTresholds];
int StartDiscover();
void Open(DiscoveryId DeviceID);
void CloseDev();
@ -237,6 +244,10 @@ namespace MK3
void decodeTreshold(Mk3AlarmThresholds_t *th);
void encodeTreshold(Mk3AlarmThresholds_t* th);
void decodedTresholds(int numdTresholds);
Epd2U(int comport);
WORD WriteConfig();
DWORD StartCom();
@ -248,8 +259,10 @@ namespace MK3
WORD TurnOff();
WORD TurnOn();
WORD WriteCal();
WORD ReadSensitivitiesAndTresholds();
//WORD ReadTresHolds();
WORD ReadDoses();
void decodetotDoses(int count);
void decodeDoses(int count);
void decodeSensitivities(int count);
void decodePeakRates(int count);

View file

@ -11,14 +11,42 @@ namespace TestEPD3Dll
{
static void Main(string[] args)
{
DateTime jan1970 = new DateTime(1970, 1, 1);
var snow = (DateTime.Now - jan1970).TotalSeconds;
DateTime dt2 = DateTime.Now.AddSeconds(-254246887);
//254245176
int rv;
MK3.Epd2 x = new MK3.Epd2(4);
x.Connect(false);
var rv = x.SetTime();
//var rv = x.SetTime();
rv = x.GetStatus();
x.ReadAlarmTresholds();
//x.ReadAlarmTresholds();
rv = x.GetDoses();
//x.SetDeIssued();
x.WriteCalibration();
x.SetDeIssued();
//x.WriteCalibration();
x.Hp07THDose = 1;
x.Hp10THDose1 = 2;
x.Hp10THDose2 = 3;
x.Hp07RateOn = 4;
x.Hp07RateOff = 5;
x.Hp10Rate1On = 6;
x.Hp10Rate1Off = 7;
x.Hp10Rate2On = 8;
x.Hp10Rate2Off = 9;
//x.AlarmDoseHP07N = 11;
//x.AlarmDoseHP101G = 12;
//x.AlarmDoseHP102G = 13;
//x.AlarmRateHP07N = 14;
//x.AlarmRateHP101G = 15;
//x.AlarmRateHP102G = 16;
x.K3 = 4; x.K4 = 3;
x.WearerName = "12345678";
x.WearerID = "12";
x.SetIssued();
}
}

View file

@ -219,6 +219,23 @@ namespace eDosStation
}
}
}
#if DummyData
ep.Hp07THDose = 70;
ep.Hp10THDose1 = 11;
ep.Hp10THDose2 = 12;
ep.Hp07RateOn = 80;
ep.Hp07RateOff = 9;
ep.Hp10Rate1On = 13;
ep.Hp10Rate1Off = 14;
ep.Hp10Rate2On = 15;
ep.Hp10Rate2Off = 16;
ep.K3 = 3; ep.K4 = 4;
if (!ep.isBG)
ep.WriteCalibration();
#endif
rv = ep.SetIssued();
if (rv != 1)

View file

@ -42,7 +42,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;noSimulateEPD</DefineConstants>
<DefineConstants>TRACE;DEBUG;noSimulateEPD,DummyData</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>