ovr_sdk

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/OVR_SerialFormat.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,128 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +PublicHeader:   n/a
     1.7 +Filename    :   OVR_SerialFormat.h
     1.8 +Content     :   Serial Number format tools
     1.9 +Created     :   June 12, 2014
    1.10 +
    1.11 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.12 +
    1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.15 +which is provided at the time of installation or download, or which 
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +You may obtain a copy of the License at
    1.19 +
    1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.21 +
    1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.23 +distributed under the License is distributed on an "AS IS" BASIS,
    1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.25 +See the License for the specific language governing permissions and
    1.26 +limitations under the License.
    1.27 +
    1.28 +************************************************************************************/
    1.29 +
    1.30 +#ifndef OVR_SerialFormat_h
    1.31 +#define OVR_SerialFormat_h
    1.32 +
    1.33 +#include "Kernel/OVR_Types.h"
    1.34 +#include "Kernel/OVR_String.h"
    1.35 +
    1.36 +namespace OVR {
    1.37 +
    1.38 +
    1.39 +//-----------------------------------------------------------------------------
    1.40 +// SerialFormatType enumeration
    1.41 +
    1.42 +enum SerialFormatType
    1.43 +{
    1.44 +	SerialFormatType_Invalid = -1, // Invalid format
    1.45 +	SerialFormatType_DK2 = 0,	   // Format used for DK2
    1.46 +};
    1.47 +
    1.48 +// Returns the expected serial format based on the first byte of the buffer
    1.49 +SerialFormatType DetectBufferFormat(uint8_t firstByte, int sizeInBytes);
    1.50 +
    1.51 +
    1.52 +//-----------------------------------------------------------------------------
    1.53 +// DK2 Serial Format
    1.54 +
    1.55 +enum DK2ProductId
    1.56 +{
    1.57 +	DK2ProductId_DK1    = 1, // DK1
    1.58 +	DK2ProductId_DK2    = 2, // Product Id used for initial DK2 launch
    1.59 +	DK2ProductId_Refurb = 3, // Refurbished DK2
    1.60 +};
    1.61 +
    1.62 +enum DK2PartId
    1.63 +{
    1.64 +	DK2PartId_HMD    = 0, // HMD
    1.65 +	DK2PartId_PTC    = 1, // PTC(camera)
    1.66 +	DK2PartId_Carton = 2, // Carton: An HMD + PTC combo (should not be stamped on a component) AKA Overpack
    1.67 +};
    1.68 +
    1.69 +typedef DK2PartId DK2LabelType; // Printed Serial Number version
    1.70 +
    1.71 +
    1.72 +// DK2 tool for reading/writing the binary serial format
    1.73 +class DK2BinarySerialFormat
    1.74 +{
    1.75 +public:
    1.76 +	static const SerialFormatType FormatType = SerialFormatType_DK2; // first byte
    1.77 +
    1.78 +	DK2ProductId ProductId;         // [4 bits] 2 = DK2
    1.79 +	DK2PartId    PartId;            // [4 bits] 0 means HMD, 1 means PTC(camera)
    1.80 +	int          MinutesSinceEpoch; // [3 bytes] Number of minutes that have elapsed since the epoch: May 1st, 2014
    1.81 +	// [0] = high byte, [1] = middle byte, [2] = low byte
    1.82 +	int          UnitNumber;        // [2 bytes] Value that increments each time a new serial number is created.  Resets to zero each day
    1.83 +	// [0] = high byte, [1] = low byte
    1.84 +	uint8_t      MacHash[5];        // [5 bytes] 5 most significant bytes of MD5 hash from first ethernet adapter mac address
    1.85 +
    1.86 +	bool operator==(const DK2BinarySerialFormat& rhs);
    1.87 +
    1.88 +public:
    1.89 +	// Returns false if the input is invalid in some way
    1.90 +	bool FromBuffer(const uint8_t buffer[12], bool allowUnknownTypes = false);
    1.91 +
    1.92 +	// Fills the provided buffer with 12 bytes
    1.93 +	void ToBuffer(uint8_t buffer[12]);
    1.94 +};
    1.95 +
    1.96 +
    1.97 +// DK2 tool for reading/writing the printed serial format
    1.98 +class DK2PrintedSerialFormat
    1.99 +{
   1.100 +public:
   1.101 +	DK2ProductId ProductId;         // [1 char] 2 = DK2, 3 = Reconditioned bundle
   1.102 +	DK2LabelType LabelType;         // [1 char] 0 means HMD, 1 means PTC(camera), 2 means Overpack(bundle)
   1.103 +	int          MinutesSinceEpoch; // [4 char] Number of minutes that have elapsed since the epoch: May 1st, 2014
   1.104 +	int          UnitNumber;        // [3 char] Value that increments each time a new serial number is created.  Resets to zero each day
   1.105 +	uint8_t      MacHashLow[3];     // [3 char] 3 least significant bytes of mac hash
   1.106 +
   1.107 +	bool operator==(const DK2PrintedSerialFormat& rhs);
   1.108 +	bool operator==(const DK2BinarySerialFormat& rhs);
   1.109 +
   1.110 +public:
   1.111 +	// Convert from binary to printed
   1.112 +	void FromBinary(const DK2BinarySerialFormat& bin);
   1.113 +
   1.114 +	// Returns false if the input is invalid in some way
   1.115 +	// Convert from a 12 character printed serial number
   1.116 +	bool FromBase32(const char* str, bool allowUnknownTypes = false);
   1.117 +
   1.118 +	// Returns a long human-readable base32 string (20 characters), NOT a printed serial number
   1.119 +	String ToBase32();
   1.120 +};
   1.121 +
   1.122 +
   1.123 +//#define SERIAL_FORMAT_UNIT_TEST
   1.124 +#ifdef SERIAL_FORMAT_UNIT_TEST
   1.125 +void TestSerialFormatStuff();
   1.126 +#endif
   1.127 +
   1.128 +
   1.129 +} // OVR
   1.130 +
   1.131 +#endif // OVR_SerialFormat_h