Skip to content
This repository was archived by the owner on Sep 13, 2020. It is now read-only.

Commit 376bc0a

Browse files
committed
Merge pull request #36 from francip/master
Refactoring the RTOS SDK into common and platform-specific
2 parents aa01c02 + 4fe90de commit 376bc0a

21 files changed

+258
-112
lines changed

cc3200/makefile.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ CFLAGS+=-Wall
3333
#
3434
# Where to find header files that do not live in the source directory.
3535
#
36+
IPATH+=$(PARSE_CC3200_SDK_ROOT)/src
3637
IPATH+=${CC3200_SDK_ROOT}/simplelink/include
3738
IPATH+=${CC3200_SDK_ROOT}/driverlib
3839
IPATH+=${CC3200_SDK_ROOT}/oslib

cc3200/src/.cproject

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.DIAG_WRAP.1900016121" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
4343
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.INCLUDE_PATH.245419243" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.INCLUDE_PATH" valueType="includePath">
4444
<listOptionValue builtIn="false" value="&quot;${CG_TOOL_ROOT}/include&quot;"/>
45+
<listOptionValue builtIn="false" value="&quot;${PROJECT_ROOT}&quot;"/>
4546
<listOptionValue builtIn="false" value="&quot;${PARSE_SDK_ROOT}/include&quot;"/>
4647
<listOptionValue builtIn="false" value="&quot;${PARSE_SDK_ROOT}/common&quot;"/>
48+
<listOptionValue builtIn="false" value="&quot;${PARSE_SDK_ROOT}/rtos&quot;"/>
4749
<listOptionValue builtIn="false" value="&quot;${SDK_ROOT}/inc&quot;"/>
4850
<listOptionValue builtIn="false" value="&quot;${SDK_ROOT}/simplelink/include&quot;"/>
4951
<listOptionValue builtIn="false" value="&quot;${SDK_ROOT}/oslib&quot;"/>
@@ -106,8 +108,10 @@
106108
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.DIAG_WRAP.25490248" name="Wrap diagnostic messages (--diag_wrap)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.DIAG_WRAP" value="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.DIAG_WRAP.off" valueType="enumerated"/>
107109
<option id="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.INCLUDE_PATH.2135435920" name="Add dir to #include search path (--include_path, -I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_5.1.compilerID.INCLUDE_PATH" valueType="includePath">
108110
<listOptionValue builtIn="false" value="&quot;${CG_TOOL_ROOT}/include&quot;"/>
111+
<listOptionValue builtIn="false" value="&quot;${PROJECT_ROOT}&quot;"/>
109112
<listOptionValue builtIn="false" value="&quot;${PARSE_SDK_ROOT}/include&quot;"/>
110113
<listOptionValue builtIn="false" value="&quot;${PARSE_SDK_ROOT}/common&quot;"/>
114+
<listOptionValue builtIn="false" value="&quot;${PARSE_SDK_ROOT}/rtos&quot;"/>
111115
<listOptionValue builtIn="false" value="&quot;${SDK_ROOT}/inc&quot;"/>
112116
<listOptionValue builtIn="false" value="&quot;${SDK_ROOT}/simplelink/include&quot;"/>
113117
<listOptionValue builtIn="false" value="&quot;${SDK_ROOT}/oslib&quot;"/>

cc3200/src/.project

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,46 @@
2525
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
2626
</natures>
2727
<linkedResources>
28+
<link>
29+
<name>certificate.c</name>
30+
<type>1</type>
31+
<locationURI>PARSE_SDK_ROOT/rtos/certificate.c</locationURI>
32+
</link>
33+
<link>
34+
<name>http.c</name>
35+
<type>1</type>
36+
<locationURI>PARSE_SDK_ROOT/rtos/http.c</locationURI>
37+
</link>
38+
<link>
39+
<name>installation.c</name>
40+
<type>1</type>
41+
<locationURI>PARSE_SDK_ROOT/rtos/installation.c</locationURI>
42+
</link>
43+
<link>
44+
<name>parse_impl.c</name>
45+
<type>1</type>
46+
<locationURI>PARSE_SDK_ROOT/rtos/parse_impl.c</locationURI>
47+
</link>
48+
<link>
49+
<name>parse_impl.h</name>
50+
<type>1</type>
51+
<locationURI>PARSE_SDK_ROOT/rtos/parse_impl.h</locationURI>
52+
</link>
53+
<link>
54+
<name>push.c</name>
55+
<type>1</type>
56+
<locationURI>PARSE_SDK_ROOT/rtos/push.c</locationURI>
57+
</link>
58+
<link>
59+
<name>request.c</name>
60+
<type>1</type>
61+
<locationURI>PARSE_SDK_ROOT/rtos/request.c</locationURI>
62+
</link>
63+
<link>
64+
<name>session.c</name>
65+
<type>1</type>
66+
<locationURI>PARSE_SDK_ROOT/rtos/session.c</locationURI>
67+
</link>
2868
<link>
2969
<name>simplejson.c</name>
3070
<type>1</type>

