Tezzeret  1
Tezzeret
GmProvision.hpp
1 /*
2  * GmProvision.h
3  *
4  * Created on: Nov 29, 2017
5  * Author: rcram
6  */
7 
8 #ifndef GMPROVISION_H_
9 #define GMPROVISION_H_
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 // To allow inclusion in CPP projects add this
15 
16 #define HW_TYPE_LEN 4 // Hardware type � 4 bytes of information
17 #define SERIAL_NUMBER_LEN 16 // Serial number � write 16 bytes of information.
18 #define SSID_LEN 32 //SSID (wifi name) � 32 bytes, holding a zero-terminated C string.
19 #define SDCARD_SPI_BUS_SPEED_LEN 32 // SDCard SPI bus speed � 32-bit unsigned integer.
20 #define USB_BUS_SPEED_LEN 32 //USB card bus speed � 32 bit unsigned integer
21 #define MACHINE_NAME_LEN 40 //Friendly machine name � 40 bytes, holding a zero-terminated C string.
22 #define APP_INFO_LEN 32 //- a 32-byte block of information
23 #define PASSWORD_LN 64 // Wifi password.
24 #define SERIAL_NO_LEN 16
25 
26 /* These error codes are larger than any EEPROM code size, so do not
27  * mimic any valid EEPROM storage location.
28  */
29 #define GM_PROVISION_EOF 1000000
30 #define GM_PROVISION_CORRUPT 1000001
31 #define GM_PROVISION_OK 1000002
32 
33 #define GM_PROVISIONING_FIRST_RECORD_OFFSET 0
34 
35 #define GEO_PROVISION_EOF (0x01010101)
36 #define GEO_PROVISION_EOF_SIZE 8
37 #define GEO_PROV_EOF_TYPE (0x01010101)
38 
39 
40 
41 
42 #define GEO_PROVISIONING_BASE_BLOCK_OBSOLETE0 0x00 // Do not reuse these numbers, which are obsolete and
43 #define GEO_PROVISIONING_BASE_BLOCK_OBSOLETE1 0x01 // Obsolete, do not re-use.
44 #define GEO_PROVISIONING_BASE_BLOCK 0x02
45 #define GEO_PROVISIONING_NETWORK_BLOCK 0x03
46 
47 // Start address is 0x0 to 0x17FC and where the sizeof(...) words would be written.
48 #define E2PROM_TEST_ADDRESS 0x100
49 
50 namespace Geometrics
51 {
52  /*******************************************************************************************
53  * Geo Machine Provisioning Parameters
54  *******************************************************************************************/
55  typedef struct _GeoMachineProvisioning{
56  uint32_t m_iRecordType; // Offset 0, size 4 Will be hard-coded to value GEO_PROVISIONING_BASE_BLOCK
57  uint32_t m_iRecordSize; // Offset 4, size 4: size of the entire data structure including type and size and all below
58  char m_iMachineName [MACHINE_NAME_LEN+4]; // Offset 8, size 44
59  char m_iSSID [SSID_LEN+4]; // Offset 52, size 36
60  char m_password[PASSWORD_LN+4]; // Ofset 88, size 68
61  char m_serialNumber [SERIAL_NO_LEN+4]; // Offset 156, size 20
62  int m_iSystemBoardType;
63  int m_iSystemInfo1;
64  int m_iSystemInfo2;
65  int m_iSystemInfo3;
66  } GeoMachineProvisioning, *GeoMachinePtr; // Total record size 176
67 
69  {
70  uint32_t m_iRecordType; // Offset 0, size 4 Will be hard-coded to value GEO_PROVISIONING_NETWORK_BLOCK
71  uint32_t m_iRecordSize; // Offset 4, size 4: size of the entire data structure including type and size and all below
72  char m_ipv4AddressAsString[16]; // Offset 8, size 16
73  uint32_t m_reserved1; // Offset 24, size 4
74  uint32_t m_reserved2; // Offset 28, size 4
75  } GeoNetworkInfoProvisioning; // Total record size 32
76 
77  #define GM_BASIC_PROVISIONING_SIZE (sizeof(GeoMachineProvisioning))
78 
79  typedef struct _GeoProvisionEof
80  {
81  uint32_t m_iRecordType; // GEO_PROVISION_EOF
82  uint32_t m_iRecordSize; // 8, the size of this record.
84 
86  {
87  public:
88  /****************************************************************************************************************
89  * Function Prototypes**************************************************************************************
90  ****************************************************************************************************************/
91  static int ClearProvisioning ();
92  static int EraseProvisioning ();
93 
94 
95  /********************************************************************************************/
96  /* Set default values into basic provisioning structure */
97  /********************************************************************************************/
98  static int InitializeGeoMachineProvisioningParameters(GeoMachinePtr );
99 
100  #if GEO_STATIC_NETWORK_PROVISIONED == GEO_TRUE
101  static int InitializeNetworkProvisioning(GeoNetworkInfoProvisioning *networkParameters, const char *ipAddress );
102  #endif
103 
104 
105  // Prep EEPROM library.
106  static void InitEEPROM_ConfigProvisioning(void);
107 
108  static int FindProvisioningRecord (uint32_t startAddress,
109  uint32_t recordType,
110  uint32_t recordSize);
111  static int OverwriteOrAppend (uint32_t startAddress,
112  uint32_t recordType,
113  uint32_t recordSize,
114  char *source,
115  bool bRetry);
116  static int GetProvisioningRecord (uint32_t startAddress,
117  uint32_t recordType,
118  uint32_t recordSize,
119  char *dest);
120 
121 
122 
123  // Write a config block.
124  static int WriteProvisionParametersToEEPROM(void *ptr , uint32_t location, int size );
125 
126  // Read a config block.
127  static int ReadProvisionParametersFromEEPROM(void *ptr , uint32_t location, int size, uint32_t type );
128  };
129 }
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 #endif /* GMPROVISION_H_ */
Definition: GmProvision.hpp:86
GmApp/GmLoggingApp.hpp>
Definition: Analogs.hpp:47
Definition: GmProvision.hpp:55
Definition: GmProvision.hpp:69
Definition: GmProvision.hpp:80