#ifndef epd_common_h
#define epd_common_h
#ifndef WINAPI
#define WINAPI __stdcall
#endif
#ifdef READER3_EXPORTS
#define EPDDLL_API __declspec(dllexport) WINAPI
#else
#define EPDDLL_API  __declspec(dllimport)  WINAPI
#endif
#include <stdint.h>
#include "Mk3Types.h"
// Grouping for Doxygen comments and function descriptions
// Documentation for method return codes
extern "C"
{
  const int r_OK = 0;
  const int r_UnknownError = -1;
  const int r_InvalidCommsHandle = -2;
  const int r_InvalidPortName = -3;
  const int r_PortAlreadyOpen = -4;
  const int r_PortClosed = -5;
  const int r_OperationFailed = -6;
  const int r_InvalidState = -7;
  const int r_InvalidCompletionToken = -8;
  const int r_OperationTimeout = -9;
  const int r_UnknownCmd = -100;
  const int r_InvalidParam = -101;
  const int r_InsufficientPriv = -102;
  const int r_UnsupportedOp = -103;
  const int r_FunctionFail = -104;
  const int r_InvalidOp = -105;
  const int r_IncompleteCommand = -106;
  const int r_ResponseTooBig = -107;    //response exceeded single frame length
  const int r_ErrorBadStoredData = -108;
  const int r_InvalidResponseDataLength = -109;
  const int r_PayloadTooBig = -110;
  const int r_ParseFailure = -111;
  const int r_EEPROMWriteFailure = -112;
  const int r_Busy = -113;
  //These are Mk2 errors
  const int r_EEPROMReadFailure = -121;
  const int r_WearerNameMismatch = -122;
  const int r_DataTooLongForBuffer = -123;
  // Error codes generated within DLL
  const int r_ErrorUnexpectedResponse = -200;
  const int r_ErrorNotProcessed = -201;  //command not processed due to previous failure
  const int r_ErrorNotConnected = -202;
  const int r_ErrorUserCancelled = -203;
  typedef  void* CommsHandle;
  typedef void* CompletionToken;
  typedef void(WINAPI *DiscoveryCallback)(CommsHandle hComms, DiscoveryId const discovered[], int32_t count);
  typedef void(WINAPI *CompletionCallback)(CommsHandle hComms, CompletionToken token);
  typedef void(WINAPI *ConnectCallback)(CommsHandle hComms, DiscoveryId id);
  typedef void(WINAPI *DisconnectCallback)(CommsHandle hComms, DiscoveryId id);
  typedef void(WINAPI *RemovedCallback)(CommsHandle hComms, DiscoveryId id);
  /********************************************************************************************************************************************
  *
  *  Interface  Setup & Tear down
  *
  ********************************************************************************************************************************************/
  CommsHandle EPDDLL_API CreateReaderInterface();
  int32_t EPDDLL_API DestroyReaderInterface(CommsHandle hComms);
  int32_t EPDDLL_API OpenReader(CommsHandle hComms, char* portName);
  int32_t EPDDLL_API CloseReader(CommsHandle hComms);
  /********************************************************************************************************************************************
  *
  *  Interface configuration
  *
  ********************************************************************************************************************************************/
  int32_t EPDDLL_API SetDllLogLevel(CommsHandle hComms, uint32_t level);
  int32_t EPDDLL_API GetDllLogLevel(CommsHandle hComms, uint32_t* level);
  int32_t EPDDLL_API SetResponseTimeout(CommsHandle hComms, uint32_t ms);
  int32_t EPDDLL_API GetResponseTimeout(CommsHandle hComms, uint32_t* ms);
  int32_t EPDDLL_API SetRetryCount(CommsHandle hComms, uint32_t retries);
  int32_t EPDDLL_API GetRetryCount(CommsHandle hComms, uint32_t* retries);
  int32_t EPDDLL_API SetMultipleDiscoveryMode(CommsHandle hComms, bool state);
  int32_t EPDDLL_API GetMultipleDiscoveryMode(CommsHandle hComms, bool *state);
  int32_t EPDDLL_API SetDiscoveryTimeslots(CommsHandle hComms, uint32_t slots);
  int32_t EPDDLL_API GetDiscoveryTimeslots(CommsHandle hComms, uint32_t *slots);
  int32_t EPDDLL_API SetDiscoveryCacheTimeout(CommsHandle hComms, uint32_t ms);
  int32_t EPDDLL_API GetDiscoveryTimeout(CommsHandle hComms, uint32_t *ms);
  /********************************************************************************************************************************************
  *
  *         General Stack Operation,  Discovery, Connection Management etc
  *
  ********************************************************************************************************************************************/
  int32_t EPDDLL_API Commit(CommsHandle hComms);
  int32_t EPDDLL_API CommitAndWait(CommsHandle hComms);
  int32_t EPDDLL_API Cancel(CommsHandle hComms);
  int32_t EPDDLL_API  StartDiscovery(CommsHandle hComms, DiscoveryCallback callback);
  int32_t EPDDLL_API StopDiscovery(CommsHandle  hComms);
  int32_t EPDDLL_API GetDiscoveredEpds(CommsHandle hComms, DiscoveryId discovered[], uint32_t size, uint32_t* count);
  int32_t EPDDLL_API Connect(CommsHandle  hComms, DiscoveryId epd, bool wait = false);
  int32_t EPDDLL_API Disconnect(CommsHandle  hComms);
  int32_t EPDDLL_API DisconnectAndNotify(CommsHandle  hComms, uint16_t alarmConfig, uint16_t duration);
  int32_t EPDDLL_API SetConnectCallback(CommsHandle hComms, ConnectCallback callback);
  int32_t EPDDLL_API SetDisconnectCallback(CommsHandle hComms, DisconnectCallback callback);
  int32_t EPDDLL_API AwaitRemoval(CommsHandle  hComms, DiscoveryId epd, bool wait=false);
  int32_t EPDDLL_API SetRemovedCallback(CommsHandle hComms, RemovedCallback callback);
  int32_t EPDDLL_API GetErrorCode();
  /********************************************************************************************************************************************
  *         Real Time Clock
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadRTC(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadRTC(CommsHandle hComms, CompletionToken token, uint32_t* rtc);
  /********************************************************************************************************************************************
  *         Common Counts Acquisition
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadCounts(CommsHandle hComms, uint8_t counterIds[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadCounts(CommsHandle hComms, CompletionToken token, Counter_t counts[], uint8_t length, uint8_t * numCounts, uint32_t * utc, uint32_t * secondsSinceBaseline);
  CompletionToken EPDDLL_API BeginReadBaselineCounts(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadBaselineCounts(CommsHandle hComms, CompletionToken token, Counter_t counts[], uint8_t length, uint32_t * timestamp, uint8_t * numCounts);
  CompletionToken EPDDLL_API BeginSetBaselineCounters(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndSetBaselineCounters(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginStartDetectorTest(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndStartDetectorTest(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadSelfTestInterval(CommsHandle hComms, CompletionCallback callback);
  int32_t EPDDLL_API EndReadSelfTestInterval(CommsHandle hComms, CompletionToken token, uint16_t * minutes);
  CompletionToken EPDDLL_API BeginWriteSelfTestInterval(CommsHandle hComms, uint16_t minutes, CompletionCallback callback);
  int32_t EPDDLL_API EndWriteSelfTestInterval(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginWriteChirpSensitivity(CommsHandle hComms, float sensitivity, CompletionCallback callback);
  int32_t EPDDLL_API EndWriteChirpSensitivity(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadChirpSensitivity(CommsHandle hComms, CompletionCallback callback);
  int32_t EPDDLL_API EndReadChirpSensitivity(CommsHandle hComms, CompletionToken token, float * sensitivity);
  /********************************************************************************************************************************************
  *
  *         Common Calibration
  *
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginWriteFactoryCalDate(CommsHandle hComms, uint32_t utc, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteFactoryCalDate(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadFactoryCalDate(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadFactoryCalDate(CommsHandle hComms, CompletionToken token, uint32_t* utc);
  CompletionToken EPDDLL_API BeginWriteCalDueDate(CommsHandle hComms, uint32_t utc, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteCalDueDate(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadCalDueDate(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadCalDueDate(CommsHandle hComms, CompletionToken token, uint32_t* utc);
  CompletionToken EPDDLL_API BeginReadSensitivities(CommsHandle hComms, uint8_t sensIds[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadSensitivities(CommsHandle hComms, CompletionToken token, CalSensitivity_t sensitivities[], uint8_t length, uint8_t * numSensitivities);
  CompletionToken EPDDLL_API BeginReadDetectorThresholds(CommsHandle hComms, uint8_t counterIds[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadDetectorThresholds(CommsHandle hComms, CompletionToken token, DetectorThreshold_t thresholds[], uint8_t length, uint8_t * numThresholds);
  CompletionToken EPDDLL_API BeginReadGains(CommsHandle hComms, uint8_t sensIds[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadGains(CommsHandle hComms, CompletionToken token, CalGain_t gains[], uint8_t length, uint8_t * numGains);
  /********************************************************************************************************************************************
  *
  *         Common Dose Measurements
  *
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadDoses(CommsHandle hComms, uint8_t ids[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadDoses(CommsHandle hComms, CompletionToken token, MeasValue_t doses[], uint8_t length, uint8_t * numDoses, uint32_t * utc);
  CompletionToken EPDDLL_API BeginReadTotalDoses(CommsHandle hComms, uint8_t ids[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadTotalDoses(CommsHandle hComms, CompletionToken token, MeasValue_t doses[], uint8_t length, uint8_t * numDoses, uint32_t * utc);
  CompletionToken EPDDLL_API BeginClearDose(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndClearDose(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginClearTotalDose(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndClearTotalDose(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginClearPeakRates(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndClearPeakRates(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginWriteDoses(CommsHandle hComms, MeasValue_t doses[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteDoses(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginWriteTotalDoses(CommsHandle hComms, MeasValue_t doses[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteTotalDoses(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadRates(CommsHandle hComms, uint8_t ids[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadRates(CommsHandle hComms, CompletionToken token, MeasValue_t rates[], uint8_t length, uint8_t * numRates, uint32_t * utc);
  CompletionToken EPDDLL_API BeginReadPeakRates(CommsHandle hComms, uint8_t ids[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadPeakRates(CommsHandle hComms, CompletionToken token, PeakRate_t rates[], uint8_t length, uint8_t * numRates);
  CompletionToken EPDDLL_API BeginReadQualityData(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadQualityData(CommsHandle hComms, CompletionToken token, Mk3QualityData_t * quality);
  /********************************************************************************************************************************************
  *         Common Alarm Thresholds
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadAlarmThresholds(CommsHandle hComms, uint8_t measurandId, uint8_t thresholdIds[], uint8_t numThresholds, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadAlarmThresholds(CommsHandle hComms, CompletionToken token, Mk3AlarmThresholds_t * thresholds);
  CompletionToken EPDDLL_API BeginWriteAlarmThresholds(CommsHandle hComms, uint8_t measurandId, uint8_t numThresholds, Mk3AlarmThreshold_t thresholds[], CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteAlarmThresholds(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadRateOffPercentage(CommsHandle hComms, uint8_t measurandIds[], uint8_t numThresholds, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadRateOffPercentage(CommsHandle hComms, CompletionToken token, Mk3RatePercentage_t offThresholds[], uint8_t length, uint8_t * numThresholds);
  CompletionToken EPDDLL_API BeginWriteRateOffPercentage(CommsHandle hComms, Mk3RatePercentage_t thresholds[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteRateOffPercentage(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common General Management
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginEpdOnOff(CommsHandle hComms, uint8_t onState, CompletionCallback callback);
  int32_t  EPDDLL_API EndEpdOnOff(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common EPD Status
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadStatus(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadStatus(CommsHandle hComms, CompletionToken token, StatusData_t * status);
  CompletionToken EPDDLL_API BeginClearFaultStatus(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndClearFaultStatus(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginClearLatchedAlarms(CommsHandle hComms, CompletionCallback callback);
  int32_t EPDDLL_API EndClearLatchedAlarms(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginClearAllStatus(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndClearAllStatus(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common Wearer Identity
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadWearerId(CommsHandle hComms, uint16_t type, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadWearerId(CommsHandle hComms, CompletionToken token, IdString_t * wearerId);
  CompletionToken EPDDLL_API BeginWriteWearerId(CommsHandle hComms, IdString_t wearerId, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteWearerId(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common Issue & Return
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginIssueEPD(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndIssueEPD(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginDeissueEPD(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndDeissueEPD(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common  Identities
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadEpdIdentities(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadEpdIdentities(CommsHandle hComms, CompletionToken token, uint32_t * epdId, EpdTypes * epdType, uint32_t * capabilities,
    MarkNumber_t * markNumber, VersionNumber_t * firmwareVersion, char* vcsRevBuf, uint32_t buflen);
  CompletionToken EPDDLL_API BeginWriteEpdSerialNumber(CommsHandle hComms, uint32_t epdId, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteEpdSerialNumber(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadEpdSerialNum(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadEpdSerialNum(CommsHandle hComms, CompletionToken token, uint32_t* epdSerialNum);
  CompletionToken EPDDLL_API BeginReadCapabilities(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadCapabilities(CommsHandle hComms, CompletionToken token, uint32_t* capabilities);
  CompletionToken EPDDLL_API BeginReadMarkNumber(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadMarkNumber(CommsHandle hComms, CompletionToken token, MarkNumber_t * markNumber);
  CompletionToken EPDDLL_API BeginReadEpdType(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadEpdType(CommsHandle hComms, CompletionToken token, EpdTypes * epdType);
  CompletionToken EPDDLL_API BeginReadFirmwareVersion(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadFirmwareVersion(CommsHandle hComms, CompletionToken token, VersionNumber_t * version);
  /********************************************************************************************************************************************
  *         Common General Configuration
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginWriteDoseWritableFlag(CommsHandle hComms, uint8_t enabled, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteDoseWritableFlag(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginWriteClearDoseOnSwitchOn(CommsHandle hComms, uint8_t enable, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteClearDoseOnSwitchOn(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginWriteReturnForReadTime(CommsHandle hComms, uint32_t utc, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteReturnForReadTime(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadReturnForReadTime(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadReturnForReadTime(CommsHandle hComms, CompletionToken token, uint32_t* utc);
  CompletionToken EPDDLL_API BeginReadAlarmConfiguration(CommsHandle hComms, AlarmConfigId alarmConfigIds[], uint16_t length, CompletionCallback callback);
  int32_t EPDDLL_API EndReadAlarmConfiguration(CommsHandle hComms, CompletionToken token, AlarmConfig_t alarmConfigs[], uint16_t length, uint16_t * numConfigs);
  /********************************************************************************************************************************************
  *         Common Dose Profile
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginWriteDoseProfileInterval(CommsHandle hComms, uint16_t interval, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteDoseProfileInterval(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadDoseProfileInterval(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadDoseProfileInterval(CommsHandle hComms, CompletionToken token, uint16_t * interval);
  CompletionToken EPDDLL_API BeginReadDoseProfileByTime(CommsHandle hComms, uint32_t startTime, uint32_t endTime, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadDoseProfileByTime(CommsHandle hComms, CompletionToken token, DoseProfileRecord_t * profile[], uint16_t *count);
  void  EPDDLL_API CleanUpReadDoseProfile(DoseProfileRecord_t * profile);
  /********************************************************************************************************************************************
  *         Common Event Log
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadEventsByIndex(CommsHandle hComms, uint8_t start, uint8_t requested, CompletionCallback callback = nullptr);
  int32_t  EPDDLL_API EndReadEventsByIndex(CommsHandle hComms, CompletionToken token, EventLog * logs[], uint8_t *count);
  void  EPDDLL_API CleanUpReadEventLog(EventLog * logs);
  /********************************************************************************************************************************************
  *         Common Scratchpad
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadScratchPad(CommsHandle hComms, uint16_t startAddress, uint16_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadScratchpad(CommsHandle hComms, CompletionToken token, uint16_t *address, uint8_t buffer[], uint16_t length, uint16_t* read);
  CompletionToken EPDDLL_API BeginWriteScratchPad(CommsHandle hComms, uint16_t startAddress, uint8_t buffer[], uint16_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteScratchpad(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadScratchpadSize(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadScratchpadSize(CommsHandle hComms, CompletionToken token, uint16_t* size);
  CompletionToken EPDDLL_API BeginClearScratchPad(CommsHandle hComms, uint8_t fillChar, CompletionCallback callback);
  int32_t EPDDLL_API EndClearScratchpad(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common EEProm
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginReadEEProm(CommsHandle hComms, uint16_t startAddress, uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadEEProm(CommsHandle hComms, CompletionToken token, uint16_t *address, uint8_t buffer[], uint8_t length, uint8_t* read);
  CompletionToken EPDDLL_API BeginWriteEEProm(CommsHandle hComms, uint16_t startAddress, uint8_t buffer[], uint8_t length, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteEEProm(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common Access level
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginWriteAccessLevel(CommsHandle hComms, AccessLevel_t level, EncryptionKey key, uint8_t length, CompletionCallback callback);
  int32_t EPDDLL_API EndWriteAccessLevel(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadCurrentAccessLevel(CommsHandle hComms, CompletionCallback callback);
  int32_t EPDDLL_API EndReadCurrentAccessLevel(CommsHandle hComms, CompletionToken token, AccessLevel_t * level);
  CompletionToken EPDDLL_API BeginWriteAccessKey(CommsHandle hComms, AccessLevel_t level, EncryptionKey key, int8_t length, CompletionCallback callback);
  int32_t EPDDLL_API EndWriteAccessKey(CommsHandle hComms, CompletionToken token);
  /********************************************************************************************************************************************
  *         Common Battery Management
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginWriteBatteryTestInterval(CommsHandle hComms, uint16_t minutes, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteBatteryTestInterval(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadBatteryTestInterval(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadBatteryTestInterval(CommsHandle hComms, CompletionToken token, uint16_t* minutes);
  CompletionToken EPDDLL_API BeginWriteBatteryLowThreshold(CommsHandle hComms, int8_t batteryType, uint16_t mV, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteBatteryLowThreshold(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadBatteryLowThreshold(CommsHandle hComms, int8_t batteryType, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadBatteryLowThreshold(CommsHandle hComms, CompletionToken token, int8_t* batteryType, uint16_t* mV );
  CompletionToken EPDDLL_API BeginReadVoltages(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadVoltages(CommsHandle hComms, CompletionToken token, uint16_t* vbat0, uint16_t* vbat1, uint16_t* vcpu);
  /********************************************************************************************************************************************
  *         Common User Inteface 
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginWriteDisplayOptions(CommsHandle hComms, uint8_t value, uint8_t mask, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteDisplayOptions(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadDisplayOptions(CommsHandle hComms, CompletionCallback callback);
  int32_t EPDDLL_API EndReadDisplayOptions(CommsHandle hComms, CompletionToken token, uint8_t * value);
  CompletionToken EPDDLL_API BeginWriteDisplayTimeout(CommsHandle hComms, uint8_t seconds, CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteDisplayTimeout(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadDisplayTimeout(CommsHandle hComms, CompletionCallback callback);
  int32_t  EPDDLL_API EndReadDisplayTimeout(CommsHandle hComms, CompletionToken token, uint8_t* seconds);
  /********************************************************************************************************************************************
  *         Common Zone Control
  ********************************************************************************************************************************************/
  CompletionToken EPDDLL_API BeginWriteZoneControlMap(CommsHandle hComms, uint8_t map[], uint8_t mask[], CompletionCallback callback);
  int32_t  EPDDLL_API EndWriteZoneControlMap(CommsHandle hComms, CompletionToken token);
  CompletionToken EPDDLL_API BeginReadZoneControlMap(CommsHandle hComms, CompletionCallback callback);
  int32_t EPDDLL_API EndReadZoneControlMap(CommsHandle hComms, CompletionToken token, uint8_t map[]);
  CompletionToken EPDDLL_API BeginReadZoneAccessPermitted(CommsHandle hComms, uint8_t zone, CompletionCallback callback);
  int32_t EPDDLL_API EndReadZoneAccessPermitted(CommsHandle hComms, CompletionToken token, bool *permitted);
}
#endif