cc3200/src/certificate_file.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2015, Parse, LLC. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Parse.
7+
*
8+
* As with any software that integrates with the Parse platform, your use of
9+
* this software is subject to the Parse Terms of Service
10+
* [https://www.parse.com/about/terms]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*
20+
*/
21+
22+
#include <simplelink.h>
23+
24+
#include <stdio.h>
25+
26+
#include <parse_impl.h>
27+
28+
void ensureCertificateFile(const unsigned char *certificate, unsigned int certificateLen) {
29+
long certificateFile = -1;
30+
31+
short status = sl_FsOpen((unsigned char *)SSL_CA_CERT_FILE_NAME, FS_MODE_OPEN_READ, NULL, &certificateFile);
32+
if (status < 0) {
33+
#ifdef SSL_DEBUG
34+
DEBUG_PRINT("[Parse] Creating certificate file\r\n");
35+
#endif /* SSL_DEBUG */
36+
37+
sl_FsClose(certificateFile, 0, 0, 0);
38+
certificateFile = -1;
39+
40+
status = sl_FsOpen((unsigned char *)SSL_CA_CERT_FILE_NAME,
41+
FS_MODE_OPEN_CREATE(65536, _FS_FILE_OPEN_FLAG_COMMIT | _FS_FILE_PUBLIC_WRITE),
42+
NULL, &certificateFile);
43+
if (status < 0) {
44+
#ifdef SSL_DEBUG
45+
DEBUG_PRINT("[Parse] Error creating certificate file: %d\r\n", status);
46+
if (status == SL_FS_ERR_NO_AVAILABLE_BLOCKS) {
47+
DEBUG_PRINT("[Parse] No available blocks. Need to flash your device file system...\r\n");
48+
}
49+
#endif /* SSL_DEBUG */
50+
return;
51+
}
52+
53+
sl_FsClose(certificateFile, 0, 0, 0);
54+
certificateFile = -1;
55+
56+
status = sl_FsOpen((unsigned char *)SSL_CA_CERT_FILE_NAME, FS_MODE_OPEN_WRITE, NULL, &certificateFile);
57+
if (status < 0) {
58+
#ifdef SSL_DEBUG
59+
DEBUG_PRINT("[Parse] Error creating certificate file: %d\r\n", status);
60+
if (status == SL_FS_ERR_NO_AVAILABLE_BLOCKS) {
61+
DEBUG_PRINT("[Parse] No available blocks. Need to flash your device file system...\r\n");
62+
}
63+
#endif /* SSL_DEBUG */
64+
sl_FsClose(certificateFile, 0, 0, 0);
65+
return;
66+
}
67+
68+
status = sl_FsWrite(certificateFile, 0, (unsigned char*)certificate, certificateLen);
69+
if (status < 0) {
70+
#ifdef SSL_DEBUG
71+
DEBUG_PRINT("[Parse] Error creating certificate file: %d\r\n", status);
72+
if (status == SL_FS_ERR_NO_AVAILABLE_BLOCKS) {
73+
DEBUG_PRINT("[Parse] No available blocks. Need to flash your device file system...\r\n");
74+
}
75+
#endif /* SSL_DEBUG */
76+
}
77+
}
78+
79+
sl_FsClose(certificateFile, 0, 0, 0);
80+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include <stdio.h>
2525

26-
#include "parse_impl.h"
26+
#include <parse_impl.h>
2727

2828
char clientStateFileName[CLIENT_STATE_FILENAME_LEN+1];
2929

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <stdlib.h>
3030
#include <stdio.h>
3131

32-
#include "parse_impl.h"
32+
#include <parse_impl.h>
3333

3434
#ifdef CONSOLE_DEBUG
3535
void debugPrint(const char *buffer) {

cc3200/src/makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ ${BINDIR}:
4444
# Rules for building the Simplelink library with os support.
4545
#
4646
${TARGET}: \
47+
${OBJDIR}/certificate_file.o \
48+
${OBJDIR}/client_state.o \
49+
${OBJDIR}/debug.o \
50+
${OBJDIR}/socket.o \
51+
${OBJDIR}/utils.o \
52+
\
53+
${OBJDIR}/certificate.o \
4754
${OBJDIR}/http.o \
4855
${OBJDIR}/installation.o \
4956
${OBJDIR}/parse_impl.o \
5057
${OBJDIR}/push.o \
5158
${OBJDIR}/request.o \
5259
${OBJDIR}/session.o \
53-
${OBJDIR}/simplejson.o \
5460
\
55-
${OBJDIR}/cc3200_certificate.o \
56-
${OBJDIR}/cc3200_client_state.o \
57-
${OBJDIR}/cc3200_debug.o \
58-
${OBJDIR}/cc3200_socket.o \
59-
${OBJDIR}/cc3200_utils.o \
61+
${OBJDIR}/simplejson.o \
6062

6163

6264
#

cc3200/src/platform_impl.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2015, Parse, LLC. All rights reserved.
3+
*
4+
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
5+
* copy, modify, and distribute this software in source code or binary form for use
6+
* in connection with the web services and APIs provided by Parse.
7+
*
8+
* As with any software that integrates with the Parse platform, your use of
9+
* this software is subject to the Parse Terms of Service
10+
* [https://www.parse.com/about/terms]. This copyright notice shall be
11+
* included in all copies or substantial portions of the software.
12+
*
13+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19+
*
20+
*/
21+
22+
#pragma once
23+
24+
#ifndef __PLATFORM_IMPL_H__
25+
#define __PLATFORM_IMPL_H__
26+
27+
#ifdef __cplusplus
28+
extern "C"
29+
{
30+
#endif
31+
32+
#define OS_VERSION_MAX_LEN 19
33+
#define CLIENT_VERSION_MAX_LEN 26
34+
#define CLIENT_VERSION "c-ti-cc3200-rtos-1.0.0"
35+
36+
// Root CA file name
37+
#define SSL_CA_CERT_FILE_NAME "/parse/DigiCertHighAssuranceEVRootCA.der"
38+
39+
#ifdef __cplusplus
40+
}
41+
#endif
42+
43+
#endif /* __PLATFORM_IMPL_H__ */
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <simplelink.h>
2323
#include <socket.h>
2424

25-
#include "parse_impl.h"
25+
#include <parse_impl.h>
2626

2727
#define CONNECT_TIMEOUT_MICROSECONDS 5 * 1000 * 1000
2828
#define READ_SMALL_TIMEOUT_MICROSECONDS 10 * 1000
@@ -66,8 +66,8 @@ short socketSslConnect(const char *host, unsigned short port) {
6666
}
6767

6868
if (status >= 0) {
69-
ensureCertificateFile();
70-
status = sl_SetSockOpt(socketHandle, SL_SOL_SOCKET, SL_SO_SECURE_FILES_CA_FILE_NAME, SL_SSL_CA_CERT_FILE_NAME, strlen(SL_SSL_CA_CERT_FILE_NAME));
69+
ensureCertificate();
70+
status = setsockopt(socketHandle, SOL_SOCKET, SL_SO_SECURE_FILES_CA_FILE_NAME, SSL_CA_CERT_FILE_NAME, strlen(SSL_CA_CERT_FILE_NAME));
7171
}
7272

7373
if (status >= 0) {
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include <stdlib.h>
2626
#include <stdio.h>
2727

28-
#include "parse_impl.h"
29-
30-
char g_osVersion[OS_VERSION_MAX_LEN+1] = {0};
28+
#include <parse_impl.h>
3129

3230
static SlDateTime_t lastDateTime = {0};
3331

@@ -62,7 +60,7 @@ void updateLastPingTime() {
6260
getDeviceTimeDate(&lastDateTime);
6361
}
6462

65-
void fetchDeviceOSVersion() {
63+
void fetchDeviceOSVersion(char *buf, size_t bufLen) {
6664
int status = -1;
6765

6866
unsigned char configOpt = SL_DEVICE_GENERAL_VERSION;
@@ -73,7 +71,7 @@ void fetchDeviceOSVersion() {
7371
status = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &configOpt, &configLen, (unsigned char *)(&ver));
7472

7573
if(status >= 0) {
76-
snprintf(g_osVersion, sizeof(g_osVersion)-1, "%lu.%lu.%lu.%lu", ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2], ver.NwpVersion[3]);
74+
snprintf(buf, bufLen, "%lu.%lu.%lu.%lu", ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2], ver.NwpVersion[3]);
7775
}
7876
}
7977

0 commit comments

Comments
 (0)