208 lines
No EOL
5.1 KiB
C++
208 lines
No EOL
5.1 KiB
C++
#include "stdafx.h"
|
|
#include "EpdBase.h"
|
|
|
|
EpdBase::Epd2U::Epd2U(int comport)
|
|
{
|
|
port = comport;
|
|
SetAutoCommit(0);
|
|
Error = 123;
|
|
//SetTimeouts(port, 20, 1000, 1000);
|
|
//SetDiscoveryExpirationPeriod(port, 5000);
|
|
InitRv= InitComms(port, 9600, 8, 0, 0);
|
|
if (InitRv == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
}
|
|
|
|
EpdBase::Epd2U::~Epd2U()
|
|
{
|
|
DeinitComms(port);
|
|
SetAutoCommit(0);
|
|
}
|
|
|
|
|
|
void EpdBase::Epd2U::StartDiscover()
|
|
{
|
|
FlushDiscoveryCache(port);
|
|
DiscRV= Discover(port, DeviceIDs, MaxDevices, &DeviceCount);
|
|
if (DiscRV == 1 && DeviceCount == 0) {
|
|
OnRV = EpdOn();
|
|
Sleep(1100);
|
|
DiscRV = Discover(port, DeviceIDs, MaxDevices, &DeviceCount);
|
|
}
|
|
|
|
}
|
|
|
|
void EpdBase::Epd2U::Open(DWORD DeviceID)
|
|
{
|
|
CurrentDeviceID = DeviceID;
|
|
ConRV = Connect(DeviceID);
|
|
if (ConRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
else {
|
|
OpenRV = OpenDevice(port, CurrentDeviceID);
|
|
if (OpenRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
}
|
|
}
|
|
|
|
void EpdBase::Epd2U::Close()
|
|
{
|
|
CloseDevice();
|
|
}
|
|
|
|
void EpdBase::Epd2U::DecodeFunctionFlags()
|
|
{
|
|
EpdType = (FunctionFlags & 0x0300) >> 8;
|
|
}
|
|
|
|
void EpdBase::Epd2U::DecodeStatus()
|
|
{
|
|
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;
|
|
|
|
}
|
|
|
|
WORD EpdBase::Epd2U::ReadStatus()
|
|
{
|
|
memset(WearerID, 0, IDLength+1);
|
|
memset(WearerName, 0, NameLength+1);
|
|
|
|
EpdClock = RealTime = IssueCount = OffTime = OperatingStatus = ErrorStatus = AlarmStatus = OtherAlarms = EEPROMBadSectors = 0;
|
|
ErrorSource = ErrorReason = ErrorData = 0;
|
|
|
|
ReadStatusRV= ReadEpdStatus(&EpdClock, &RealTime, &IssueCount, &OffTime, &OperatingStatus, &ErrorStatus, &AlarmStatus, &OtherAlarms, &EEPROMBadSectors);
|
|
if (ReadStatusRV == 0) {
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
return ErrorReason;
|
|
}
|
|
|
|
EpdID = HardVersion = SoftVersion = FunctionFlags = 0;
|
|
ReadEpdIDRV = ReadEpdID(
|
|
&EpdID,
|
|
&HardVersion,
|
|
&SoftVersion,
|
|
&FunctionFlags);
|
|
if (ReadEpdIDRV == 0) {
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
return ErrorReason;
|
|
}
|
|
|
|
CommitRV = Commit();
|
|
if(CommitRV == 0) {
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
return ErrorReason;
|
|
}
|
|
else {
|
|
time_t t = RealTime;
|
|
TimeFunctions::UnixTimeToSystemTime(t, &tRealTime);
|
|
DecodeStatus();
|
|
DecodeFunctionFlags();
|
|
}
|
|
|
|
if (ReadStatusRV == 1 && EPDIssued == 1) {
|
|
ReadWearerRV = 3;
|
|
ReadWearerRV = ReadWearer(
|
|
WearerID,
|
|
IDLength,
|
|
WearerName,
|
|
NameLength);
|
|
CommitRV = Commit();
|
|
if (CommitRV == 0) {
|
|
Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
return ErrorReason;
|
|
}
|
|
}
|
|
else
|
|
ReadWearerRV = 4;
|
|
|
|
|
|
|
|
return 1;
|
|
}
|
|
|
|
WORD EpdBase::Epd2U::EPDReadConfig()
|
|
{
|
|
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;
|
|
}
|
|
|
|
WORD EpdBase::Epd2U::TurnOff()
|
|
{
|
|
OffRV = EpdOff();
|
|
if (OffRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
EndSessionRV = EndSession(AlarmCtrl,8);
|
|
if (EndSessionRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
|
|
else {
|
|
CommitRV = Commit();
|
|
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
}
|
|
return CommitRV;
|
|
}
|
|
|
|
WORD EpdBase::Epd2U::ReadTresHolds()
|
|
{
|
|
ReadDoseTresholdRV = ReadAlarmDoseThresholds(&Hp10Dose1, &Hp10Dose2, &Hp07Dose);
|
|
ReadAlarmRateThresholdsRV = ReadAlarmRateThresholds(
|
|
&Hp10Rate1On,
|
|
&Hp10Rate2On,
|
|
&Hp07RateOn,
|
|
&Hp10Rate1Off,
|
|
&Hp10Rate2Off,
|
|
&Hp07RateOff);
|
|
ReadCalibrationDataRV = ReadCalibrationData(
|
|
&K1,
|
|
&K2,
|
|
&K3,
|
|
&K4,
|
|
&K5,
|
|
&K6,
|
|
&SG,
|
|
&BC,
|
|
&FB,
|
|
&HG);
|
|
CommitRV = Commit();
|
|
if (CommitRV == 0) Error = GetErrorDetails(&ErrorSource, &ErrorReason, &ErrorData);
|
|
return CommitRV;
|
|
} |