KDDI Fx0 hackathon
/
MurataTypeYD_Websocket_Sample_full
Websocket_Sample for MurataTypeYD
Websocket_Function.cpp@1:b5ac0f971f43, 2015-03-12 (annotated)
- Committer:
- komoritan
- Date:
- Thu Mar 12 12:15:46 2015 +0000
- Revision:
- 1:b5ac0f971f43
- Parent:
- 0:14bd24b5a77f
Fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
komoritan | 0:14bd24b5a77f | 1 | /* Copyright (C) 2015 KDDI Technology, MIT License |
komoritan | 0:14bd24b5a77f | 2 | * |
komoritan | 0:14bd24b5a77f | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
komoritan | 0:14bd24b5a77f | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
komoritan | 0:14bd24b5a77f | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
komoritan | 0:14bd24b5a77f | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
komoritan | 0:14bd24b5a77f | 7 | * furnished to do so, subject to the following conditions: |
komoritan | 0:14bd24b5a77f | 8 | * |
komoritan | 0:14bd24b5a77f | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
komoritan | 0:14bd24b5a77f | 10 | * substantial portions of the Software. |
komoritan | 0:14bd24b5a77f | 11 | * |
komoritan | 0:14bd24b5a77f | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
komoritan | 0:14bd24b5a77f | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
komoritan | 0:14bd24b5a77f | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
komoritan | 0:14bd24b5a77f | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
komoritan | 0:14bd24b5a77f | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
komoritan | 0:14bd24b5a77f | 17 | */ |
komoritan | 0:14bd24b5a77f | 18 | |
komoritan | 0:14bd24b5a77f | 19 | #include "mbed.h" |
komoritan | 0:14bd24b5a77f | 20 | #include "SNIC_WifiInterface.h" |
komoritan | 0:14bd24b5a77f | 21 | #include "Websocket_Function.h" |
komoritan | 0:14bd24b5a77f | 22 | |
komoritan | 0:14bd24b5a77f | 23 | // LED設定 |
komoritan | 0:14bd24b5a77f | 24 | DigitalOut led1(LED1); |
komoritan | 0:14bd24b5a77f | 25 | DigitalOut led2(LED2); |
komoritan | 0:14bd24b5a77f | 26 | DigitalOut led3(LED3); |
komoritan | 0:14bd24b5a77f | 27 | DigitalOut led4(LED4); |
komoritan | 0:14bd24b5a77f | 28 | |
komoritan | 0:14bd24b5a77f | 29 | // ジャイロ設定 |
komoritan | 0:14bd24b5a77f | 30 | AnalogIn gyro1_adc(p16); |
komoritan | 0:14bd24b5a77f | 31 | AnalogIn gyro2_adc(p17); |
komoritan | 0:14bd24b5a77f | 32 | |
komoritan | 0:14bd24b5a77f | 33 | // Led1~4の点灯・消灯処理 |
komoritan | 0:14bd24b5a77f | 34 | // サンプルとしてLEDの点灯、消灯処理を追加しています |
komoritan | 0:14bd24b5a77f | 35 | void doSetLed(char* output, string inputLed1, string inputLed2, string inputLed3, string inputLed4) { |
komoritan | 0:14bd24b5a77f | 36 | |
komoritan | 0:14bd24b5a77f | 37 | led1 = atoi(inputLed1.c_str()); |
komoritan | 0:14bd24b5a77f | 38 | led2 = atoi(inputLed2.c_str()); |
komoritan | 0:14bd24b5a77f | 39 | led3 = atoi(inputLed3.c_str()); |
komoritan | 0:14bd24b5a77f | 40 | led4 = atoi(inputLed4.c_str()); |
komoritan | 0:14bd24b5a77f | 41 | |
komoritan | 0:14bd24b5a77f | 42 | // outputにJSON形式で処理結果を返す |
komoritan | 0:14bd24b5a77f | 43 | sprintf(output, "{\"method\": \"setLed\", \"led1\": \"%d\", \"led2\": \"%d\", \"led3\": \"%d\", \"led4\": \"%d\"}",(int)led1 ,(int)led2 ,(int)led3 ,(int)led4); |
komoritan | 0:14bd24b5a77f | 44 | } |
komoritan | 0:14bd24b5a77f | 45 | |
komoritan | 0:14bd24b5a77f | 46 | // ジャイロ1,2データの取得、返却 |
komoritan | 0:14bd24b5a77f | 47 | // サンプルとしてジャイロ1,2データの取得、返却処理を追加しています |
komoritan | 0:14bd24b5a77f | 48 | void doGetGyro(char* output) { |
komoritan | 0:14bd24b5a77f | 49 | float gy1_data; |
komoritan | 0:14bd24b5a77f | 50 | float gy2_data; |
komoritan | 0:14bd24b5a77f | 51 | |
komoritan | 0:14bd24b5a77f | 52 | // ジャイロ1,2データの読み込み |
komoritan | 0:14bd24b5a77f | 53 | gy1_data=gyro1_adc.read(); |
komoritan | 0:14bd24b5a77f | 54 | gy2_data=gyro2_adc.read(); |
komoritan | 0:14bd24b5a77f | 55 | |
komoritan | 0:14bd24b5a77f | 56 | // outputにJSON形式で処理結果を返す |
komoritan | 0:14bd24b5a77f | 57 | sprintf(output, "{\"method\": \"getGyro\", \"Gyro1\": \"%2.5f\", \"Gyro2\": \"%2.5f\"}",gy1_data ,gy2_data); |
komoritan | 0:14bd24b5a77f | 58 | } |