ovr_sdk

view LibOVR/Src/OVR_SerialFormat.h @ 1:bd36c61436fa

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