From 20ea23ecae9844377f14cb95dc2e7663b63ec850 Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Wed, 9 May 2018 11:06:21 +0200 Subject: [PATCH 1/9] initial- enterprise bool added to wlan --- .../1.0.0/xdk110.platform | 2 ++ .../platform/xdk110/connectivity/WlanGenerator.xtend | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index f7f823ff..31c058d3 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -391,6 +391,8 @@ connectivity named-singleton WLAN { * the WLAN connectivity does not support enterprise WLAN. */ required configuration-item psk : string + + required configuration-item enterprise : bool /** * If true we'll attempt to configure the wireless interface using DHCP and diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend index 1d620872..bc252ab3 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend @@ -67,17 +67,23 @@ class WlanGenerator extends AbstractSystemResourceGenerator { return retcode; } «ENDIF» - - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + + «IF configuration.getBoolean("enterprise")» + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + check + «ELSE» /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the * WlanConnect_WPA function will return only once a connection to the WLAN has been established, * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass * a callback instead of NULL. */ + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to personal network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» retcode = WlanConnect_WPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); if(RETCODE_OK != retcode) { return retcode; } + «ENDIF» + NetworkConfig_IpSettings_T currentIpSettings; retcode = NetworkConfig_GetIpSettings(¤tIpSettings); @@ -106,6 +112,7 @@ class WlanGenerator extends AbstractSystemResourceGenerator { .setPreamble(''' #define NETWORK_SSID "«configuration.getString("ssid")»" #define NETWORK_PSK "«configuration.getString("psk")»" + #define NETWORK_USERNAME "«configuration.getString("username")»" ''') .addHeader('BCDS_Basics.h', true, IncludePath.VERY_HIGH_PRIORITY) .addHeader('BCDS_WlanConnect.h', true, IncludePath.HIGH_PRIORITY) From b52e5d9cbfcd5de4379b10221842dd8ae2835283 Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Thu, 10 May 2018 18:14:29 +0200 Subject: [PATCH 2/9] Enterprise connection in wlan implementation --- .../1.0.0/xdk110.platform | 7 ++-- .../xdk110/connectivity/WlanGenerator.xtend | 35 ++++++++++++++++--- .../xdk110/platform/MakefileGenerator.xtend | 21 ++++++++++- 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index 31c058d3..4e5153c2 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -392,8 +392,9 @@ connectivity named-singleton WLAN { */ required configuration-item psk : string - required configuration-item enterprise : bool - + required configuration-item enterprise : bool //todo add doc + configuration-item IsHostPgmEnabled : bool //todo add doc + configuration-item Username : string //todo add doc /** * If true we'll attempt to configure the wireless interface using DHCP and * all static settings will be ignored. If false, the static settings have to @@ -432,7 +433,7 @@ connectivity named-singleton WLAN { * is recommended. */ configuration-item staticMask : string - + } exception MqttException; diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend index bc252ab3..330e8cac 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend @@ -36,7 +36,6 @@ class WlanGenerator extends AbstractSystemResourceGenerator { override generateEnable() { codeFragmentProvider.create(''' Retcode_T retcode; - retcode_t servalRetcode; retcode = WlanConnect_Init(); if(RETCODE_OK != retcode) @@ -70,7 +69,31 @@ class WlanGenerator extends AbstractSystemResourceGenerator { «IF configuration.getBoolean("enterprise")» «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» - check + + «IF configuration.getBoolean("IsHostPgmEnabled")» + retcode = WLANHostPgm_Enable(); + /* disable server authentication */ + unsigned char pValues; + pValues = 0; //0 - Disable the server authentication | 1 - Enable (this is the default) + if (0U != sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, 19, 1, &pValues)) + { + return RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_WLAN_SL_SET_FAILED); + } + /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the + * WlanConnect_WPA function will return only once a connection to the WLAN has been established, + * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass + * a callback instead of NULL. */ + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to personal network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + retcode = WlanConnect_EnterpriseWPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_Username_T) NETWORK_USERNAME, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); +««« retcode = WlanConnect_WPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); + if(RETCODE_OK != retcode) + { + return retcode; + } + «ELSE» + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network without host programming")» + «ENDIF» + «ELSE» /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the * WlanConnect_WPA function will return only once a connection to the WLAN has been established, @@ -84,7 +107,6 @@ class WlanGenerator extends AbstractSystemResourceGenerator { } «ENDIF» - NetworkConfig_IpSettings_T currentIpSettings; retcode = NetworkConfig_GetIpSettings(¤tIpSettings); if(RETCODE_OK != retcode) @@ -110,15 +132,18 @@ class WlanGenerator extends AbstractSystemResourceGenerator { return RETCODE_OK; ''') .setPreamble(''' - #define NETWORK_SSID "«configuration.getString("ssid")»" + #define NETWORK_SSID "«configuration.getString("ssid")»" #define NETWORK_PSK "«configuration.getString("psk")»" - #define NETWORK_USERNAME "«configuration.getString("username")»" + #define NETWORK_USERNAME "«configuration.getString("username")»" ''') + .addHeader('XdkCommonInfo.h', true, IncludePath.HIGH_PRIORITY) .addHeader('BCDS_Basics.h', true, IncludePath.VERY_HIGH_PRIORITY) .addHeader('BCDS_WlanConnect.h', true, IncludePath.HIGH_PRIORITY) .addHeader('BCDS_NetworkConfig.h', true, IncludePath.HIGH_PRIORITY) + .addHeader('WLANHostPgm.h', true, IncludePath.HIGH_PRIORITY) .addHeader('Serval_Network.h', true, IncludePath.HIGH_PRIORITY) .addHeader('Serval_Ip.h', true, IncludePath.HIGH_PRIORITY) + .addHeader('wlan.h', true, IncludePath.HIGH_PRIORITY) } } diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend index 9fb3f967..6514f056 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend @@ -43,12 +43,31 @@ class MakefileGenerator implements IPlatformMakefileGenerator { #and if any addition flags required then add that flags only in the below macro #export BCDS_CFLAGS_COMMON = + + # This variable should fully specify the build configuration of the Serval + # Stack library with regards the enabled and disabled features for the HTTPS Using TLS. + export SERVAL_ENABLE_TLS_CLIENT=1 + export SERVAL_ENABLE_TLS_ECC=1 + export SERVAL_ENABLE_TLS_PSK=0 + export SERVAL_ENABLE_DTLS_PSK=0 + export SERVAL_ENABLE_DTLS_ECC=1 + export SERVAL_MAX_NUM_MESSAGES=8 + export SERVAL_MAX_SIZE_APP_PACKET=900 + export SERVAL_ENABLE_TLS=1 + export EscTls_CIPHER_SUITE=TLS_RSA_WITH_AES_128_CBC_SHA + + export BCDS_SERVALSTACK_MACROS = \ + -D SERVAL_CYCURTLS_HANDSHAKE_BUFFER_SIZE=5500 + #List all the application header file under variable BCDS_XDK_INCLUDES export BCDS_XDK_INCLUDES = \ -I$(BCDS_BASE_DIR)/xdk110/Libraries/BSTLib/3rd-party/bstlib/BMA2x2_driver \ -I$(BCDS_APP_SOURCE_DIR) \ -I$(BCDS_APP_SOURCE_DIR)/.. \ - -I$(BCDS_APP_SOURCE_DIR)/base + -I$(BCDS_APP_SOURCE_DIR)/base \ + -I$(BCDS_BASE_DIR)/xdk110/Common/include \ + -I$(BCDS_BASE_DIR)/xdk110/Common/certs/XDKDummy \ + -I$(BCDS_BASE_DIR)/xdk110/Common/source #List all the application source file under variable BCDS_XDK_APP_SOURCE_FILES in a similar pattern as below export BCDS_XDK_APP_SOURCE_FILES = \ From 7b020daf7ca7294a795e4dedb8f79b107c114253 Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Mon, 14 May 2018 12:18:12 +0200 Subject: [PATCH 3/9] Improved documentation in platform file --- .../1.0.0/xdk110.platform | 21 +++++++++++++------ .../xdk110/connectivity/WlanGenerator.xtend | 7 ++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index 4e5153c2..e80b551c 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -387,14 +387,24 @@ connectivity named-singleton WLAN { /** * The pre-shared key of the WLAN we're connecting to. Note that this - * setting implies WPA2-PSK as authentication method. At this moment - * the WLAN connectivity does not support enterprise WLAN. + * setting implies WPA2-PSK as authentication method. */ required configuration-item psk : string - required configuration-item enterprise : bool //todo add doc - configuration-item IsHostPgmEnabled : bool //todo add doc - configuration-item Username : string //todo add doc + /** + * If true we'll establish enterprise WLAN connectivity. If false, personal WLAN connectivity. + */ + required configuration-item enterprise : bool + + /** + * If true certificate will be uploaded for WiFi chip. + */ + configuration-item IsHostPgmEnabled : bool + + /** + * The username of the WLAN network we want to connect to. + */ + configuration-item Username : string /** * If true we'll attempt to configure the wireless interface using DHCP and * all static settings will be ignored. If false, the static settings have to @@ -433,7 +443,6 @@ connectivity named-singleton WLAN { * is recommended. */ configuration-item staticMask : string - } exception MqttException; diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend index 330e8cac..fe8f9109 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend @@ -71,6 +71,8 @@ class WlanGenerator extends AbstractSystemResourceGenerator { «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» «IF configuration.getBoolean("IsHostPgmEnabled")» + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network with host programming")» + retcode = WLANHostPgm_Enable(); /* disable server authentication */ unsigned char pValues; @@ -80,12 +82,11 @@ class WlanGenerator extends AbstractSystemResourceGenerator { return RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_WLAN_SL_SET_FAILED); } /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the - * WlanConnect_WPA function will return only once a connection to the WLAN has been established, + * WlanConnect_EnterpriseWPA function will return only once a connection to the WLAN has been established, * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass * a callback instead of NULL. */ - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to personal network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + retcode = WlanConnect_EnterpriseWPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_Username_T) NETWORK_USERNAME, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); -««« retcode = WlanConnect_WPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); if(RETCODE_OK != retcode) { return retcode; From 64286f18ec47c732c6e5f6e47b30ed05e8739716 Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Tue, 15 May 2018 15:21:50 +0200 Subject: [PATCH 4/9] WLAN enterprise validator implemented --- .../1.0.0/xdk110.platform | 2 +- .../xdk110/connectivity/WlanGenerator.xtend | 13 +++++------- .../xdk110/connectivity/WlanValidator.xtend | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index e80b551c..26307c55 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -404,7 +404,7 @@ connectivity named-singleton WLAN { /** * The username of the WLAN network we want to connect to. */ - configuration-item Username : string + configuration-item userName : string /** * If true we'll attempt to configure the wireless interface using DHCP and * all static settings will be ignored. If false, the static settings have to diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend index fe8f9109..389d6458 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend @@ -69,10 +69,8 @@ class WlanGenerator extends AbstractSystemResourceGenerator { «IF configuration.getBoolean("enterprise")» «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» - - «IF configuration.getBoolean("IsHostPgmEnabled")» - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network with host programming")» - + «IF configuration.getBoolean("IsHostPgmEnabled")» + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network with host programming")» retcode = WLANHostPgm_Enable(); /* disable server authentication */ unsigned char pValues; @@ -91,16 +89,15 @@ class WlanGenerator extends AbstractSystemResourceGenerator { { return retcode; } - «ELSE» + «ELSE» «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network without host programming")» - «ENDIF» - + «ENDIF» «ELSE» /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the * WlanConnect_WPA function will return only once a connection to the WLAN has been established, * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass * a callback instead of NULL. */ - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to personal network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to personal network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» retcode = WlanConnect_WPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); if(RETCODE_OK != retcode) { diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend index ffcccee3..dae92e93 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend @@ -31,6 +31,7 @@ class WlanValidator implements IResourceValidator { override validate(Program program, EObject context, ValidationMessageAcceptor acceptor) { if(context instanceof SystemResourceSetup) { validateNetworkConfig(context, acceptor); + validateEnterprise(context, acceptor); } } @@ -69,4 +70,23 @@ class WlanValidator implements IResourceValidator { } + protected def validateEnterprise(SystemResourceSetup setup, ValidationMessageAcceptor acceptor) { + val enterpriseConfigItem = setup.configurationItemValues.findFirst[ it.item.name == "enterprise" ]; + val useEnterprise = if(enterpriseConfigItem === null) { + true + } else { + StaticValueInferrer.infer(enterpriseConfigItem.value, []) as Boolean; + } + + if(useEnterprise) { + val enterpriseHost = setup.configurationItemValues.findFirst[ it.item.name == "IsHostPgmEnabled" ]; + if(enterpriseHost === null) { + acceptor.acceptError("With enterprise set true, IsHostPgmEnabled must be configured", setup, ProgramPackage.Literals.SYSTEM_RESOURCE_SETUP__TYPE, 0, "network_IsHostPgmEnabled_not_conf"); + } + val userName = setup.configurationItemValues.findFirst[ it.item.name == "userName" ]; + if(userName === null) { + acceptor.acceptError("With enterprise set true, userName must be configured", setup, ProgramPackage.Literals.SYSTEM_RESOURCE_SETUP__TYPE, 0, "network_userName_not_conf"); + } + } + } } \ No newline at end of file From 7d863ffd273ec7e677882580c673e784ef9c8782 Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Tue, 15 May 2018 17:30:03 +0200 Subject: [PATCH 5/9] Fixed review comments: remove http macros from make file, improved documentation of IsHostProgramming argument Signed-off-by: Padmapriya Govindasamy (RBEI/EAC5) --- .../1.0.0/xdk110.platform | 4 +++- .../xdk110/connectivity/WlanGenerator.xtend | 5 ++++- .../xdk110/platform/MakefileGenerator.xtend | 15 --------------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index 26307c55..9b8c92e2 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -397,7 +397,9 @@ connectivity named-singleton WLAN { required configuration-item enterprise : bool /** - * If true certificate will be uploaded for WiFi chip. + * If true server certificate will be uploaded to the WiFi chip CC3100. + * Make sure to update service pack of the WiFi and then upload the certificate. + * Certificate must placed under XDK110/common/certs/XDKDummy. */ configuration-item IsHostPgmEnabled : bool diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend index 389d6458..46a78047 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend @@ -83,12 +83,15 @@ class WlanGenerator extends AbstractSystemResourceGenerator { * WlanConnect_EnterpriseWPA function will return only once a connection to the WLAN has been established, * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass * a callback instead of NULL. */ - retcode = WlanConnect_EnterpriseWPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_Username_T) NETWORK_USERNAME, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); if(RETCODE_OK != retcode) { return retcode; } + else + { + vTaskDelay(pdMS_TO_TICKS(1000)); + } «ELSE» «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network without host programming")» «ENDIF» diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend index 6514f056..63d402fe 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/MakefileGenerator.xtend @@ -44,21 +44,6 @@ class MakefileGenerator implements IPlatformMakefileGenerator { #export BCDS_CFLAGS_COMMON = - # This variable should fully specify the build configuration of the Serval - # Stack library with regards the enabled and disabled features for the HTTPS Using TLS. - export SERVAL_ENABLE_TLS_CLIENT=1 - export SERVAL_ENABLE_TLS_ECC=1 - export SERVAL_ENABLE_TLS_PSK=0 - export SERVAL_ENABLE_DTLS_PSK=0 - export SERVAL_ENABLE_DTLS_ECC=1 - export SERVAL_MAX_NUM_MESSAGES=8 - export SERVAL_MAX_SIZE_APP_PACKET=900 - export SERVAL_ENABLE_TLS=1 - export EscTls_CIPHER_SUITE=TLS_RSA_WITH_AES_128_CBC_SHA - - export BCDS_SERVALSTACK_MACROS = \ - -D SERVAL_CYCURTLS_HANDSHAKE_BUFFER_SIZE=5500 - #List all the application header file under variable BCDS_XDK_INCLUDES export BCDS_XDK_INCLUDES = \ -I$(BCDS_BASE_DIR)/xdk110/Libraries/BSTLib/3rd-party/bstlib/BMA2x2_driver \ From c67fee9cc3e33b8f3e5c7b3f494c468d48f53299 Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Tue, 15 May 2018 18:12:19 +0200 Subject: [PATCH 6/9] Review comments addressed: coding std, return handling Signed-off-by: Padmapriya Govindasamy (RBEI/EAC5) --- .../1.0.0/xdk110.platform | 2 +- .../platform/xdk110/connectivity/WlanGenerator.xtend | 10 ++++++++-- .../platform/xdk110/connectivity/WlanValidator.xtend | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index 9b8c92e2..68ce2621 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -401,7 +401,7 @@ connectivity named-singleton WLAN { * Make sure to update service pack of the WiFi and then upload the certificate. * Certificate must placed under XDK110/common/certs/XDKDummy. */ - configuration-item IsHostPgmEnabled : bool + configuration-item isHostPgmEnabled : bool /** * The username of the WLAN network we want to connect to. diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend index 46a78047..10916a74 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend @@ -69,16 +69,22 @@ class WlanGenerator extends AbstractSystemResourceGenerator { «IF configuration.getBoolean("enterprise")» «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» - «IF configuration.getBoolean("IsHostPgmEnabled")» + «IF configuration.getBoolean("isHostPgmEnabled")» «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network with host programming")» retcode = WLANHostPgm_Enable(); + if(RETCODE_OK != retcode) + { + return retcode; + } + /* disable server authentication */ unsigned char pValues; pValues = 0; //0 - Disable the server authentication | 1 - Enable (this is the default) if (0U != sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, 19, 1, &pValues)) { - return RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_WLAN_SL_SET_FAILED); + return RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_WLAN_SL_SET_FAILED); } + /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the * WlanConnect_EnterpriseWPA function will return only once a connection to the WLAN has been established, * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend index dae92e93..3541b7b3 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend @@ -77,11 +77,11 @@ class WlanValidator implements IResourceValidator { } else { StaticValueInferrer.infer(enterpriseConfigItem.value, []) as Boolean; } - + if(useEnterprise) { - val enterpriseHost = setup.configurationItemValues.findFirst[ it.item.name == "IsHostPgmEnabled" ]; + val enterpriseHost = setup.configurationItemValues.findFirst[ it.item.name == "isHostPgmEnabled" ]; if(enterpriseHost === null) { - acceptor.acceptError("With enterprise set true, IsHostPgmEnabled must be configured", setup, ProgramPackage.Literals.SYSTEM_RESOURCE_SETUP__TYPE, 0, "network_IsHostPgmEnabled_not_conf"); + acceptor.acceptError("With enterprise set true, isHostPgmEnabled must be configured", setup, ProgramPackage.Literals.SYSTEM_RESOURCE_SETUP__TYPE, 0, "network_IsHostPgmEnabled_not_conf"); } val userName = setup.configurationItemValues.findFirst[ it.item.name == "userName" ]; if(userName === null) { From 50758db28447ef50654e997005ed294c9b43122a Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Wed, 16 May 2018 11:42:04 +0200 Subject: [PATCH 7/9] Review comment fixed: enum for connectivity type Signed-off-by: Padmapriya Govindasamy (RBEI/EAC5) --- .../inferrer/StaticValueInferrer.xtend | 9 ++++- .../1.0.0/xdk110.platform | 16 +++++--- .../xdk110/connectivity/WlanGenerator.xtend | 37 +++++++++--------- .../xdk110/connectivity/WlanValidator.xtend | 39 +++++++++++-------- 4 files changed, 58 insertions(+), 43 deletions(-) diff --git a/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/StaticValueInferrer.xtend b/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/StaticValueInferrer.xtend index d01f536b..a376f389 100644 --- a/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/StaticValueInferrer.xtend +++ b/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/StaticValueInferrer.xtend @@ -13,9 +13,9 @@ package org.eclipse.mita.program.inferrer +import org.eclipse.emf.ecore.EObject import org.eclipse.mita.program.ValueRange import org.eclipse.mita.program.VariableDeclaration -import org.eclipse.emf.ecore.EObject import org.yakindu.base.expressions.expressions.BoolLiteral import org.yakindu.base.expressions.expressions.DoubleLiteral import org.yakindu.base.expressions.expressions.ElementReferenceExpression @@ -25,6 +25,7 @@ import org.yakindu.base.expressions.expressions.IntLiteral import org.yakindu.base.expressions.expressions.NumericalUnaryExpression import org.yakindu.base.expressions.expressions.PrimitiveValueExpression import org.yakindu.base.expressions.expressions.StringLiteral +import org.yakindu.base.types.Enumerator /** * Infers the value of an expression at compile time. @@ -51,6 +52,10 @@ class StaticValueInferrer { return expression.value; } + static dispatch def Object infer(Enumerator expression, (EObject) => void inferenceBlockerAcceptor) { + return expression; + } + static dispatch def Object infer(NumericalUnaryExpression expression, (EObject) => void inferenceBlockerAcceptor) { val inner = expression.operand.infer(inferenceBlockerAcceptor); if(inner === null || !(inner instanceof Integer || inner instanceof Float)) { @@ -85,7 +90,7 @@ class StaticValueInferrer { return expression.initialization?.infer(inferenceBlockerAcceptor); } } - + static dispatch def Object infer(ValueRange expression, (EObject) => void inferenceBlockerAcceptor) { val lower = expression.lowerBound?.infer(inferenceBlockerAcceptor); if(expression.lowerBound !== null && lower === null) return null; diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index 68ce2621..3c78d98e 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -373,6 +373,10 @@ sensor Button { event released } +enum ConnectivityType { + Personal, + Enterprise +} /** * Specifies the connection to a wireless wide-area network, also refered to as WiFi. */ @@ -380,6 +384,11 @@ connectivity named-singleton WLAN { generator "org.eclipse.mita.platform.xdk110.connectivity.WlanGenerator" validator "org.eclipse.mita.platform.xdk110.connectivity.WlanValidator" + /** + * Choose personal WPA connection or Enterprise WPA connection + */ + required configuration-item connection : ConnectivityType + /** * The SSID of the WLAN network we want to connect to. */ @@ -390,12 +399,7 @@ connectivity named-singleton WLAN { * setting implies WPA2-PSK as authentication method. */ required configuration-item psk : string - - /** - * If true we'll establish enterprise WLAN connectivity. If false, personal WLAN connectivity. - */ - required configuration-item enterprise : bool - + /** * If true server certificate will be uploaded to the WiFi chip CC3100. * Make sure to update service pack of the WiFi and then upload the certificate. diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend index 10916a74..0486f800 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanGenerator.xtend @@ -66,17 +66,30 @@ class WlanGenerator extends AbstractSystemResourceGenerator { return retcode; } «ENDIF» - - «IF configuration.getBoolean("enterprise")» - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + + «IF configuration.getEnumerator("connection").name == "Personal"» + /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the + * WlanConnect_WPA function will return only once a connection to the WLAN has been established, + * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass + * a callback instead of NULL. */ + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to personal network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + retcode = WlanConnect_WPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); + if(RETCODE_OK != retcode) + { + return retcode; + } + «ELSEIF configuration.getEnumerator("connection").name == "Enterprise"» «IF configuration.getBoolean("isHostPgmEnabled")» - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network with host programming")» + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network with host programming: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» retcode = WLANHostPgm_Enable(); if(RETCODE_OK != retcode) { return retcode; } - + «ELSE» + «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network without host programming: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» + «ENDIF» + /* disable server authentication */ unsigned char pValues; pValues = 0; //0 - Disable the server authentication | 1 - Enable (this is the default) @@ -99,19 +112,7 @@ class WlanGenerator extends AbstractSystemResourceGenerator { vTaskDelay(pdMS_TO_TICKS(1000)); } «ELSE» - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to enterprise network without host programming")» - «ENDIF» - «ELSE» - /* Passing NULL as onConnection callback (last parameter) makes this a blocking call, i.e. the - * WlanConnect_WPA function will return only once a connection to the WLAN has been established, - * or if something went wrong while trying to do so. If you wanted non-blocking behavior, pass - * a callback instead of NULL. */ - «loggingGenerator.generateLogStatement(LogLevel.Info, "Connecting to personal network: %s", codeFragmentProvider.create('''NETWORK_SSID'''))» - retcode = WlanConnect_WPA((WlanConnect_SSID_T) NETWORK_SSID, (WlanConnect_PassPhrase_T) NETWORK_PSK, NULL); - if(RETCODE_OK != retcode) - { - return retcode; - } + «loggingGenerator.generateLogStatement(LogLevel.Info, "Invalid connection type")» «ENDIF» NetworkConfig_IpSettings_T currentIpSettings; diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend index 3541b7b3..06f14eff 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/connectivity/WlanValidator.xtend @@ -21,6 +21,10 @@ import org.eclipse.mita.program.validation.IResourceValidator import java.util.regex.Pattern import org.eclipse.emf.ecore.EObject import org.eclipse.xtext.validation.ValidationMessageAcceptor +import java.util.Enumeration +import org.eclipse.xtext.xbase.scoping.featurecalls.StaticImplicitMethodsFeatureForTypeProvider.ExtensionClassNameProvider +import org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransient +import org.yakindu.base.types.Enumerator class WlanValidator implements IResourceValidator { @@ -31,7 +35,7 @@ class WlanValidator implements IResourceValidator { override validate(Program program, EObject context, ValidationMessageAcceptor acceptor) { if(context instanceof SystemResourceSetup) { validateNetworkConfig(context, acceptor); - validateEnterprise(context, acceptor); + validateConnectivityType(context, acceptor); } } @@ -70,23 +74,24 @@ class WlanValidator implements IResourceValidator { } - protected def validateEnterprise(SystemResourceSetup setup, ValidationMessageAcceptor acceptor) { - val enterpriseConfigItem = setup.configurationItemValues.findFirst[ it.item.name == "enterprise" ]; - val useEnterprise = if(enterpriseConfigItem === null) { - true - } else { - StaticValueInferrer.infer(enterpriseConfigItem.value, []) as Boolean; + protected def validateConnectivityType(SystemResourceSetup setup, ValidationMessageAcceptor acceptor) { + + val connectivityConfigItem = setup.configurationItemValues.findFirst[x | x.item.name == 'connection']; + val enterpriseOrPersonal = StaticValueInferrer.infer(connectivityConfigItem.value, []); + if(enterpriseOrPersonal instanceof Enumerator) { + if(enterpriseOrPersonal.name == "Enterprise") { + val enterpriseHost = setup.configurationItemValues.findFirst[ it.item.name == "isHostPgmEnabled" ]; + if(enterpriseHost === null) { + acceptor.acceptError("With enterprise set true, isHostPgmEnabled must be configured", connectivityConfigItem, ProgramPackage.Literals.CONFIGURATION_ITEM_VALUE__VALUE, 0, "network_IsHostPgmEnabled_not_conf"); + } + val userName = setup.configurationItemValues.findFirst[ it.item.name == "userName" ]; + if(userName === null) { + acceptor.acceptError("With enterprise set true, userName must be configured", connectivityConfigItem, ProgramPackage.Literals.CONFIGURATION_ITEM_VALUE__VALUE, 0, "network_userName_not_conf"); + } + } } - - if(useEnterprise) { - val enterpriseHost = setup.configurationItemValues.findFirst[ it.item.name == "isHostPgmEnabled" ]; - if(enterpriseHost === null) { - acceptor.acceptError("With enterprise set true, isHostPgmEnabled must be configured", setup, ProgramPackage.Literals.SYSTEM_RESOURCE_SETUP__TYPE, 0, "network_IsHostPgmEnabled_not_conf"); - } - val userName = setup.configurationItemValues.findFirst[ it.item.name == "userName" ]; - if(userName === null) { - acceptor.acceptError("With enterprise set true, userName must be configured", setup, ProgramPackage.Literals.SYSTEM_RESOURCE_SETUP__TYPE, 0, "network_userName_not_conf"); - } + else { + acceptor.acceptError("We should never get here", setup, null, 0, null); } } } \ No newline at end of file From 709a77424ecc7b52b3a7d2d356cc2a82ee4e490e Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC5)" Date: Thu, 8 Nov 2018 10:38:18 +0530 Subject: [PATCH 8/9] sd card added to xdk110 platform Signed-off-by: Padmapriya Govindasamy (RBEI/EAC5) --- .../program/generator/GeneratorUtils.xtend | 1 + .../GenericPlatformSizeInferrer.xtend | 8 +- .../1.0.0/xdk110.platform | 23 ++ .../platform/xdk110/io/SDCardGenerator.xtend | 229 ++++++++++++++++++ .../xdk110/io/SDCardSizeInferrer.xtend | 25 ++ .../platform/xdk110/platform/Validation.xtend | 22 +- 6 files changed, 305 insertions(+), 3 deletions(-) create mode 100644 platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardGenerator.xtend create mode 100644 platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardSizeInferrer.xtend diff --git a/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/generator/GeneratorUtils.xtend b/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/generator/GeneratorUtils.xtend index 9877c3d4..2292b051 100644 --- a/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/generator/GeneratorUtils.xtend +++ b/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/generator/GeneratorUtils.xtend @@ -32,6 +32,7 @@ import org.eclipse.mita.base.types.SumType import org.eclipse.mita.platform.AbstractSystemResource import org.eclipse.mita.platform.Bus import org.eclipse.mita.platform.Connectivity +import org.eclipse.mita.platform.InputOutput import org.eclipse.mita.platform.Modality import org.eclipse.mita.platform.Platform import org.eclipse.mita.platform.Sensor diff --git a/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/GenericPlatformSizeInferrer.xtend b/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/GenericPlatformSizeInferrer.xtend index f2449787..f641aba1 100644 --- a/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/GenericPlatformSizeInferrer.xtend +++ b/bundles/org.eclipse.mita.program/src/org/eclipse/mita/program/inferrer/GenericPlatformSizeInferrer.xtend @@ -10,7 +10,11 @@ import org.eclipse.mita.base.expressions.FeatureCall import org.eclipse.mita.base.expressions.ElementReferenceExpression class GenericPlatformSizeInferrer extends ElementSizeInferrer { - + + def String getLengthParameterName(SignalInstance sigInst) { + return 'length'; + } + override infer(EObject obj) { val instance = if(obj instanceof ElementReferenceExpression) { if(obj.isOperationCall && obj.arguments.size > 0) { @@ -36,7 +40,7 @@ class GenericPlatformSizeInferrer extends ElementSizeInferrer { if(instance instanceof FeatureCall) { val signal = instance.feature; if(signal instanceof SignalInstance) { - val lengthArg = ModelUtils.getArgumentValue(signal, 'length'); + val lengthArg = ModelUtils.getArgumentValue(signal, signal.lengthParameterName); if(lengthArg !== null) { val maxLength = StaticValueInferrer.infer(lengthArg, [ ]); return newValidResult(obj, maxLength as Integer); diff --git a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform index 7ae4df50..97d576b1 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform +++ b/platforms/org.eclipse.mita.platform.xdk110/1.0.0/xdk110.platform @@ -986,6 +986,27 @@ bus named-singleton GPIO { signal digitalOut(pin : GPIOPin, initialValue : bool = false) : bool } +exception EndOfFileException + +io named-singleton SDCard { + generator "org.eclipse.mita.platform.xdk110.io.SDCardGenerator" + sizeInferrer "org.eclipse.mita.platform.xdk110.io.SDCardSizeInferrer" + + signal appendingFile_Text_Read(filePath: string, blockSize: uint32) : string + signal appendingFile_Text_Write(filePath: string) : string + + signal rewindingFile_Text_Read(filePath: string, fileSize: uint32) : string + signal rewindingFile_Text_Write(filePath: string) : string + + signal appendingFile_Binary_Read(filePath: string, blockSize: uint32) : array + signal appendingFile_Binary_Write(filePath: string) : array + + signal rewindingFile_Binary_Read(filePath: string, fileSize: uint32) : array + signal rewindingFile_Binary_Write(filePath: string) : array + + modality SDCardAvailable +} + alias environment for BME280 alias accelerometer for BMA280 @@ -1021,6 +1042,8 @@ platform XDK110 { has HonoMqtt has HttpRestClient + has SDCard + configuration-item applicationName : string = "EclipseMitaApplication" /** * Enabling this powers the 2.5V and 3.3V external power on the extension bus. diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardGenerator.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardGenerator.xtend new file mode 100644 index 00000000..0b686dbe --- /dev/null +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardGenerator.xtend @@ -0,0 +1,229 @@ +/******************************************************************************** + * Copyright (c) 2017, 2018 Bosch Connected Devices and Solutions GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * Contributors: + * Bosch Connected Devices and Solutions GmbH - initial contribution + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ + +package org.eclipse.mita.platform.xdk110.io + +import org.eclipse.mita.program.SignalInstance +import org.eclipse.mita.program.generator.AbstractSystemResourceGenerator +import org.eclipse.mita.program.generator.CodeFragment.IncludePath +import org.eclipse.mita.program.inferrer.StaticValueInferrer +import org.eclipse.mita.program.model.ModelUtils +import org.eclipse.mita.program.generator.CodeFragment + +import com.google.inject.Inject +import org.eclipse.mita.program.generator.IPlatformLoggingGenerator +import org.eclipse.mita.program.generator.IPlatformLoggingGenerator.LogLevel + +class SDCardGenerator extends AbstractSystemResourceGenerator { + + @Inject(optional=true) + protected IPlatformLoggingGenerator loggingGenerator + + override generateSetup() { + codeFragmentProvider.create(''' + ''').addHeader('BCDS_Basics.h', true, IncludePath.VERY_HIGH_PRIORITY).addHeader('BCDS_Retcode.h', true, + IncludePath.VERY_HIGH_PRIORITY).addHeader("FreeRTOS.h", true, IncludePath.HIGH_PRIORITY).addHeader("task.h", + true).addHeader("string.h", true).addHeader("XdkCommonInfo.h", true).addHeader("ff.h", true).addHeader( + "BCDS_SDCard_Driver.h", true).setPreamble(''' + static FATFS StorageSDCardFatFSObject; /** File system specific objects */ + /**< Macro to define default logical drive */ + #define STORAGE_DEFAULT_LOGICAL_DRIVE "" + + /**< Macro to define force mount */ + #define STORAGE_SDCARD_FORCE_MOUNT UINT8_C(1) + + /**< SD Card Drive 0 location */ + #define STORAGE_SDCARD_DRIVE_NUMBER UINT8_C(0) + + «FOR sigInst : setup.signalInstances» + «IF sigInst.instanceOf.name.startsWith("appendingFile")» + static uint16_t «sigInst.name»FilePosition = 0UL; + «ENDIF» + «ENDFOR» + + ''') + + } + + def CodeFragment getSize(SignalInstance instance) { + val result = StaticValueInferrer.infer(ModelUtils.getArgumentValue(instance, instance.sizeName), []); + if (result instanceof Integer) { + return codeFragmentProvider.create('''«result»'''); + } else { + return codeFragmentProvider.create('''-1'''); + } + + } + + static def String getSizeName(SignalInstance instance) { + if (instance.instanceOf.name.startsWith("appendingFile")) { + return "blockSize"; + } else { + return "fileSize"; + } + } + + override generateEnable() { + codeFragmentProvider.create(''' + Retcode_T retcode = RETCODE_OK; + retcode = SDCardDriver_Initialize(); + if (RETCODE_OK == retcode) + { + if (SDCARD_INSERTED != SDCardDriver_GetDetectStatus()) + { + «loggingGenerator.generateLogStatement(LogLevel.Error, "SD card was not detected for Storage")» + retcode = RETCODE(RETCODE_SEVERITY_WARNING, RETCODE_STORAGE_SDCARD_NOT_AVAILABLE); + } + } + if (RETCODE_OK == retcode) + { + retcode = SDCardDriver_DiskInitialize(STORAGE_SDCARD_DRIVE_NUMBER); /* Initialize SD card */ + } + if (RETCODE_OK == retcode) + { + /* Initialize file system */ + if (FR_OK != f_mount(&StorageSDCardFatFSObject, STORAGE_DEFAULT_LOGICAL_DRIVE, STORAGE_SDCARD_FORCE_MOUNT)) + { + retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_STORAGE_SDCARD_MOUNT_FAILED); + } + } + return retcode; + ''') + } + + override generateSignalInstanceGetter(SignalInstance sigInst, String valueVariableName) { + val data = sigInst.dataAccessor(valueVariableName); + val len = sigInst.getSize; + val filename = sigInst.filenameAccessor(valueVariableName); + val fileSeekIndex = if (sigInst.instanceOf.name.startsWith("appendingFile")) { + codeFragmentProvider.create('''«sigInst.name»FilePosition'''); + } else { + codeFragmentProvider.create('''0'''); + } + codeFragmentProvider.create(''' + Retcode_T retcode = RETCODE_OK; + FRESULT sdCardReturn = FR_OK, fileOpenReturn = FR_OK; + FILINFO sdCardFileInfo; + #if _USE_LFN + sdCardFileInfo.lfname = NULL; + #endif + FIL fileReadHandle; + UINT bytesRead; + + sdCardReturn = f_stat(«filename», &sdCardFileInfo); + if (FR_OK == sdCardReturn) + { + if(«fileSeekIndex» >= sdCardFileInfo.fsize) + { + return EXCEPTION_ENDOFFILEEXCEPTION; + } + else + { + fileOpenReturn = f_open(&fileReadHandle, «filename», FA_OPEN_EXISTING | FA_READ); + } + } + if ((FR_OK == sdCardReturn) && (FR_OK == fileOpenReturn)) + { + sdCardReturn = f_lseek(&fileReadHandle, «fileSeekIndex»); + } + if ((FR_OK == sdCardReturn) && (FR_OK == fileOpenReturn)) + { + sdCardReturn = f_read(&fileReadHandle, «data», «len», &bytesRead); /* Read a chunk of source file */ + } + if ((FR_OK == sdCardReturn) && (FR_OK == fileOpenReturn)) + { + «IF sigInst.instanceOf.name.startsWith("appendingFile")» + «sigInst.name»FilePosition += bytesRead; + «ENDIF» + } + if (FR_OK == fileOpenReturn) + { + sdCardReturn = f_close(&fileReadHandle); + } + if ((FR_OK != sdCardReturn) || (FR_OK != fileOpenReturn)) + { + retcode = RETCODE(RETCODE_SEVERITY_ERROR, RETCODE_STORAGE_SDCARD_READ_FAILED); + } + return retcode; + ''') + .addHeader("MitaExceptions.h", false) + } + + override generateSignalInstanceSetter(SignalInstance sigInst, String valueVariableName) { + val data = sigInst.dataAccessor(valueVariableName); + val len = sigInst.lenAccessor(valueVariableName); + val filename = sigInst.filenameAccessor(valueVariableName); + val fileSeekIndex = if (sigInst.instanceOf.name.startsWith("appendingFile")) { + codeFragmentProvider.create('''«sigInst.name»FilePosition'''); + } else { + codeFragmentProvider.create('''0'''); + } + + codeFragmentProvider.create(''' + Retcode_T retcode = RETCODE_OK; + uint32_t length = 0; + FRESULT sdCardReturn = FR_OK, fileOpenReturn = FR_OK; + FIL fileWriteHandle; + UINT bytesWritten; + fileOpenReturn = f_open(&fileWriteHandle, «filename», FA_WRITE | FA_CREATE_ALWAYS); + if ((FR_OK == sdCardReturn) && (FR_OK == fileOpenReturn)) + { + sdCardReturn = f_lseek(&fileWriteHandle, «fileSeekIndex»); + } + if ((FR_OK == sdCardReturn) && (FR_OK == fileOpenReturn)) + { + sdCardReturn = f_write(&fileWriteHandle, «data», «len», &bytesWritten); /* Write it to the destination file */ + } + if ((FR_OK == sdCardReturn) && (FR_OK == fileOpenReturn)) + { + «IF sigInst.instanceOf.name.startsWith("appendingFile")» + «sigInst.name»FilePosition += bytesWritten; + «ENDIF» + } + if (FR_OK == fileOpenReturn) + { + sdCardReturn = f_close(&fileWriteHandle); + } + if ((FR_OK != sdCardReturn) || (FR_OK != fileOpenReturn)) + { + retcode = RETCODE(RETCODE_SEVERITY_WARNING, RETCODE_STORAGE_ERROR_IN_FILE_WRITE); + } + return retcode; + ''') + } + + def CodeFragment dataAccessor(SignalInstance sigInst, String varName) { + return if (sigInst.instanceOf.name.contains("Text")) { + codeFragmentProvider.create('''*«varName»'''); + } else { + codeFragmentProvider.create('''«varName»->data'''); + } + } + + def CodeFragment lenAccessor(SignalInstance sigInst, String varName) { + return if (sigInst.instanceOf.name.contains("Text")) { + codeFragmentProvider.create('''strlen(*«varName»)'''); + } else { + codeFragmentProvider.create('''«varName»->length'''); + } + } + + def CodeFragment filenameAccessor(SignalInstance sigInst, String varName) { + val filenameRaw = StaticValueInferrer.infer(ModelUtils.getArgumentValue(sigInst, 'filePath'), []); + return if (filenameRaw instanceof String) { + codeFragmentProvider.create('''"«filenameRaw»"'''); + } else { + codeFragmentProvider.create('''INVALID_ARGUMENT'''); + } + } +} diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardSizeInferrer.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardSizeInferrer.xtend new file mode 100644 index 00000000..999825f8 --- /dev/null +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/io/SDCardSizeInferrer.xtend @@ -0,0 +1,25 @@ +/******************************************************************************** + * Copyright (c) 2017, 2018 Bosch Connected Devices and Solutions GmbH. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * Contributors: + * Bosch Connected Devices and Solutions GmbH - initial contribution + * + * SPDX-License-Identifier: EPL-2.0 + ********************************************************************************/ + +package org.eclipse.mita.platform.xdk110.io + +import org.eclipse.mita.program.inferrer.GenericPlatformSizeInferrer +import org.eclipse.mita.program.SignalInstance + +class SDCardSizeInferrer extends GenericPlatformSizeInferrer { + + override getLengthParameterName(SignalInstance sigInst) { + return SDCardGenerator.getSizeName(sigInst); + } + +} \ No newline at end of file diff --git a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/Validation.xtend b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/Validation.xtend index d5904197..fcbdceec 100644 --- a/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/Validation.xtend +++ b/platforms/org.eclipse.mita.platform.xdk110/src/org/eclipse/mita/platform/xdk110/platform/Validation.xtend @@ -115,6 +115,7 @@ class Validation implements IResourceValidator { val i2cs = filterSigInstName.apply("I2C").toSet val gpios = filterSigInstName.apply("GPIO").toSet + val sdcard = filterSigInstName.apply("SDCard").toSet // since modalities are read only this should only be reads. val noises = filterModalityName.apply("noise_sensor").toSet; @@ -138,6 +139,8 @@ class Validation implements IResourceValidator { val i2cWrites = new HashSet(i2cs ) => [retainAll(writes)] val gpioReads = new HashSet(gpios ) => [retainAll(reads)] val gpioWrites = new HashSet(gpios ) => [retainAll(writes)] + val sdCardReads = new HashSet(sdcard) => [retainAll(reads)] + val sdCardWrites = new HashSet(sdcard) => [retainAll(writes)] i2cReads.forEach[validateI2cReadWrite(it.source, it.sigInst, it.structFeature, "Read", "read from", acceptor)] i2cWrites.forEach[validateI2cReadWrite(it.source, it.sigInst, it.structFeature, "Write", "write to", acceptor)] @@ -146,8 +149,11 @@ class Validation implements IResourceValidator { gpioReads.forEach[validateGpioRead(it, acceptor)] gpioWrites.forEach[validateGpioWrite(it, acceptor)] - + noises.forEach[NoiseSensorValidator.validateNoiseRead(noises, it, acceptor)] + + sdCardReads.forEach[validateSdCardRead(it, acceptor)] + sdCardWrites.forEach[validateSdCardWrite(it, acceptor)] } @@ -203,6 +209,20 @@ class Validation implements IResourceValidator { } + def validateSdCardRead(MethodCall call, ValidationMessageAcceptor acceptor) { + val init = call.sigInst.initialization as ElementReferenceExpression; + val signal = init.reference as Signal; + if(signal.name.contains("_Write")) { + acceptor.acceptError("Can not read from " + signal.name, call.source, call.structFeature, 0, "CANT_READ_FROM_" + signal.name.toUpperCase) + } + } + def validateSdCardWrite(MethodCall call, ValidationMessageAcceptor acceptor) { + val init = call.sigInst.initialization as ElementReferenceExpression; + val signal = init.reference as Signal; + if(signal.name.contains("_Read")) { + acceptor.acceptError("Can not write to " + signal.name, call.source, call.structFeature, 0, "CANT_WRITE_TO_" + signal.name.toUpperCase) + } + } } From cfa2d64506ef378f7fc86f9cea69a58b866adf00 Mon Sep 17 00:00:00 2001 From: "Padmapriya Govindasamy (RBEI/EAC4)" Date: Tue, 12 Mar 2019 09:15:39 +0100 Subject: [PATCH 9/9] rebase --- bundles/org.eclipse.mita.base/META-INF/MANIFEST.MF | 5 +++-- bundles/org.eclipse.mita.platform/META-INF/MANIFEST.MF | 5 +++-- bundles/org.eclipse.mita.program/META-INF/MANIFEST.MF | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.mita.base/META-INF/MANIFEST.MF b/bundles/org.eclipse.mita.base/META-INF/MANIFEST.MF index 387a57a4..b76f891c 100644 --- a/bundles/org.eclipse.mita.base/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.mita.base/META-INF/MANIFEST.MF @@ -1,11 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Mita Type Definition Language -Bundle-Vendor: Eclipse.org/Mita +Bundle-Name: %pluginName +Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-Version: 0.1.0.qualifier Bundle-ClassPath: . Bundle-SymbolicName: org.eclipse.mita.base;singleton:=true +Automatic-Module-Name: org.eclipse.mita.base Bundle-ActivationPolicy: lazy Require-Bundle: org.eclipse.xtext;visibility:=reexport, org.eclipse.xtext.xbase, diff --git a/bundles/org.eclipse.mita.platform/META-INF/MANIFEST.MF b/bundles/org.eclipse.mita.platform/META-INF/MANIFEST.MF index 78c4e26d..0e518ce2 100644 --- a/bundles/org.eclipse.mita.platform/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.mita.platform/META-INF/MANIFEST.MF @@ -1,11 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Mita Platform Definition Language -Bundle-Vendor: Eclipse.org/Mita +Bundle-Name: %pluginName +Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-Version: 0.1.0.qualifier Bundle-ClassPath: . Bundle-SymbolicName: org.eclipse.mita.platform;singleton:=true +Automatic-Module-Name: org.eclipse.mita.platform Bundle-ActivationPolicy: lazy Require-Bundle: org.eclipse.xtext, org.eclipse.xtext.xbase, diff --git a/bundles/org.eclipse.mita.program/META-INF/MANIFEST.MF b/bundles/org.eclipse.mita.program/META-INF/MANIFEST.MF index bf0cd60a..3c302166 100644 --- a/bundles/org.eclipse.mita.program/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.mita.program/META-INF/MANIFEST.MF @@ -1,11 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Mita Program Definition Language -Bundle-Vendor: Eclipse.org/Mita +Bundle-Name: %pluginName +Bundle-Vendor: %providerName Bundle-Localization: plugin Bundle-Version: 0.1.0.qualifier Bundle-ClassPath: . Bundle-SymbolicName: org.eclipse.mita.program;singleton:=true +Automatic-Module-Name: org.eclipse.mita.program Bundle-ActivationPolicy: lazy Require-Bundle: org.eclipse.xtext, org.eclipse.xtext.xtext.generator,