From ef8362bb6060cde6303de364592037fab2532e4e Mon Sep 17 00:00:00 2001 From: Luc Date: Tue, 18 May 2021 15:42:46 +0200 Subject: [PATCH] prepare for read dose --- MK3/MK3.cpp | 12 +++--- MK3/MK3.h | 2 +- MK3/MK3Base.cpp | 89 +++++++++++++++++++++++++++++++++++++++--- MK3/MK3Base.h | 6 ++- TestEPD3Dll/Program.cs | 2 + TestMK3/TestMK3.cpp | 4 +- 6 files changed, 101 insertions(+), 14 deletions(-) diff --git a/MK3/MK3.cpp b/MK3/MK3.cpp index 0af758c..24c660b 100644 --- a/MK3/MK3.cpp +++ b/MK3/MK3.cpp @@ -117,10 +117,10 @@ int MK3::Epd2::GetStatus() return StatusRV; } -//int MK3::Epd2::GetDoses() -//{ -// Hp10 = Hp07 = 0.0; -// ReadDosesRV = epd->ReadDoses(); +int MK3::Epd2::GetDoses() +{ + Hp10 = Hp07 = 0.0; + int ReadDosesRV = epd->ReadDoses(); // // if (ReadDosesRV == 1) { // GetDosesError = 0; @@ -161,8 +161,8 @@ int MK3::Epd2::GetStatus() // FB = epd->FB; // HG = epd->HG; // -// return ReadDosesRV; -//} + return ReadDosesRV; +} // //int MK3::Epd2::SetDeIssued() //{ diff --git a/MK3/MK3.h b/MK3/MK3.h index ade4fd5..a528eba 100644 --- a/MK3/MK3.h +++ b/MK3/MK3.h @@ -134,7 +134,7 @@ namespace MK3 { int GetStatus(); - //int GetDoses(); + int GetDoses(); //int SetDeIssued(); //int SetIssued(); //int PrepareForIssue(); diff --git a/MK3/MK3Base.cpp b/MK3/MK3Base.cpp index 441b2d1..03e214e 100644 --- a/MK3/MK3Base.cpp +++ b/MK3/MK3Base.cpp @@ -282,16 +282,16 @@ WORD MK3::Epd2U::ReadStatus() r = Commit(epdComsHandle); r = WaitForSingleObject(Ev1, 10000); // no time-out interval r = EndReadWearerId(epdComsHandle, token, &mk3WearerID); - if (mk3WearerID.Length > 23) mk3WearerID.Length = 23; - memcpy(WearerName, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length - 1] = 0; + if (mk3WearerID.Length > WearerNameLength) mk3WearerID.Length = WearerNameLength; + memcpy(WearerName, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length] = 0; ResetEvent(Ev1); token = BeginReadWearerId(epdComsHandle, static_cast(WearerIdType::WearerId_Primary), completion); r = Commit(epdComsHandle); r = WaitForSingleObject(Ev1, 10000); // no time-out interval r = EndReadWearerId(epdComsHandle, token, &mk3WearerID); - if (mk3WearerID.Length > 13) mk3WearerID.Length = 13; - memcpy(this->WearerID, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length - 1] = 0; + if (mk3WearerID.Length > WearerIDLength) mk3WearerID.Length = WearerIDLength; + memcpy(this->WearerID, mk3WearerID.Utf8String, mk3WearerID.Length); WearerName[mk3WearerID.Length] = 0; for (int i = 0; i < mk3WearerID.Length; i++) if (WearerID[i] == 0xb) WearerID[i] = '0'; else WearerID[i] |= 0x30; @@ -343,4 +343,83 @@ WORD MK3::Epd2U::ReadStatus() // } //} return CommitRV; -} \ No newline at end of file +} + +WORD MK3::Epd2U::ReadDoses() +{ + if (port == 0) { + Hp10Dose = Hp07Dose = Hp10Total = Hp07Total = Knocks = Resets = QualityData = 21; + Hp10Peak = Hp07Peak = Hp10Time = Hp07Time = 1000; + ErrorSource = ErrorReason = ErrorData = 0; + K1 = 1; K2 = 2; K3 = 3; K4 = 4; K5 = 5; K6 = 6; + SG = 7; BC = 8; FB = 9; HG = 10; + return 1; + } + ReadDosesQualityRV = ReadPeaksRV = CommitRV = 0; + + 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 = WaitForSingleObject(Ev1, 10000); // no time-out interval + r = EndReadDoses(epdComsHandle, token, doses, 2, &numDoses, &utc); + + + //int32_t EPDDLL_API EndReadQualityData(CommsHandle hComms, CompletionToken token, Mk3QualityData_t * quality ) + //ReadDosesQualityRV = ReadDosesQuality( + // &Hp10Dose, + // &Hp07Dose, + // &Hp10Total, + // &Hp07Total, + // &Knocks, + // &Resets, + // &QualityData); + + //if (ReadDosesQualityRV == 0) { + // Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); + // return 0; + //} + + //BeginReadPeakRates(CommsHandle hComms, uint8_t ids[], uint8_t length, CompletionCallback callback ) + /*ReadPeaksRV = ReadPeaks( + &Hp10Peak, + &Hp07Peak, + &Hp10Time, + &Hp07Time); + if (ReadPeaksRV == 0) { + Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); + return 0; + }*/ + + // EPD2 : + // int32_t EPDDLL_API EndReadCalibrationData_R2 (CommsHandle hComms, CompletionToken token, 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) + // EPD3 + // + //CompletionToken EPDDLL_API BeginReadSensitivities_R3(CommsHandle hComms, uint8_t sensIds[], uint8_t length, CompletionCallback callback ) + //ReadCalibrationData( + // &K1, + // &K2, + // &K3, + // &K4, + // &K5, + // &K6, + // &SG, + // &BC, + // &FB, + // &HG); + //CommitRV = Commit(); + //if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData); + return CommitRV; +} +//WORD EpdBase::Epd2U::PrepareForIssue() +//{ +// if (port == 0) return 1; +// CommitRV = WriteConfig(); +// if (CommitRV) CommitRV = Commit(); +// if (CommitRV) CommitRV = ClearDose(); +// if (CommitRV) CommitRV = ClearTotalDose(); +// if (CommitRV) CommitRV = ClearPeakRates(); +// if (CommitRV) CommitRV = Commit(); +// return CommitRV; +//} \ No newline at end of file diff --git a/MK3/MK3Base.h b/MK3/MK3Base.h index 4589f2d..fd58c69 100644 --- a/MK3/MK3Base.h +++ b/MK3/MK3Base.h @@ -212,6 +212,10 @@ namespace MK3 BYTE byStatus3; BYTE byStatus4; + MeasValue_t doses[4]; + uint8_t numDoses; + uint32_t utc; + int StartDiscover(); void Open(DiscoveryId DeviceID); void CloseDev(); @@ -230,7 +234,7 @@ namespace MK3 WORD TurnOn(); //WORD WriteCal(); //WORD ReadTresHolds(); - //WORD ReadDoses(); + WORD ReadDoses(); //WORD PrepareForIssue(); //WORD DeIssue(); diff --git a/TestEPD3Dll/Program.cs b/TestEPD3Dll/Program.cs index 6721420..19749de 100644 --- a/TestEPD3Dll/Program.cs +++ b/TestEPD3Dll/Program.cs @@ -20,6 +20,8 @@ namespace TestEPD3Dll x.Connect(false); var rv = x.GetStatus(); + + } } } diff --git a/TestMK3/TestMK3.cpp b/TestMK3/TestMK3.cpp index 67ab080..a1fb131 100644 --- a/TestMK3/TestMK3.cpp +++ b/TestMK3/TestMK3.cpp @@ -64,8 +64,10 @@ void GetEPD() r = EndReadStatus(epdComsHandle, token, &status); + numDoses = 0; utc = 0; ResetEvent(Ev1); - token = BeginReadDoses(epdComsHandle, new uint8_t[]{0, 1}, 2, completion); + //token = BeginReadDoses(epdComsHandle, new uint8_t[]{ 0, 1 }, 2 , completion); + token = BeginReadDoses(epdComsHandle, nullptr, 0 , completion); r = Commit(epdComsHandle); r = WaitForSingleObject(Ev1, 10000); // no time-out interval std::cout << "got doses\n";