Send the data of GR-PEACH_HVC-P2_sample to the cloud.
Dependencies: AsciiFont GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP USBHost_custom easy-connect-gr-peach
Fork of mbed-os-example-client by
Note at the time of sample import
Please not check the "Update all libraries to the latest version" at the time of import.
Warning!
When exporting and using it, increase the following stack size.
mbed-os/features/FEATURE_LWIP/lwip-interface/lwipopts.h
#define TCPIP_THREAD_STACKSIZE 1024 -> #define TCPIP_THREAD_STACKSIZE 2048
Overview
This is a sample to send the analysis result of GR-PEACH_HVC-P2_sample to the cloud using mbed-client. Please refer to following for operation of HVC-P2.
Import programGR-PEACH_HVC-P2_sample
Sample to operate omron HVC-P2 on GR-PEACH.
Required hardware
- GR-PEACH ( https://developer.mbed.org/platforms/Renesas-GR-PEACH/ )
- HVC-P2( https://developer.mbed.org/teams/Renesas/code/GR-PEACH_HVC-P2_sample/ )
- LCD Shield ( https://developer.mbed.org/teams/Renesas/wiki/LCD-shield )
- BP3595 ( https://developer.mbed.org/components/BP3595-for-GR-PEACH/ )
- Ethernet cable and connection to the internet
Application setup
Client credentials
To register the application to mbed Device Connector, you need to create and set the client side certificate.
- Go to https://connector.mbed.com/ and log in with your mbed account
- On mbed Device Connector, go to https://connector.mbed.com/#credentials and click the Get my device security credentials button to get new credentials for your device.
- Replace the contents in security.h of this example with content copied above.
Ethernet settings
This sample uses Ethernet as the default connection type. To change the connection type, set WIFI_BP3595 in mbed_app.json:
mbed_app.json
"network-interface":{ "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_BP3595", "value": "ETHERNET" },
To specify MAC address, add fllowing function to main.cpp. (When using Wifi, setting of MAC address is not necessary.)
Specify MAC address
// set mac address void mbed_mac_address(char *mac) { mac[0] = 0x00; mac[1] = 0x02; mac[2] = 0xF7; mac[3] = 0xF0; mac[4] = 0x00; mac[5] = 0x00; }
Wifi settings
This example can use BP3595 Wifi Interface for managing the wireless connectivity. To run this example using Wifi, you need:
- A BP3595 Wifi module ( https://developer.mbed.org/components/BP3595-for-GR-PEACH/ )
- Mount BP3595 onto GR-PEACH
- Close GR-PEACH's JP21 (https://developer.mbed.org/teams/Renesas/wiki/Jumper-settings-of-GR-PEACH)
- In the mbed_app.json file, change
mbed_app.json
"network-interface":{ "help": "Options are ETHERNET, WIFI_ESP8266, WIFI_BP3595", "value": "WIFI_BP3595" },
Provide your Wifi SSID and password here and leave \" in the beginning and end of your SSID and password as shown in the example below:
mbed_app.json
"wifi-ssid": { "help": "WiFi SSID", "value": "\"SSID\"" }, "wifi-password": { "help": "WIFI Password", "value": "\"Password\"" }
Specify the security type for connection to be used. When the security type is WPA2, you need to specify
NSAPI_SECURITY_WAP as follows:
mbed_app.json
"wifi-security":{ "help": "Options are NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2, NSAPI_SECURITY_WPA_WPA2", "value": "NSAPI_SECURITY_WEP" },
By default, NSAPI_SECURITY_WPA_WPA2 is specified here.
Application resources
This example exposes four resources listed below:
- 3202/0/5700. Recognition result from HVC-P2 (GET).
- 3201/0/5850. Blink function, blinks LED when executed (POST).
- 3201/0/5853. Blink pattern, used by the blink function to determine how to blink. In the format of 1000:500:1000:500:1000:500 (PUT).
- 3201/0/5855. Blink color, used by the blink function. Any of red, green, blue, cyan, yellow and magenta is acceptable (PUT).
For more info on how to get notifications when resource 1 changes, or how to use resource 2, 3 and 4, please look at
Import programGR-PEACH_mbed-connector-ZXingSample-node
Node.js based Web Application for mbed Device Connector specific to GR-PEACH_mbed-os-client-ZXingSample
# This is a Web Application for GR-PEACH_mbed-os-client-ZXingSample, but it can also be used for this sample.
main.cpp@73:fbc0212c2eaf, 2017-03-14 (annotated)
- Committer:
- dkato
- Date:
- Tue Mar 14 05:43:50 2017 +0000
- Revision:
- 73:fbc0212c2eaf
- Parent:
- 71:ec259c9b02ea
- Child:
- 74:bf6d9bd511bd
Send the data of GR-PEACH_HVC-P2_sample to the cloud.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 21:b88cdeb5b302 | 1 | /* |
mbed_official | 44:2b472e66a942 | 2 | * Copyright (c) 2015, 2016 ARM Limited. All rights reserved. |
mbed_official | 21:b88cdeb5b302 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbed_official | 21:b88cdeb5b302 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbed_official | 21:b88cdeb5b302 | 5 | * not use this file except in compliance with the License. |
mbed_official | 21:b88cdeb5b302 | 6 | * You may obtain a copy of the License at |
mbed_official | 21:b88cdeb5b302 | 7 | * |
mbed_official | 21:b88cdeb5b302 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 21:b88cdeb5b302 | 9 | * |
mbed_official | 21:b88cdeb5b302 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 21:b88cdeb5b302 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbed_official | 21:b88cdeb5b302 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 21:b88cdeb5b302 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 21:b88cdeb5b302 | 14 | * limitations under the License. |
mbed_official | 21:b88cdeb5b302 | 15 | */ |
mbed_official | 63:c73f78fd7982 | 16 | #define __STDC_FORMAT_MACROS |
mbed_official | 63:c73f78fd7982 | 17 | #include <inttypes.h> |
mbed_official | 21:b88cdeb5b302 | 18 | #include "simpleclient.h" |
mbed_official | 21:b88cdeb5b302 | 19 | #include <string> |
mbed_official | 21:b88cdeb5b302 | 20 | #include <sstream> |
mbed_official | 21:b88cdeb5b302 | 21 | #include <vector> |
mbed_official | 21:b88cdeb5b302 | 22 | #include "mbed-trace/mbed_trace.h" |
mbed_official | 21:b88cdeb5b302 | 23 | #include "mbedtls/entropy_poll.h" |
mbed_official | 21:b88cdeb5b302 | 24 | |
mbed_official | 21:b88cdeb5b302 | 25 | #include "security.h" |
mbed_official | 21:b88cdeb5b302 | 26 | |
mbed_official | 21:b88cdeb5b302 | 27 | #include "mbed.h" |
dkato | 73:fbc0212c2eaf | 28 | #include "DisplayBace.h" |
dkato | 73:fbc0212c2eaf | 29 | #include "rtos.h" |
dkato | 73:fbc0212c2eaf | 30 | #include "LCD_shield_config_4_3inch.h" |
dkato | 73:fbc0212c2eaf | 31 | #include "recognition_proc.h" |
dkato | 73:fbc0212c2eaf | 32 | #include "touch_proc.h" |
mbed_official | 21:b88cdeb5b302 | 33 | |
mbed_official | 63:c73f78fd7982 | 34 | // easy-connect compliancy, it has 2 sets of wifi pins we have only one |
mbed_official | 63:c73f78fd7982 | 35 | #define MBED_CONF_APP_ESP8266_TX MBED_CONF_APP_WIFI_TX |
mbed_official | 63:c73f78fd7982 | 36 | #define MBED_CONF_APP_ESP8266_RX MBED_CONF_APP_WIFI_RX |
dkato | 73:fbc0212c2eaf | 37 | #include "easy-connect.h" |
mbed_official | 21:b88cdeb5b302 | 38 | |
mbed_official | 21:b88cdeb5b302 | 39 | |
mbed_official | 21:b88cdeb5b302 | 40 | // These are example resource values for the Device Object |
mbed_official | 21:b88cdeb5b302 | 41 | struct MbedClientDevice device = { |
mbed_official | 21:b88cdeb5b302 | 42 | "Manufacturer_String", // Manufacturer |
mbed_official | 21:b88cdeb5b302 | 43 | "Type_String", // Type |
mbed_official | 21:b88cdeb5b302 | 44 | "ModelNumber_String", // ModelNumber |
mbed_official | 21:b88cdeb5b302 | 45 | "SerialNumber_String" // SerialNumber |
mbed_official | 21:b88cdeb5b302 | 46 | }; |
mbed_official | 21:b88cdeb5b302 | 47 | |
mbed_official | 21:b88cdeb5b302 | 48 | // Instantiate the class which implements LWM2M Client API (from simpleclient.h) |
mbed_official | 21:b88cdeb5b302 | 49 | MbedClient mbed_client(device); |
mbed_official | 21:b88cdeb5b302 | 50 | |
dkato | 73:fbc0212c2eaf | 51 | static DisplayBase Display; |
dkato | 73:fbc0212c2eaf | 52 | static DigitalOut lcd_pwon(P7_15); |
dkato | 73:fbc0212c2eaf | 53 | static DigitalOut lcd_blon(P8_1); |
dkato | 73:fbc0212c2eaf | 54 | static PwmOut lcd_cntrst(P8_15); |
dkato | 73:fbc0212c2eaf | 55 | static Thread recognitionTask; |
dkato | 73:fbc0212c2eaf | 56 | static Thread touchTask; |
dkato | 73:fbc0212c2eaf | 57 | static char send_cloud_buf_last[1024 * 4]; |
mbed_official | 21:b88cdeb5b302 | 58 | |
dkato | 73:fbc0212c2eaf | 59 | // LED Output |
dkato | 73:fbc0212c2eaf | 60 | DigitalOut led1(LED1); |
dkato | 73:fbc0212c2eaf | 61 | DigitalOut led2(LED2); |
dkato | 73:fbc0212c2eaf | 62 | DigitalOut led3(LED3); |
mbed_official | 21:b88cdeb5b302 | 63 | |
mbed_official | 21:b88cdeb5b302 | 64 | /* |
mbed_official | 21:b88cdeb5b302 | 65 | * The Led contains one property (pattern) and a function (blink). |
mbed_official | 21:b88cdeb5b302 | 66 | * When the function blink is executed, the pattern is read, and the LED |
mbed_official | 21:b88cdeb5b302 | 67 | * will blink based on the pattern. |
mbed_official | 21:b88cdeb5b302 | 68 | */ |
mbed_official | 21:b88cdeb5b302 | 69 | class LedResource { |
mbed_official | 21:b88cdeb5b302 | 70 | public: |
mbed_official | 21:b88cdeb5b302 | 71 | LedResource() { |
mbed_official | 21:b88cdeb5b302 | 72 | // create ObjectID with metadata tag of '3201', which is 'digital output' |
mbed_official | 21:b88cdeb5b302 | 73 | led_object = M2MInterfaceFactory::create_object("3201"); |
mbed_official | 21:b88cdeb5b302 | 74 | M2MObjectInstance* led_inst = led_object->create_object_instance(); |
mbed_official | 21:b88cdeb5b302 | 75 | |
dkato | 73:fbc0212c2eaf | 76 | // 5855 = Multi-state output |
dkato | 73:fbc0212c2eaf | 77 | M2MResource* color_res = led_inst->create_dynamic_resource("5855", "Color", |
dkato | 73:fbc0212c2eaf | 78 | M2MResourceInstance::STRING, false); |
dkato | 73:fbc0212c2eaf | 79 | // read and write |
dkato | 73:fbc0212c2eaf | 80 | color_res->set_operation(M2MBase::GET_PUT_ALLOWED); |
dkato | 73:fbc0212c2eaf | 81 | // set red as initial color |
dkato | 73:fbc0212c2eaf | 82 | color_res->set_value((const uint8_t*)"red", 3); |
dkato | 73:fbc0212c2eaf | 83 | |
mbed_official | 21:b88cdeb5b302 | 84 | // 5853 = Multi-state output |
mbed_official | 21:b88cdeb5b302 | 85 | M2MResource* pattern_res = led_inst->create_dynamic_resource("5853", "Pattern", |
mbed_official | 21:b88cdeb5b302 | 86 | M2MResourceInstance::STRING, false); |
mbed_official | 21:b88cdeb5b302 | 87 | // read and write |
mbed_official | 21:b88cdeb5b302 | 88 | pattern_res->set_operation(M2MBase::GET_PUT_ALLOWED); |
mbed_official | 21:b88cdeb5b302 | 89 | // set initial pattern (toggle every 200ms. 7 toggles in total) |
mbed_official | 21:b88cdeb5b302 | 90 | pattern_res->set_value((const uint8_t*)"500:500:500:500:500:500:500", 27); |
mbed_official | 21:b88cdeb5b302 | 91 | |
mbed_official | 21:b88cdeb5b302 | 92 | // there's not really an execute LWM2M ID that matches... hmm... |
mbed_official | 21:b88cdeb5b302 | 93 | M2MResource* led_res = led_inst->create_dynamic_resource("5850", "Blink", |
mbed_official | 21:b88cdeb5b302 | 94 | M2MResourceInstance::OPAQUE, false); |
mbed_official | 21:b88cdeb5b302 | 95 | // we allow executing a function here... |
mbed_official | 21:b88cdeb5b302 | 96 | led_res->set_operation(M2MBase::POST_ALLOWED); |
mbed_official | 21:b88cdeb5b302 | 97 | // when a POST comes in, we want to execute the led_execute_callback |
mbed_official | 21:b88cdeb5b302 | 98 | led_res->set_execute_function(execute_callback(this, &LedResource::blink)); |
mbed_official | 21:b88cdeb5b302 | 99 | } |
mbed_official | 21:b88cdeb5b302 | 100 | |
mbed_official | 21:b88cdeb5b302 | 101 | M2MObject* get_object() { |
mbed_official | 21:b88cdeb5b302 | 102 | return led_object; |
mbed_official | 21:b88cdeb5b302 | 103 | } |
mbed_official | 21:b88cdeb5b302 | 104 | |
dkato | 73:fbc0212c2eaf | 105 | void blink(void *) { |
mbed_official | 21:b88cdeb5b302 | 106 | // read the value of 'Pattern' |
mbed_official | 21:b88cdeb5b302 | 107 | M2MObjectInstance* inst = led_object->object_instance(); |
mbed_official | 21:b88cdeb5b302 | 108 | M2MResource* res = inst->resource("5853"); |
dkato | 73:fbc0212c2eaf | 109 | // read the value of 'Color' |
dkato | 73:fbc0212c2eaf | 110 | M2MObjectInstance* instC = led_object->object_instance(); |
dkato | 73:fbc0212c2eaf | 111 | M2MResource* resC = instC->resource("5855"); |
mbed_official | 21:b88cdeb5b302 | 112 | |
mbed_official | 21:b88cdeb5b302 | 113 | // values in mbed Client are all buffers, and we need a vector of int's |
mbed_official | 21:b88cdeb5b302 | 114 | uint8_t* buffIn = NULL; |
mbed_official | 21:b88cdeb5b302 | 115 | uint32_t sizeIn; |
mbed_official | 21:b88cdeb5b302 | 116 | res->get_value(buffIn, sizeIn); |
dkato | 73:fbc0212c2eaf | 117 | |
dkato | 73:fbc0212c2eaf | 118 | uint8_t* cbuffIn = NULL; |
dkato | 73:fbc0212c2eaf | 119 | uint32_t csizeIn; |
dkato | 73:fbc0212c2eaf | 120 | resC->get_value(cbuffIn, csizeIn); |
mbed_official | 21:b88cdeb5b302 | 121 | |
mbed_official | 21:b88cdeb5b302 | 122 | // turn the buffer into a string, and initialize a vector<int> on the heap |
mbed_official | 21:b88cdeb5b302 | 123 | std::string s((char*)buffIn, sizeIn); |
dkato | 73:fbc0212c2eaf | 124 | std::vector<uint32_t>* v = new std::vector<uint32_t>; |
dkato | 73:fbc0212c2eaf | 125 | |
dkato | 73:fbc0212c2eaf | 126 | printf("led_execute_callback pattern=%s\r\n", s.c_str()); |
mbed_official | 21:b88cdeb5b302 | 127 | |
mbed_official | 21:b88cdeb5b302 | 128 | // our pattern is something like 500:200:500, so parse that |
mbed_official | 21:b88cdeb5b302 | 129 | std::size_t found = s.find_first_of(":"); |
mbed_official | 21:b88cdeb5b302 | 130 | while (found!=std::string::npos) { |
dkato | 73:fbc0212c2eaf | 131 | |
dkato | 73:fbc0212c2eaf | 132 | v->push_back(atoi((const char*)s.substr(0,found).c_str())); |
mbed_official | 21:b88cdeb5b302 | 133 | s = s.substr(found+1); |
mbed_official | 21:b88cdeb5b302 | 134 | found=s.find_first_of(":"); |
mbed_official | 21:b88cdeb5b302 | 135 | if(found == std::string::npos) { |
dkato | 73:fbc0212c2eaf | 136 | v->push_back(atoi((const char*)s.c_str())); |
mbed_official | 21:b88cdeb5b302 | 137 | } |
mbed_official | 21:b88cdeb5b302 | 138 | } |
dkato | 73:fbc0212c2eaf | 139 | |
dkato | 73:fbc0212c2eaf | 140 | int position = 0; |
dkato | 73:fbc0212c2eaf | 141 | while (1) { |
dkato | 73:fbc0212c2eaf | 142 | do_blink(cbuffIn); |
dkato | 73:fbc0212c2eaf | 143 | if (position >= v->size()) { |
dkato | 73:fbc0212c2eaf | 144 | break; |
dkato | 73:fbc0212c2eaf | 145 | } |
dkato | 73:fbc0212c2eaf | 146 | // how long do we need to wait before the next blink? |
dkato | 73:fbc0212c2eaf | 147 | Thread::wait(v->at(position)); |
dkato | 73:fbc0212c2eaf | 148 | position++; |
mbed_official | 21:b88cdeb5b302 | 149 | } |
dkato | 73:fbc0212c2eaf | 150 | free(buffIn); |
dkato | 73:fbc0212c2eaf | 151 | free(cbuffIn); |
dkato | 73:fbc0212c2eaf | 152 | delete v; |
mbed_official | 21:b88cdeb5b302 | 153 | } |
mbed_official | 21:b88cdeb5b302 | 154 | |
mbed_official | 21:b88cdeb5b302 | 155 | private: |
mbed_official | 21:b88cdeb5b302 | 156 | M2MObject* led_object; |
dkato | 73:fbc0212c2eaf | 157 | |
dkato | 73:fbc0212c2eaf | 158 | void do_blink(uint8_t* color) { |
dkato | 73:fbc0212c2eaf | 159 | if (!strcmp((char *)color, "red")) { |
dkato | 73:fbc0212c2eaf | 160 | // blink the LED in red color |
dkato | 73:fbc0212c2eaf | 161 | led1 = !led1; |
dkato | 73:fbc0212c2eaf | 162 | } |
dkato | 73:fbc0212c2eaf | 163 | else if (!strcmp((char *)color, "green")) { |
dkato | 73:fbc0212c2eaf | 164 | // blink in green color |
dkato | 73:fbc0212c2eaf | 165 | led2 = !led2; |
dkato | 73:fbc0212c2eaf | 166 | } |
dkato | 73:fbc0212c2eaf | 167 | else if (!strcmp((char *)color, "blue")) { |
dkato | 73:fbc0212c2eaf | 168 | // blink in blue color |
dkato | 73:fbc0212c2eaf | 169 | led3 = !led3; |
dkato | 73:fbc0212c2eaf | 170 | } |
dkato | 73:fbc0212c2eaf | 171 | else if (!strcmp((char *)color, "cyan")) { |
dkato | 73:fbc0212c2eaf | 172 | // blink in cyan color |
dkato | 73:fbc0212c2eaf | 173 | led2 = !led2; |
dkato | 73:fbc0212c2eaf | 174 | led3 = !led3; |
dkato | 73:fbc0212c2eaf | 175 | } |
dkato | 73:fbc0212c2eaf | 176 | else if (!strcmp((char *)color, "yellow")) { |
dkato | 73:fbc0212c2eaf | 177 | // blink in yellow color |
dkato | 73:fbc0212c2eaf | 178 | led1 = !led1; |
dkato | 73:fbc0212c2eaf | 179 | led2 = !led2; |
dkato | 73:fbc0212c2eaf | 180 | } |
dkato | 73:fbc0212c2eaf | 181 | else if (!strcmp((char *)color, "magenta")) { |
dkato | 73:fbc0212c2eaf | 182 | // blink in magenta color |
dkato | 73:fbc0212c2eaf | 183 | led1 = !led1; |
dkato | 73:fbc0212c2eaf | 184 | led3 = !led3; |
dkato | 73:fbc0212c2eaf | 185 | } |
dkato | 73:fbc0212c2eaf | 186 | else if (!strcmp((char *)color, "white")) { |
dkato | 73:fbc0212c2eaf | 187 | // blink in white color |
dkato | 73:fbc0212c2eaf | 188 | led1 = !led1; |
dkato | 73:fbc0212c2eaf | 189 | led2 = !led2; |
dkato | 73:fbc0212c2eaf | 190 | led3 = !led3; |
dkato | 73:fbc0212c2eaf | 191 | } |
dkato | 73:fbc0212c2eaf | 192 | else { |
dkato | 73:fbc0212c2eaf | 193 | // no operation |
mbed_official | 21:b88cdeb5b302 | 194 | } |
mbed_official | 21:b88cdeb5b302 | 195 | } |
mbed_official | 21:b88cdeb5b302 | 196 | }; |
mbed_official | 21:b88cdeb5b302 | 197 | |
mbed_official | 21:b88cdeb5b302 | 198 | /* |
dkato | 73:fbc0212c2eaf | 199 | * The HVC contains a function (send string). |
dkato | 73:fbc0212c2eaf | 200 | * When `handle_string_send` is executed, the string after decoding is sent. |
mbed_official | 21:b88cdeb5b302 | 201 | */ |
dkato | 73:fbc0212c2eaf | 202 | class HVCResource { |
mbed_official | 21:b88cdeb5b302 | 203 | public: |
dkato | 73:fbc0212c2eaf | 204 | HVCResource() { |
dkato | 73:fbc0212c2eaf | 205 | // create ObjectID with metadata tag of '3202', which is 'send string' |
dkato | 73:fbc0212c2eaf | 206 | hvc_object = M2MInterfaceFactory::create_object("3202"); |
dkato | 73:fbc0212c2eaf | 207 | M2MObjectInstance* hvc_inst = hvc_object->create_object_instance(); |
dkato | 73:fbc0212c2eaf | 208 | // create resource with ID '5700', which is 'send string' |
dkato | 73:fbc0212c2eaf | 209 | M2MResource* hvc_res = hvc_inst->create_dynamic_resource("5700", "hvc", |
dkato | 73:fbc0212c2eaf | 210 | M2MResourceInstance::STRING, true); |
mbed_official | 21:b88cdeb5b302 | 211 | // we can read this value |
dkato | 73:fbc0212c2eaf | 212 | hvc_res->set_operation(M2MBase::GET_ALLOWED); |
mbed_official | 21:b88cdeb5b302 | 213 | // set initial value (all values in mbed Client are buffers) |
mbed_official | 21:b88cdeb5b302 | 214 | // to be able to read this data easily in the Connector console, we'll use a string |
dkato | 73:fbc0212c2eaf | 215 | hvc_res->set_value((uint8_t*)"0", 1); |
mbed_official | 21:b88cdeb5b302 | 216 | } |
mbed_official | 21:b88cdeb5b302 | 217 | |
dkato | 73:fbc0212c2eaf | 218 | ~HVCResource() { |
mbed_official | 21:b88cdeb5b302 | 219 | } |
mbed_official | 21:b88cdeb5b302 | 220 | |
mbed_official | 21:b88cdeb5b302 | 221 | M2MObject* get_object() { |
dkato | 73:fbc0212c2eaf | 222 | return hvc_object; |
mbed_official | 21:b88cdeb5b302 | 223 | } |
mbed_official | 21:b88cdeb5b302 | 224 | |
mbed_official | 21:b88cdeb5b302 | 225 | /* |
dkato | 73:fbc0212c2eaf | 226 | * When you success the decode process of barcode, we send the string after decoding to mbed Device Connector. |
mbed_official | 21:b88cdeb5b302 | 227 | */ |
dkato | 73:fbc0212c2eaf | 228 | void handle_string_send(char * addr, int size) { |
dkato | 73:fbc0212c2eaf | 229 | M2MObjectInstance* inst = hvc_object->object_instance(); |
dkato | 73:fbc0212c2eaf | 230 | M2MResource* res = inst->resource("5700"); |
mbed_official | 21:b88cdeb5b302 | 231 | |
dkato | 73:fbc0212c2eaf | 232 | printf("%s\r\n", addr); |
dkato | 73:fbc0212c2eaf | 233 | |
dkato | 73:fbc0212c2eaf | 234 | // tell the string to connector |
dkato | 73:fbc0212c2eaf | 235 | res->set_value((uint8_t *)addr, size); |
mbed_official | 21:b88cdeb5b302 | 236 | } |
mbed_official | 21:b88cdeb5b302 | 237 | |
mbed_official | 21:b88cdeb5b302 | 238 | private: |
dkato | 73:fbc0212c2eaf | 239 | M2MObject* hvc_object; |
mbed_official | 21:b88cdeb5b302 | 240 | }; |
mbed_official | 21:b88cdeb5b302 | 241 | |
mbed_official | 21:b88cdeb5b302 | 242 | // Network interaction must be performed outside of interrupt context |
mbed_official | 21:b88cdeb5b302 | 243 | Semaphore updates(0); |
mbed_official | 21:b88cdeb5b302 | 244 | osThreadId mainThread; |
mbed_official | 21:b88cdeb5b302 | 245 | |
dkato | 73:fbc0212c2eaf | 246 | HVCResource hvc_resource; |
dkato | 73:fbc0212c2eaf | 247 | volatile bool sent = false; |
dkato | 73:fbc0212c2eaf | 248 | Timer send_timer; |
dkato | 73:fbc0212c2eaf | 249 | |
dkato | 73:fbc0212c2eaf | 250 | void HVCSendData(char * addr, int size) { |
dkato | 73:fbc0212c2eaf | 251 | if (send_timer.read_ms() > 500) { |
dkato | 73:fbc0212c2eaf | 252 | if (memcmp(send_cloud_buf_last, addr, sizeof(send_cloud_buf_last)) != 0) { |
dkato | 73:fbc0212c2eaf | 253 | memcpy(send_cloud_buf_last, addr, sizeof(send_cloud_buf_last)); |
dkato | 73:fbc0212c2eaf | 254 | send_timer.reset(); |
dkato | 73:fbc0212c2eaf | 255 | hvc_resource.handle_string_send(addr, size); |
dkato | 73:fbc0212c2eaf | 256 | sent = true; |
dkato | 73:fbc0212c2eaf | 257 | updates.release(); |
dkato | 73:fbc0212c2eaf | 258 | } |
dkato | 73:fbc0212c2eaf | 259 | } |
dkato | 73:fbc0212c2eaf | 260 | } |
dkato | 73:fbc0212c2eaf | 261 | |
dkato | 73:fbc0212c2eaf | 262 | // LCD |
dkato | 73:fbc0212c2eaf | 263 | static void IntCallbackFunc_LoVsync(DisplayBase::int_type_t int_type) { |
dkato | 73:fbc0212c2eaf | 264 | /* Interrupt callback function for Vsync interruption */ |
dkato | 73:fbc0212c2eaf | 265 | touch_lcd_int(int_type); |
mbed_official | 21:b88cdeb5b302 | 266 | } |
mbed_official | 21:b88cdeb5b302 | 267 | |
dkato | 73:fbc0212c2eaf | 268 | static void Init_LCD_Display(void) { |
dkato | 73:fbc0212c2eaf | 269 | DisplayBase::graphics_error_t error; |
dkato | 73:fbc0212c2eaf | 270 | DisplayBase::lcd_config_t lcd_config; |
dkato | 73:fbc0212c2eaf | 271 | PinName lvds_pin[8] = { |
dkato | 73:fbc0212c2eaf | 272 | /* data pin */ |
dkato | 73:fbc0212c2eaf | 273 | P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0 |
dkato | 73:fbc0212c2eaf | 274 | }; |
dkato | 73:fbc0212c2eaf | 275 | |
dkato | 73:fbc0212c2eaf | 276 | lcd_pwon = 0; |
dkato | 73:fbc0212c2eaf | 277 | lcd_blon = 0; |
dkato | 73:fbc0212c2eaf | 278 | Thread::wait(100); |
dkato | 73:fbc0212c2eaf | 279 | lcd_pwon = 1; |
dkato | 73:fbc0212c2eaf | 280 | lcd_blon = 1; |
dkato | 73:fbc0212c2eaf | 281 | |
dkato | 73:fbc0212c2eaf | 282 | Display.Graphics_Lvds_Port_Init(lvds_pin, 8); |
dkato | 73:fbc0212c2eaf | 283 | |
dkato | 73:fbc0212c2eaf | 284 | /* Graphics initialization process */ |
dkato | 73:fbc0212c2eaf | 285 | lcd_config = LcdCfgTbl_LCD_shield; |
dkato | 73:fbc0212c2eaf | 286 | error = Display.Graphics_init(&lcd_config); |
dkato | 73:fbc0212c2eaf | 287 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 73:fbc0212c2eaf | 288 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 73:fbc0212c2eaf | 289 | mbed_die(); |
dkato | 73:fbc0212c2eaf | 290 | } |
dkato | 73:fbc0212c2eaf | 291 | |
dkato | 73:fbc0212c2eaf | 292 | /* Interrupt callback function setting (Vsync signal output from scaler 0) */ |
dkato | 73:fbc0212c2eaf | 293 | error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_LoVsync); |
dkato | 73:fbc0212c2eaf | 294 | if (error != DisplayBase::GRAPHICS_OK) { |
dkato | 73:fbc0212c2eaf | 295 | printf("Line %d, error %d\n", __LINE__, error); |
dkato | 73:fbc0212c2eaf | 296 | mbed_die(); |
dkato | 73:fbc0212c2eaf | 297 | } |
mbed_official | 21:b88cdeb5b302 | 298 | } |
mbed_official | 21:b88cdeb5b302 | 299 | |
mbed_official | 21:b88cdeb5b302 | 300 | // Entry point to the program |
mbed_official | 21:b88cdeb5b302 | 301 | int main() { |
mbed_official | 21:b88cdeb5b302 | 302 | |
mbed_official | 21:b88cdeb5b302 | 303 | unsigned int seed; |
mbed_official | 21:b88cdeb5b302 | 304 | size_t len; |
mbed_official | 21:b88cdeb5b302 | 305 | |
dkato | 73:fbc0212c2eaf | 306 | /* Initialization of LCD */ |
dkato | 73:fbc0212c2eaf | 307 | Init_LCD_Display(); |
dkato | 73:fbc0212c2eaf | 308 | |
dkato | 73:fbc0212c2eaf | 309 | /* Start recognition processing */ |
dkato | 73:fbc0212c2eaf | 310 | recognitionTask.start(callback(recognition_task, &Display)); |
dkato | 73:fbc0212c2eaf | 311 | |
dkato | 73:fbc0212c2eaf | 312 | /* Start touch panel processing */ |
dkato | 73:fbc0212c2eaf | 313 | touchTask.start(callback(touch_task, &Display)); |
dkato | 73:fbc0212c2eaf | 314 | |
dkato | 73:fbc0212c2eaf | 315 | /* Backlight on */ |
dkato | 73:fbc0212c2eaf | 316 | Thread::wait(200); |
dkato | 73:fbc0212c2eaf | 317 | lcd_cntrst.write(1.0); |
dkato | 73:fbc0212c2eaf | 318 | |
mbed_official | 21:b88cdeb5b302 | 319 | #ifdef MBEDTLS_ENTROPY_HARDWARE_ALT |
mbed_official | 21:b88cdeb5b302 | 320 | // Used to randomize source port |
mbed_official | 21:b88cdeb5b302 | 321 | mbedtls_hardware_poll(NULL, (unsigned char *) &seed, sizeof seed, &len); |
mbed_official | 21:b88cdeb5b302 | 322 | |
mbed_official | 21:b88cdeb5b302 | 323 | #elif defined MBEDTLS_TEST_NULL_ENTROPY |
mbed_official | 21:b88cdeb5b302 | 324 | |
mbed_official | 21:b88cdeb5b302 | 325 | #warning "mbedTLS security feature is disabled. Connection will not be secure !! Implement proper hardware entropy for your selected hardware." |
mbed_official | 21:b88cdeb5b302 | 326 | // Used to randomize source port |
mbed_official | 21:b88cdeb5b302 | 327 | mbedtls_null_entropy_poll( NULL,(unsigned char *) &seed, sizeof seed, &len); |
mbed_official | 21:b88cdeb5b302 | 328 | |
mbed_official | 21:b88cdeb5b302 | 329 | #else |
mbed_official | 21:b88cdeb5b302 | 330 | |
mbed_official | 21:b88cdeb5b302 | 331 | #error "This hardware does not have entropy, endpoint will not register to Connector.\ |
mbed_official | 21:b88cdeb5b302 | 332 | You need to enable NULL ENTROPY for your application, but if this configuration change is made then no security is offered by mbed TLS.\ |
mbed_official | 21:b88cdeb5b302 | 333 | Add MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_TEST_NULL_ENTROPY in mbed_app.json macros to register your endpoint." |
mbed_official | 21:b88cdeb5b302 | 334 | |
mbed_official | 21:b88cdeb5b302 | 335 | #endif |
mbed_official | 21:b88cdeb5b302 | 336 | |
mbed_official | 21:b88cdeb5b302 | 337 | srand(seed); |
mbed_official | 21:b88cdeb5b302 | 338 | // Keep track of the main thread |
mbed_official | 21:b88cdeb5b302 | 339 | mainThread = osThreadGetId(); |
mbed_official | 63:c73f78fd7982 | 340 | printf("\nStarting mbed Client example in "); |
mbed_official | 44:2b472e66a942 | 341 | #if defined (MESH) || (MBED_CONF_LWIP_IPV6_ENABLED==true) |
mbed_official | 63:c73f78fd7982 | 342 | printf("IPv6 mode\n"); |
mbed_official | 44:2b472e66a942 | 343 | #else |
mbed_official | 63:c73f78fd7982 | 344 | printf("IPv4 mode\n"); |
mbed_official | 44:2b472e66a942 | 345 | #endif |
mbed_official | 21:b88cdeb5b302 | 346 | |
mbed_official | 21:b88cdeb5b302 | 347 | mbed_trace_init(); |
mbed_official | 44:2b472e66a942 | 348 | |
mbed_official | 63:c73f78fd7982 | 349 | NetworkInterface* network = easy_connect(true); |
mbed_official | 63:c73f78fd7982 | 350 | if(network == NULL) { |
mbed_official | 63:c73f78fd7982 | 351 | printf("\nConnection to Network Failed - exiting application...\n"); |
mbed_official | 63:c73f78fd7982 | 352 | return -1; |
mbed_official | 21:b88cdeb5b302 | 353 | } |
mbed_official | 21:b88cdeb5b302 | 354 | |
mbed_official | 21:b88cdeb5b302 | 355 | // we create our button and LED resources |
mbed_official | 21:b88cdeb5b302 | 356 | LedResource led_resource; |
mbed_official | 21:b88cdeb5b302 | 357 | |
mbed_official | 21:b88cdeb5b302 | 358 | |
mbed_official | 21:b88cdeb5b302 | 359 | // Create endpoint interface to manage register and unregister |
mbed_official | 63:c73f78fd7982 | 360 | mbed_client.create_interface(MBED_SERVER_ADDRESS, network); |
mbed_official | 21:b88cdeb5b302 | 361 | |
mbed_official | 21:b88cdeb5b302 | 362 | // Create Objects of varying types, see simpleclient.h for more details on implementation. |
mbed_official | 21:b88cdeb5b302 | 363 | M2MSecurity* register_object = mbed_client.create_register_object(); // server object specifying connector info |
mbed_official | 21:b88cdeb5b302 | 364 | M2MDevice* device_object = mbed_client.create_device_object(); // device resources object |
mbed_official | 21:b88cdeb5b302 | 365 | |
mbed_official | 21:b88cdeb5b302 | 366 | // Create list of Objects to register |
mbed_official | 21:b88cdeb5b302 | 367 | M2MObjectList object_list; |
mbed_official | 21:b88cdeb5b302 | 368 | |
mbed_official | 21:b88cdeb5b302 | 369 | // Add objects to list |
mbed_official | 21:b88cdeb5b302 | 370 | object_list.push_back(device_object); |
mbed_official | 21:b88cdeb5b302 | 371 | object_list.push_back(led_resource.get_object()); |
dkato | 73:fbc0212c2eaf | 372 | object_list.push_back(hvc_resource.get_object()); |
mbed_official | 21:b88cdeb5b302 | 373 | |
mbed_official | 21:b88cdeb5b302 | 374 | // Set endpoint registration object |
mbed_official | 21:b88cdeb5b302 | 375 | mbed_client.set_register_object(register_object); |
mbed_official | 21:b88cdeb5b302 | 376 | |
mbed_official | 21:b88cdeb5b302 | 377 | // Register with mbed Device Connector |
mbed_official | 21:b88cdeb5b302 | 378 | mbed_client.test_register(register_object, object_list); |
dkato | 73:fbc0212c2eaf | 379 | send_timer.start(); |
dkato | 73:fbc0212c2eaf | 380 | while (1) { |
mbed_official | 21:b88cdeb5b302 | 381 | updates.wait(25000); |
dkato | 73:fbc0212c2eaf | 382 | if(!sent) { |
dkato | 73:fbc0212c2eaf | 383 | mbed_client.test_update_register(); |
mbed_official | 21:b88cdeb5b302 | 384 | } |
dkato | 73:fbc0212c2eaf | 385 | sent = false; |
mbed_official | 21:b88cdeb5b302 | 386 | } |
mbed_official | 21:b88cdeb5b302 | 387 | |
mbed_official | 21:b88cdeb5b302 | 388 | mbed_client.test_unregister(); |
mbed_official | 21:b88cdeb5b302 | 389 | } |