MurataTypeYD_RPC_Sample fixed version for 050314

Dependencies:   PowerControl SNICInterface_mod2 mbed-rtos mbed

Fork of HTTPClient_WiFi_HelloWorld by KDDI Fx0 hackathon

Committer:
komoritan
Date:
Thu Mar 12 12:27:31 2015 +0000
Revision:
6:6c49fdc29825
Fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
komoritan 6:6c49fdc29825 1 /* Copyright (C) 2015 KDDI Technology, MIT License
komoritan 6:6c49fdc29825 2 *
komoritan 6:6c49fdc29825 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
komoritan 6:6c49fdc29825 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
komoritan 6:6c49fdc29825 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
komoritan 6:6c49fdc29825 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
komoritan 6:6c49fdc29825 7 * furnished to do so, subject to the following conditions:
komoritan 6:6c49fdc29825 8 *
komoritan 6:6c49fdc29825 9 * The above copyright notice and this permission notice shall be included in all copies or
komoritan 6:6c49fdc29825 10 * substantial portions of the Software.
komoritan 6:6c49fdc29825 11 *
komoritan 6:6c49fdc29825 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
komoritan 6:6c49fdc29825 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
komoritan 6:6c49fdc29825 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
komoritan 6:6c49fdc29825 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
komoritan 6:6c49fdc29825 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
komoritan 6:6c49fdc29825 17 */
komoritan 6:6c49fdc29825 18
komoritan 6:6c49fdc29825 19 #include "mbed.h"
komoritan 6:6c49fdc29825 20 #include "SNIC_WifiInterface.h"
komoritan 6:6c49fdc29825 21 #include "RPC_Function.h"
komoritan 6:6c49fdc29825 22
komoritan 6:6c49fdc29825 23 // LED設定
komoritan 6:6c49fdc29825 24 DigitalOut led1(LED1);
komoritan 6:6c49fdc29825 25 DigitalOut led2(LED2);
komoritan 6:6c49fdc29825 26 DigitalOut led3(LED3);
komoritan 6:6c49fdc29825 27 DigitalOut led4(LED4);
komoritan 6:6c49fdc29825 28
komoritan 6:6c49fdc29825 29 // ジャイロセンサー設定
komoritan 6:6c49fdc29825 30 AnalogIn gyro1_adc(p16);
komoritan 6:6c49fdc29825 31 AnalogIn gyro2_adc(p17);
komoritan 6:6c49fdc29825 32
komoritan 6:6c49fdc29825 33 // Led1~4の点灯・消灯処理
komoritan 6:6c49fdc29825 34 // サンプルとしてLEDの点灯、消灯処理を追加しています
komoritan 6:6c49fdc29825 35 void doSetLed(char* input, char* output) {
komoritan 6:6c49fdc29825 36
komoritan 6:6c49fdc29825 37 char *tok;
komoritan 6:6c49fdc29825 38 char s2[] = ","; // カンマで区切られていることを想定
komoritan 6:6c49fdc29825 39 int cnt = 1;
komoritan 6:6c49fdc29825 40
komoritan 6:6c49fdc29825 41 DEBUG_PRINT("doSetLed IN input = %s, output = %s\r\n", input, output);
komoritan 6:6c49fdc29825 42
komoritan 6:6c49fdc29825 43 tok = strtok( input, "," );
komoritan 6:6c49fdc29825 44
komoritan 6:6c49fdc29825 45 // カンマ区切りの文字列を取得し、1:LED点灯、0(1以外):消灯とする
komoritan 6:6c49fdc29825 46 while( tok != NULL ){
komoritan 6:6c49fdc29825 47 int ret;
komoritan 6:6c49fdc29825 48 int setled = 0;
komoritan 6:6c49fdc29825 49 ret = strcmp( tok, "1" );
komoritan 6:6c49fdc29825 50 if (ret == 0) {
komoritan 6:6c49fdc29825 51 setled = 1;
komoritan 6:6c49fdc29825 52 } else {
komoritan 6:6c49fdc29825 53 setled = 0;
komoritan 6:6c49fdc29825 54 }
komoritan 6:6c49fdc29825 55 switch (cnt) {
komoritan 6:6c49fdc29825 56 case 1:
komoritan 6:6c49fdc29825 57 led1 = setled;
komoritan 6:6c49fdc29825 58 break;
komoritan 6:6c49fdc29825 59 case 2:
komoritan 6:6c49fdc29825 60 led2 = setled;
komoritan 6:6c49fdc29825 61 break;
komoritan 6:6c49fdc29825 62 case 3:
komoritan 6:6c49fdc29825 63 led3 = setled;
komoritan 6:6c49fdc29825 64 break;
komoritan 6:6c49fdc29825 65 case 4:
komoritan 6:6c49fdc29825 66 led4 = setled;
komoritan 6:6c49fdc29825 67 break;
komoritan 6:6c49fdc29825 68 default:
komoritan 6:6c49fdc29825 69 break;
komoritan 6:6c49fdc29825 70 }
komoritan 6:6c49fdc29825 71 cnt++;
komoritan 6:6c49fdc29825 72 tok = strtok( NULL, s2 ); // 2回目以降
komoritan 6:6c49fdc29825 73 }
komoritan 6:6c49fdc29825 74
komoritan 6:6c49fdc29825 75 // outputにJSON形式で処理結果を返す
komoritan 6:6c49fdc29825 76 sprintf(output, "{\"led1\":%d, \"led2\":%d, \"led3\":%d, \"led4\":%d}",(int)led1, (int)led2, (int)led3, (int)led4);
komoritan 6:6c49fdc29825 77 }
komoritan 6:6c49fdc29825 78
komoritan 6:6c49fdc29825 79 // ジャイロセンサーの値の取得、返却処理
komoritan 6:6c49fdc29825 80 // サンプルとしてジャイロセンサーの値の取得、返却処理を追加しています
komoritan 6:6c49fdc29825 81 void doGetGyro(char* input, char* output) {
komoritan 6:6c49fdc29825 82 float gy1_data;
komoritan 6:6c49fdc29825 83 float gy2_data;
komoritan 6:6c49fdc29825 84
komoritan 6:6c49fdc29825 85 // ジャイロ1,2データの読み込み
komoritan 6:6c49fdc29825 86 gy1_data=gyro1_adc.read();
komoritan 6:6c49fdc29825 87 gy2_data=gyro2_adc.read();
komoritan 6:6c49fdc29825 88
komoritan 6:6c49fdc29825 89 // outputにJSON形式で処理結果を返す
komoritan 6:6c49fdc29825 90 sprintf(output, "Gyro1:%2.5f, Gyro2:%2.5f",gy1_data ,gy2_data);
komoritan 6:6c49fdc29825 91 DEBUG_PRINT("doGetGyro output = %s\r\n",output);
komoritan 6:6c49fdc29825 92 }