-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_time.h
215 lines (177 loc) · 8.85 KB
/
get_time.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* Copyright (c) 2016, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef GET_TIME_H
#define GET_TIME_H
/* Standard includes */
#include <mqueue.h>
#include <stdbool.h>
/* TI-DRIVERS Header files */
#include <ti/drivers/net/wifi/simplelink.h>
/* Application includes */
#include "SMO.h"
/* Application Name and Version*/
#define APPLICATION_NAME "6 Ohms Apart Capstone"
#define APPLICATION_VERSION "0.1.0"
#define PROVISIONING (0)
#define PUSH_BUTTONS (0)
/* Priority of Wi-Fi interface in SimpleLink NetSock Driver */
#define SLNET_IF_WIFI_PRIO (5)
#define SPAWN_TASK_PRIORITY (9)
#define TASK_STACK_SIZE (2048)
/* CC3220 Specific */
/* OCP register used to store device role when coming out of hibernate */
/* if ocpRegOffset is set -> AP role, otherwise -> STATION role */
#define OCP_REGISTER_INDEX (0)
#define OCP_REGISTER_OFFSET (10)
#define SSID_LEN_MAX (32)
#define BSSID_LEN_MAX (6)
#define SL_STOP_TIMEOUT (200)
#define SECONDS_SINCE_1900 3815231770
#define SECONDS_BEFORE_UNIX_EPOCH 2208988800
#define TZ_EST_OFFSET_SECS 18000
#define SMALL_BUF 32
#define GMT_TIME_ZONE_HR 1
#define GMT_TIME_ZONE_MIN 00
#define TIMEOUT_SEC 2
#define TIMEOUT_USEC 0
#define DATA_PORT 5004
#define AES256_BLOCKSIZE 16
#define DATE_BLOCKS 2
/* Expiration value for the timer that is being used to toggle the Led. */
#define TIMER_EXPIRATION_VALUE 100 * 1000000
/* Loop forever, user can change it as per application's requirement */
#define LOOP_FOREVER() \
{\
while(1); \
}
/* check the error code and handle it */
#define ASSERT_ON_ERROR(error_code)\
{\
if(error_code < 0) \
{\
ERR_PRINT(error_code);\
return error_code;\
}\
}
/* Basic Macros for Manipulating Status Variables */
#define CLR_STATUS_BIT_ALL(status_variable) (status_variable = 0)
#define SET_STATUS_BIT(status_variable, bit) (status_variable |= (1<<(bit)))
#define CLR_STATUS_BIT(status_variable, bit) (status_variable &= ~(1<<(bit)))
#define CLR_STATUS_BIT_ALL(status_variable) (status_variable = 0)
#define GET_STATUS_BIT(status_variable, bit) (0 != (status_variable & (1<<(bit))))
/* Network Specific Status Bit Macros */
#define IS_NW_PROCSR_ON(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_NwpInit)
#define IS_CONNECTED(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_Connection)
#define IS_IP_LEASED(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_IpLeased)
#define IS_IP_ACQUIRED(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_IpAcquired)
#define IS_IPV6L_ACQUIRED(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_Ipv6lAcquired)
#define IS_IPV6G_ACQUIRED(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_Ipv6gAcquired)
#define IS_SMART_CFG_START(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_SmartconfigStart)
#define IS_CONNECT_FAILED(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_Connection)
#define IS_PING_DONE(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_PingDone)
#define IS_AUTHENTICATION_FAILED(status_variable) \
GET_STATUS_BIT(status_variable, AppStatusBits_AuthenticationFailed)
/* Application specific status/error codes */
typedef enum
{
/* Choosing -0x7D0 to avoid overlap w/ host-driver's error codes */
AppStatusCodes_LanConnectionFailed = -0x7D0,
AppStatusCodes_InternetConnectionFailed = AppStatusCodes_LanConnectionFailed - 1,
AppStatusCodes_DeviceNotInStationMode = AppStatusCodes_InternetConnectionFailed - 1,
AppStatusCodes_StatusCodeMax = -0xBB8
}AppStatusCodes;
typedef enum
{
AppStatusBits_NwpInit = 0, /* If this bit is set: Network Processor is powered up */
AppStatusBits_Connection = 1, /* If this bit is set: the device is connected to the AP or client is connected to device (AP) */
AppStatusBits_IpLeased = 2, /* If this bit is set: the device has leased IP to any connected client */
AppStatusBits_IpAcquired = 3, /* If this bit is set: the device has acquired an IP */
AppStatusBits_SmartconfigStart = 4, /* If this bit is set: the SmartConfiguration process is started from SmartConfig app */
AppStatusBits_P2pDevFound = 5, /* If this bit is set: the device (P2P mode) found any p2p-device in scan */
AppStatusBits_P2pReqReceived = 6, /* If this bit is set: the device (P2P mode) found any p2p-negotiation request */
AppStatusBits_ConnectionFailed = 7, /* If this bit is set: the device(P2P mode) connection to client(or reverse way) is failed */
AppStatusBits_PingDone = 8, /* If this bit is set: the device has completed the ping operation */
AppStatusBits_Ipv6lAcquired = 9, /* If this bit is set: the device has acquired an IPv6 address */
AppStatusBits_Ipv6gAcquired = 10, /* If this bit is set: the device has acquired an IPv6 address */
AppStatusBits_AuthenticationFailed = 11,
AppStatusBits_ResetRequired = 12,
}AppStatusBits;
/* Control block definition */
typedef struct Application_ControlBlock_t
{
/* Network IF Vars */
uint32_t status; /* SimpleLink Status */
uint32_t gatewayIP; /* Network Gateway IP address */
uint32_t staIP; /* Device station IP address */
uint8_t connectionSSID[SSID_LEN_MAX+1]; /* Connection SSID */
uint8_t ssidLen; /* Connection SSID */
uint8_t connectionBSSID[BSSID_LEN_MAX]; /* Connection BSSID */
uint8_t numConnAttempts; /* Number of times device attempted to connect to AP */
/* Application Vars */
bool resetApplication; /* Represents wether there is a pending application reset request */
int32_t apConnectionState; /* Connection state: (0) - connected, (negative) - disconnected */
uint32_t initState; /* Represents what initialization state the MQTT interface is in */
uint32_t timeElapsedSec;
uint32_t timeUGeneralVar;
uint32_t timeUGeneralVar1;
uint8_t timeHostName[SMALL_BUF];
uint16_t timeCCLen;
uint32_t timeDestinationIP;
int32_t timeSockID;
int32_t timeSGeneralVar;
uint8_t time[30];
uint8_t *timeCCPtr;
/* General */
uint16_t timerInts;
timer_t timer;
/* Security */
uint8_t lockUDID[16];
} Application_CB;
typedef struct {
uint8_t ssid[100];
uint8_t passKey[100];
uint8_t secParamType;
uint8_t demoNetworkConfigured;
uint8_t city[100];
int8_t gmtTimeZoneHR;
uint8_t demoCityConfigured;
} demo_Config_t;
#endif