123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447 |
-
- #pragma once
- #define COMMON_REV 1.1
- public ref class CommonData
- {
- public:
- static const UCHAR START_COMMON_PAGE = 0x40;
- static const UCHAR PAGE70 = 70;
- static const UCHAR PAGE80 = 80;
- static const UCHAR PAGE81 = 81;
- static const UCHAR PAGE82 = 82;
- static const UCHAR PAGE83 = 83;
- static const UCHAR PAGE85 = 85;
- static const UCHAR PAGE86 = 86;
- static const UCHAR RESERVED = 0xFF;
- static const USHORT BATTERY_VOLTAGE_INVALID = 0xFFF;
- static const ULONG MAX_2SEC = (ULONG) 0xFFFFFF << 1;
- static const ULONG MAX_16SEC = (ULONG) 0xFFFFFF << 4;
- static const ULONG OPERATING_TIME_MASK = 0x00FFFFFF;
- static const UCHAR COMMAND_TYPE_DATA = 0x01;
- static const UCHAR COMMAND_TYPE_FS = 0x02;
- enum class BatStatus : UCHAR // Battery status definitions
- {
- NEW = 1,
- GOOD = 2,
- OK = 3,
- LOW = 4,
- CRITICAL = 5,
- INVALID = 7
- };
- enum class TimeResolution : UCHAR // Time resolution definitions
- {
- TWO = 2,
- SIXTEEN = 16
- };
- enum class DayOfWeek : UCHAR // defines the day of the week
- {
- SUNDAY = 0,
- MONDAY,
- TUESDAY,
- WEDNESDAY,
- THURSDAY,
- FRIDAY,
- SATURDAY,
- INVALID
- };
- enum class TotalSizeUnits : UCHAR
- {
- BIT = 0x00,
- BYTE = 0x80,
- BASE_UNIT = 0x08,
- KILO = 0x01,
- MEGA = 0x02,
- TERA = 0x03,
- };
- enum class PairingStates : UCHAR
- {
- PAIRED = 0x00,
- UNPAIRED = 0x80,
- };
- enum class ConnectionStates : UCHAR
- {
- CLOSED = 0x00,
- SEARCHING = 0x08,
- TRACKING = 0x10,
- };
- enum class NetworkKeys : UCHAR
- {
- NETWORK_PUBLIC = 0x00,
- NETWORK_PRIVATE = 0x01,
- NETWORK_ANTPLUS = 0x02,
- NETWORK_ANTFS = 0x03,
- };
-
-
- ref class Error : public System::Exception{
- public:
- BOOL bUndefPage;
- BOOL bBadReserved;
- BOOL bUndefBatStatus;
- enum class Code : UCHAR // Error code definitions
- {
- UNDEF_COMMON_PAGE,
- UNDEF_BAT_STATUS,
- INVALID_RESERVED
- };
- Error()
- {
- ClearFlags();
- }
- Error(Code eCode1_)
- {
- ClearFlags();
- SetFlags(eCode1_);
- }
- Error(Code eCode1_, Code eCode2_)
- {
- ClearFlags();
- SetFlags(eCode1_);
- SetFlags(eCode2_);
- }
- private:
- void ClearFlags()
- {
- bUndefPage = FALSE;
- bBadReserved = FALSE;
- bUndefBatStatus = FALSE;
- }
- void SetFlags(Code eCode_)
- {
- switch(eCode_)
- {
- case Code::UNDEF_COMMON_PAGE:
- bUndefPage = TRUE;
- break;
- case Code::UNDEF_BAT_STATUS:
- bUndefBatStatus = TRUE;
- break;
- case Code::INVALID_RESERVED:
- bBadReserved = TRUE;
- break;
- default:
- break;
- }
- }
- };
- public:
-
- UCHAR ucDescriptorByte1;
- UCHAR ucDescriptorByte2;
- UCHAR ucReqTransResp;
- UCHAR ucReqPageNum;
- UCHAR ucCommandType;
-
- UCHAR ucHwVersion;
- USHORT usMfgID;
- USHORT usModelNum;
-
-
-
- UCHAR ucSwVersion;
- ULONG ulSerialNum;
-
-
-
- BOOL bBattPageEnabled;
- ULONG ulOpTime;
- USHORT usBatVoltage256;
- BatStatus eBatStatus;
-
-
- TimeResolution eTimeResolution;
-
- BOOL bTimePageEnabled;
- UCHAR ucSeconds;
- UCHAR ucMinutes;
- UCHAR ucHours;
- UCHAR ucDays;
- UCHAR ucMonth;
- UCHAR ucYears;
- DayOfWeek eDayOfWeek;
-
- UCHAR ucPercentUsed;
- UCHAR ucTotalSizeExponent;
- UCHAR ucTotalSizeUnit;
-
- UCHAR ucPeripheralDeviceIndex;
- UCHAR ucTotalConnectedDevices;
- PairingStates ePairingState;
- ConnectionStates eConnectionState;
- NetworkKeys eNetworkKey;
- ULONG ulDeviceChannelId;
-
- BOOL bValidation;
- public:
- CommonData()
- {
- bValidation = FALSE;
- }
- ~CommonData()
- {
- }
- public:
- void Encode(UCHAR ucPageNum_, UCHAR* pucTxBuffer_)
- {
- switch(ucPageNum_)
- {
- case PAGE70:
- pucTxBuffer_[0] = ucPageNum_;
- pucTxBuffer_[1] = RESERVED;
- pucTxBuffer_[2] = RESERVED;
- pucTxBuffer_[3] = ucDescriptorByte1;
- pucTxBuffer_[4] = ucDescriptorByte2;
- pucTxBuffer_[5] = ucReqTransResp;
- pucTxBuffer_[6] = ucReqPageNum;
- pucTxBuffer_[7] = ucCommandType;
- break;
- case PAGE80:
- pucTxBuffer_[0] = ucPageNum_;
- pucTxBuffer_[1] = RESERVED;
- pucTxBuffer_[2] = RESERVED;
- pucTxBuffer_[3] = ucHwVersion;
- pucTxBuffer_[4] = usMfgID & 0xFF;
- pucTxBuffer_[5] = (usMfgID >> 8) & 0xFF;
- pucTxBuffer_[6] = usModelNum & 0xFF;
- pucTxBuffer_[7] = (usModelNum >> 8) & 0xFF;
- break;
- case PAGE81:
- pucTxBuffer_[0] = ucPageNum_;
- pucTxBuffer_[1] = RESERVED;
- pucTxBuffer_[2] = RESERVED;
- pucTxBuffer_[3] = ucSwVersion;
- pucTxBuffer_[4] = ulSerialNum & 0xFF;
- pucTxBuffer_[5] = (ulSerialNum >> 8) & 0xFF;
- pucTxBuffer_[6] = (ulSerialNum >> 16) & 0xFF;
- pucTxBuffer_[7] = (ulSerialNum >> 24) & 0xFF;
- break;
- case PAGE82:
- pucTxBuffer_[0] = ucPageNum_;
- pucTxBuffer_[1] = RESERVED;
- pucTxBuffer_[2] = RESERVED;
- pucTxBuffer_[3] = ulOpTime & 0xFF;
- pucTxBuffer_[4] = (ulOpTime >> 8) & 0xFF;
- pucTxBuffer_[5] = (ulOpTime >> 16) & 0xFF;
- pucTxBuffer_[6] = usBatVoltage256 & 0XFF;
- pucTxBuffer_[7] = (usBatVoltage256 >> 8) & 0x0F;
- pucTxBuffer_[7] |= ((UCHAR)eBatStatus << 4) & 0x70;
- if(eTimeResolution == TimeResolution::TWO)
- pucTxBuffer_[7] |= 0x80;
- break;
- case PAGE83:
- pucTxBuffer_[0] = ucPageNum_;
- pucTxBuffer_[1] = RESERVED;
- pucTxBuffer_[2] = ucSeconds;
- pucTxBuffer_[3] = ucMinutes;
- pucTxBuffer_[4] = ucHours;
- pucTxBuffer_[5] = ((UCHAR) eDayOfWeek << 5) & 0xE0;
- pucTxBuffer_[5] |= ucDays & 0x1F;
- pucTxBuffer_[6] = ucMonth;
- pucTxBuffer_[7] = ucYears;
- break;
- case PAGE85:
- pucTxBuffer_[0] = ucPageNum_;
- pucTxBuffer_[1] = RESERVED;
- pucTxBuffer_[2] = RESERVED;
- pucTxBuffer_[3] = RESERVED;
- pucTxBuffer_[4] = RESERVED;
- pucTxBuffer_[5] = ucPercentUsed;
- pucTxBuffer_[6] = ucTotalSizeExponent;
- pucTxBuffer_[7] = ucTotalSizeUnit;
- break;
- case PAGE86:
- pucTxBuffer_[0] = ucPageNum_;
- pucTxBuffer_[1] = ucPeripheralDeviceIndex;
- pucTxBuffer_[2] = ucTotalConnectedDevices;
- pucTxBuffer_[3] = (UCHAR)ePairingState;
- pucTxBuffer_[3] |= (UCHAR) eConnectionState;
- pucTxBuffer_[3] |= (UCHAR)eNetworkKey;
- pucTxBuffer_[4] = ulDeviceChannelId & 0xFF;
- pucTxBuffer_[5] = (ulDeviceChannelId >> 8) & 0xFF;
- pucTxBuffer_[6] = (ulDeviceChannelId >> 16) & 0xFF;
- pucTxBuffer_[7] = (ulDeviceChannelId >> 24) & 0xFF;
- break;
- default:
- break;
- }
- }
- void Decode(UCHAR* pucRxBuffer_)
- {
- BOOL bUndefBatStatus = FALSE;
- switch(pucRxBuffer_[0])
- {
- case PAGE70:
- ucDescriptorByte1 = pucRxBuffer_[3];
- ucDescriptorByte2 = pucRxBuffer_[4];
- ucReqTransResp = pucRxBuffer_[5];
- ucReqPageNum = pucRxBuffer_[6];
- ucCommandType = pucRxBuffer_[7];
- break;
- case PAGE80:
- ucHwVersion = pucRxBuffer_[3];
- usMfgID = pucRxBuffer_[4] | pucRxBuffer_[5] <<8;
- usModelNum = pucRxBuffer_[6] | pucRxBuffer_[7] <<8;
- break;
- case PAGE81:
- ucSwVersion = pucRxBuffer_[3];
- ulSerialNum = pucRxBuffer_[4] | pucRxBuffer_[5]<<8 | pucRxBuffer_[6]<<16 | pucRxBuffer_[7]<<24;
- break;
- case PAGE82:
- ulOpTime = pucRxBuffer_[3] | pucRxBuffer_[4] << 8 | pucRxBuffer_[5] << 16;
- usBatVoltage256 = pucRxBuffer_[6] | (pucRxBuffer_[7] & 0x0F) << 8;
- if((pucRxBuffer_[7] & 0x70) == 0 || (pucRxBuffer_[7] & 0x70) == 0x60)
- bUndefBatStatus = TRUE;
- eBatStatus = (BatStatus) ((pucRxBuffer_[7] & 0x70) >> 4);
- if(pucRxBuffer_[7] & 0x80)
- eTimeResolution = TimeResolution::TWO;
- else
- eTimeResolution = TimeResolution::SIXTEEN;
- break;
- case PAGE83:
- ucSeconds = pucRxBuffer_[2];
- ucMinutes = pucRxBuffer_[3];
- ucHours = pucRxBuffer_[4];
- eDayOfWeek = (DayOfWeek) ((pucRxBuffer_[5] & 0xE0) >> 5);
- ucDays = pucRxBuffer_[5] & 0x1F;
- ucMonth = pucRxBuffer_[6];
- ucYears = pucRxBuffer_[7];
- break;
- case PAGE85:
- ucPercentUsed = pucRxBuffer_[5];
- ucTotalSizeExponent = pucRxBuffer_[6];
- ucTotalSizeUnit = pucRxBuffer_[7];
- break;
- case PAGE86:
- ucPeripheralDeviceIndex = pucRxBuffer_[1];
- ucTotalConnectedDevices = pucRxBuffer_[2];
- ePairingState = (PairingStates)(pucRxBuffer_[3] & 0x80);
- eConnectionState = (ConnectionStates)(pucRxBuffer_[3] & 0x78);
- eNetworkKey = (NetworkKeys)(pucRxBuffer_[3] & 0x07);
- ulDeviceChannelId = pucRxBuffer_[4] | (pucRxBuffer_[5] << 8) | (pucRxBuffer_[6] << 16) | (pucRxBuffer_[7] << 24);
- default:
- break;
- }
- }
- BOOL IsBatteryVoltageInvalid(USHORT usBatVoltage256_)
- {
- if((usBatVoltage256 >> 8) == BATTERY_VOLTAGE_INVALID)
- return TRUE;
- else
- return FALSE;
- }
- BOOL IsBatteryStatusInvalid(BatStatus eBatStatus_)
- {
- if(eBatStatus_ == BatStatus::INVALID)
- return TRUE;
- else
- return FALSE;
- }
- BOOL IsDayOfWeekValid(DayOfWeek eDay_)
- {
- if (eDay_ == DayOfWeek::INVALID)
- return FALSE;
- else
- return TRUE;
- }
- };
|