ovr_sdk

annotate LibOVR/Src/OVR_SerialFormat.h @ 0:1b39a1b46319

initial 0.4.4
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Jan 2015 06:51:16 +0200
parents
children
rev   line source
nuclear@0 1 /************************************************************************************
nuclear@0 2
nuclear@0 3 PublicHeader: n/a
nuclear@0 4 Filename : OVR_SerialFormat.h
nuclear@0 5 Content : Serial Number format tools
nuclear@0 6 Created : June 12, 2014
nuclear@0 7
nuclear@0 8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
nuclear@0 9
nuclear@0 10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
nuclear@0 11 you may not use the Oculus VR Rift SDK except in compliance with the License,
nuclear@0 12 which is provided at the time of installation or download, or which
nuclear@0 13 otherwise accompanies this software in either electronic or hard copy form.
nuclear@0 14
nuclear@0 15 You may obtain a copy of the License at
nuclear@0 16
nuclear@0 17 http://www.oculusvr.com/licenses/LICENSE-3.2
nuclear@0 18
nuclear@0 19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
nuclear@0 20 distributed under the License is distributed on an "AS IS" BASIS,
nuclear@0 21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nuclear@0 22 See the License for the specific language governing permissions and
nuclear@0 23 limitations under the License.
nuclear@0 24
nuclear@0 25 ************************************************************************************/
nuclear@0 26
nuclear@0 27 #ifndef OVR_SerialFormat_h
nuclear@0 28 #define OVR_SerialFormat_h
nuclear@0 29
nuclear@0 30 #include "Kernel/OVR_Types.h"
nuclear@0 31 #include "Kernel/OVR_String.h"
nuclear@0 32
nuclear@0 33 namespace OVR {
nuclear@0 34
nuclear@0 35
nuclear@0 36 //-----------------------------------------------------------------------------
nuclear@0 37 // SerialFormatType enumeration
nuclear@0 38
nuclear@0 39 enum SerialFormatType
nuclear@0 40 {
nuclear@0 41 SerialFormatType_Invalid = -1, // Invalid format
nuclear@0 42 SerialFormatType_DK2 = 0, // Format used for DK2
nuclear@0 43 };
nuclear@0 44
nuclear@0 45 // Returns the expected serial format based on the first byte of the buffer
nuclear@0 46 SerialFormatType DetectBufferFormat(uint8_t firstByte, int sizeInBytes);
nuclear@0 47
nuclear@0 48
nuclear@0 49 //-----------------------------------------------------------------------------
nuclear@0 50 // DK2 Serial Format
nuclear@0 51
nuclear@0 52 enum DK2ProductId
nuclear@0 53 {
nuclear@0 54 DK2ProductId_DK1 = 1, // DK1
nuclear@0 55 DK2ProductId_DK2 = 2, // Product Id used for initial DK2 launch
nuclear@0 56 DK2ProductId_Refurb = 3, // Refurbished DK2
nuclear@0 57 };
nuclear@0 58
nuclear@0 59 enum DK2PartId
nuclear@0 60 {
nuclear@0 61 DK2PartId_HMD = 0, // HMD
nuclear@0 62 DK2PartId_PTC = 1, // PTC(camera)
nuclear@0 63 DK2PartId_Carton = 2, // Carton: An HMD + PTC combo (should not be stamped on a component) AKA Overpack
nuclear@0 64 };
nuclear@0 65
nuclear@0 66 typedef DK2PartId DK2LabelType; // Printed Serial Number version
nuclear@0 67
nuclear@0 68
nuclear@0 69 // DK2 tool for reading/writing the binary serial format
nuclear@0 70 class DK2BinarySerialFormat
nuclear@0 71 {
nuclear@0 72 public:
nuclear@0 73 static const SerialFormatType FormatType = SerialFormatType_DK2; // first byte
nuclear@0 74
nuclear@0 75 DK2ProductId ProductId; // [4 bits] 2 = DK2
nuclear@0 76 DK2PartId PartId; // [4 bits] 0 means HMD, 1 means PTC(camera)
nuclear@0 77 int MinutesSinceEpoch; // [3 bytes] Number of minutes that have elapsed since the epoch: May 1st, 2014
nuclear@0 78 // [0] = high byte, [1] = middle byte, [2] = low byte
nuclear@0 79 int UnitNumber; // [2 bytes] Value that increments each time a new serial number is created. Resets to zero each day
nuclear@0 80 // [0] = high byte, [1] = low byte
nuclear@0 81 uint8_t MacHash[5]; // [5 bytes] 5 most significant bytes of MD5 hash from first ethernet adapter mac address
nuclear@0 82
nuclear@0 83 bool operator==(const DK2BinarySerialFormat& rhs);
nuclear@0 84
nuclear@0 85 public:
nuclear@0 86 // Returns false if the input is invalid in some way
nuclear@0 87 bool FromBuffer(const uint8_t buffer[12], bool allowUnknownTypes = false);
nuclear@0 88
nuclear@0 89 // Fills the provided buffer with 12 bytes
nuclear@0 90 void ToBuffer(uint8_t buffer[12]);
nuclear@0 91 };
nuclear@0 92
nuclear@0 93
nuclear@0 94 // DK2 tool for reading/writing the printed serial format
nuclear@0 95 class DK2PrintedSerialFormat
nuclear@0 96 {
nuclear@0 97 public:
nuclear@0 98 DK2ProductId ProductId; // [1 char] 2 = DK2, 3 = Reconditioned bundle
nuclear@0 99 DK2LabelType LabelType; // [1 char] 0 means HMD, 1 means PTC(camera), 2 means Overpack(bundle)
nuclear@0 100 int MinutesSinceEpoch; // [4 char] Number of minutes that have elapsed since the epoch: May 1st, 2014
nuclear@0 101 int UnitNumber; // [3 char] Value that increments each time a new serial number is created. Resets to zero each day
nuclear@0 102 uint8_t MacHashLow[3]; // [3 char] 3 least significant bytes of mac hash
nuclear@0 103
nuclear@0 104 bool operator==(const DK2PrintedSerialFormat& rhs);
nuclear@0 105 bool operator==(const DK2BinarySerialFormat& rhs);
nuclear@0 106
nuclear@0 107 public:
nuclear@0 108 // Convert from binary to printed
nuclear@0 109 void FromBinary(const DK2BinarySerialFormat& bin);
nuclear@0 110
nuclear@0 111 // Returns false if the input is invalid in some way
nuclear@0 112 // Convert from a 12 character printed serial number
nuclear@0 113 bool FromBase32(const char* str, bool allowUnknownTypes = false);
nuclear@0 114
nuclear@0 115 // Returns a long human-readable base32 string (20 characters), NOT a printed serial number
nuclear@0 116 String ToBase32();
nuclear@0 117 };
nuclear@0 118
nuclear@0 119
nuclear@0 120 //#define SERIAL_FORMAT_UNIT_TEST
nuclear@0 121 #ifdef SERIAL_FORMAT_UNIT_TEST
nuclear@0 122 void TestSerialFormatStuff();
nuclear@0 123 #endif
nuclear@0 124
nuclear@0 125
nuclear@0 126 } // OVR
nuclear@0 127
nuclear@0 128 #endif // OVR_SerialFormat_h