スマートコンセント(富士通 FX-5204PS)をIEEE1888 StorageにWRITEするサンプルプログラムです。

Dependencies:   EthernetInterface FiapV2 HTTPClientForSOAP NTPClient TextLCD mbed-rtos mbed spxml

Fork of BlueUSB_f by Yasushi TAUCHI

スマートコンセント(富士通 FX-5204PS)をIEEE1888 StorageにWRITEするサンプルプログラムです。
USB HUBを使用して2台利用した例です。
表示のみは http://mbed.org/users/yueee_yt/code/BlueUSB_f/で公開しています。

BlueUSBより派生していますが、BluetoothとMass Storage Classは利用できません。

2台まで確認していますが、プログラム的には10台まで接続できるようにしています。
(RTOSとの整合により難しいかもしれません)

Committer:
yueee_yt
Date:
Sun Sep 30 07:41:28 2012 +0000
Revision:
5:96a70a8cebb9
Parent:
3:528f73ce625e
Child:
6:08a406cd2726
?????1????????????OK?
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
peterbarrett1967 0:606b230e5b4a 1 /*
peterbarrett1967 0:606b230e5b4a 2 Copyright (c) 2010 Peter Barrett
peterbarrett1967 0:606b230e5b4a 3
peterbarrett1967 0:606b230e5b4a 4 Permission is hereby granted, free of charge, to any person obtaining a copy
peterbarrett1967 0:606b230e5b4a 5 of this software and associated documentation files (the "Software"), to deal
peterbarrett1967 0:606b230e5b4a 6 in the Software without restriction, including without limitation the rights
peterbarrett1967 0:606b230e5b4a 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
peterbarrett1967 0:606b230e5b4a 8 copies of the Software, and to permit persons to whom the Software is
peterbarrett1967 0:606b230e5b4a 9 furnished to do so, subject to the following conditions:
peterbarrett1967 0:606b230e5b4a 10
peterbarrett1967 0:606b230e5b4a 11 The above copyright notice and this permission notice shall be included in
peterbarrett1967 0:606b230e5b4a 12 all copies or substantial portions of the Software.
peterbarrett1967 0:606b230e5b4a 13
peterbarrett1967 0:606b230e5b4a 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
peterbarrett1967 0:606b230e5b4a 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
peterbarrett1967 0:606b230e5b4a 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
peterbarrett1967 0:606b230e5b4a 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
peterbarrett1967 0:606b230e5b4a 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
peterbarrett1967 0:606b230e5b4a 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
peterbarrett1967 0:606b230e5b4a 20 THE SOFTWARE.
peterbarrett1967 0:606b230e5b4a 21 */
peterbarrett1967 0:606b230e5b4a 22
peterbarrett1967 0:606b230e5b4a 23 #include "USBHost.h"
peterbarrett1967 0:606b230e5b4a 24 #include "Utils.h"
yueee_yt 2:32a2d06f4fe2 25 #include "TextLCD.h"
yueee_yt 3:528f73ce625e 26 #include "EthernetInterface.h"
yueee_yt 3:528f73ce625e 27 #include "NTPClient.h"
yueee_yt 3:528f73ce625e 28 #include "fiap.h"
yueee_yt 3:528f73ce625e 29 #include "mbed.h"
yueee_yt 3:528f73ce625e 30
yueee_yt 3:528f73ce625e 31 //#define NTPServer "ntp.nict.jp"
yueee_yt 3:528f73ce625e 32 #define NTPServer "ntp.cc.yamaguchi-u.ac.jp"
yueee_yt 3:528f73ce625e 33
yueee_yt 3:528f73ce625e 34 EthernetInterface eth;
yueee_yt 3:528f73ce625e 35 NTPClient ntp;
yueee_yt 3:528f73ce625e 36 Ticker timer1;
yueee_yt 3:528f73ce625e 37 time_t ctTime;
yueee_yt 3:528f73ce625e 38 char timezone[] = "+09:00"; // JST
yueee_yt 5:96a70a8cebb9 39 char atemp[6],avolt[6],afreq[6], apower1[6],apower2[6],apower3[6],apower4[6];
yueee_yt 3:528f73ce625e 40 FIAP fiap("http://192.168.1.3/axis2/services/FIAPStorage");
yueee_yt 3:528f73ce625e 41 struct fiap_element element[]= {
yueee_yt 5:96a70a8cebb9 42 {"http://www.gutp.jp/SmartTap1/temp",atemp,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
yueee_yt 5:96a70a8cebb9 43 {"http://www.gutp.jp/SmartTap1/volt",avolt,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
yueee_yt 5:96a70a8cebb9 44 {"http://www.gutp.jp/SmartTap1/freq",afreq,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
yueee_yt 5:96a70a8cebb9 45 {"http://www.gutp.jp/SmartTap1/watt_1",apower1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
yueee_yt 5:96a70a8cebb9 46 {"http://www.gutp.jp/SmartTap1/watt_2",apower2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
yueee_yt 5:96a70a8cebb9 47 {"http://www.gutp.jp/SmartTap1/watt_3",apower3,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
yueee_yt 5:96a70a8cebb9 48 {"http://www.gutp.jp/SmartTap1/watt_4",apower4,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
yueee_yt 3:528f73ce625e 49 };
peterbarrett1967 0:606b230e5b4a 50
peterbarrett1967 0:606b230e5b4a 51 /*
peterbarrett1967 0:606b230e5b4a 52 Simple test shell to exercise mouse,keyboard,mass storage and hubs.
peterbarrett1967 0:606b230e5b4a 53 Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
peterbarrett1967 0:606b230e5b4a 54 */
peterbarrett1967 0:606b230e5b4a 55
peterbarrett1967 0:606b230e5b4a 56 Serial pc(USBTX, USBRX);
peterbarrett1967 0:606b230e5b4a 57 int GetConsoleChar()
peterbarrett1967 0:606b230e5b4a 58 {
peterbarrett1967 0:606b230e5b4a 59 if (!pc.readable())
peterbarrett1967 0:606b230e5b4a 60 return -1;
peterbarrett1967 0:606b230e5b4a 61 char c = pc.getc();
peterbarrett1967 0:606b230e5b4a 62 pc.putc(c); // echo
peterbarrett1967 0:606b230e5b4a 63 return c;
peterbarrett1967 0:606b230e5b4a 64 }
yueee_yt 1:3f2890d103fb 65 void InitUSPS();
yueee_yt 1:3f2890d103fb 66 void USPS_Refresh();
yueee_yt 1:3f2890d103fb 67 DigitalOut led1(LED1);
yueee_yt 2:32a2d06f4fe2 68 DigitalOut led2(LED2);
yueee_yt 2:32a2d06f4fe2 69 DigitalOut led3(LED3);
yueee_yt 2:32a2d06f4fe2 70 DigitalOut led4(LED4);
yueee_yt 1:3f2890d103fb 71 Timer t;
yueee_yt 2:32a2d06f4fe2 72 Timer t2;
yueee_yt 3:528f73ce625e 73 Timer t3;
yueee_yt 2:32a2d06f4fe2 74 TextLCD lcd(p24, p26, p27, p28, p29, p30);
yueee_yt 2:32a2d06f4fe2 75 extern float WattData1[],WattData2[],WattData3[],WattData4[];
yueee_yt 2:32a2d06f4fe2 76 extern int SerialNo[];
yueee_yt 3:528f73ce625e 77 extern float TempData[];
yueee_yt 3:528f73ce625e 78 extern float VoltData[];
yueee_yt 3:528f73ce625e 79 extern float FreqData[];
peterbarrett1967 0:606b230e5b4a 80 int main()
peterbarrett1967 0:606b230e5b4a 81 {
yueee_yt 3:528f73ce625e 82 int i;
yueee_yt 3:528f73ce625e 83 lcd.cls();
yueee_yt 3:528f73ce625e 84 lcd.printf("Watting....");
yueee_yt 3:528f73ce625e 85
peterbarrett1967 0:606b230e5b4a 86 pc.baud(460800);
yueee_yt 3:528f73ce625e 87
yueee_yt 3:528f73ce625e 88 eth.init(); //Use DHCP
yueee_yt 3:528f73ce625e 89 eth.connect();
yueee_yt 3:528f73ce625e 90 printf("%s", eth.getIPAddress());
yueee_yt 3:528f73ce625e 91 printf("Trying to update time...\r\n");
yueee_yt 3:528f73ce625e 92 if (ntp.setTime(NTPServer) == 0) {
yueee_yt 3:528f73ce625e 93 printf("Set time successfully\r\n");
yueee_yt 3:528f73ce625e 94 time_t ctTime;
yueee_yt 3:528f73ce625e 95 ctTime = time(NULL);
yueee_yt 3:528f73ce625e 96 ctTime+=32400;
yueee_yt 3:528f73ce625e 97 set_time(ctTime);
yueee_yt 3:528f73ce625e 98 ctTime = time(NULL);
yueee_yt 3:528f73ce625e 99 printf("Time is set to (JST): %s\r\n", ctime(&ctTime));
yueee_yt 3:528f73ce625e 100 printf("finish \n");
yueee_yt 3:528f73ce625e 101 } else {
yueee_yt 3:528f73ce625e 102 lcd.locate(0,1);
yueee_yt 3:528f73ce625e 103 lcd.printf("Error");
yueee_yt 3:528f73ce625e 104 return -1;
yueee_yt 3:528f73ce625e 105 }
yueee_yt 3:528f73ce625e 106
yueee_yt 1:3f2890d103fb 107 InitUSPS();
yueee_yt 2:32a2d06f4fe2 108 USBInit();
yueee_yt 5:96a70a8cebb9 109 fiap.debug_mode=1;
yueee_yt 2:32a2d06f4fe2 110 t.start();
yueee_yt 2:32a2d06f4fe2 111 t2.start();
yueee_yt 3:528f73ce625e 112 t3.start();
yueee_yt 2:32a2d06f4fe2 113 while(1) {
yueee_yt 2:32a2d06f4fe2 114 USBLoop();
yueee_yt 2:32a2d06f4fe2 115 if(t>0.1 ) {
yueee_yt 2:32a2d06f4fe2 116 t.start();
yueee_yt 2:32a2d06f4fe2 117 led4=!led4;
yueee_yt 2:32a2d06f4fe2 118 USPS_Refresh();
yueee_yt 2:32a2d06f4fe2 119 }
yueee_yt 3:528f73ce625e 120 if(t2>1) { //Data to LCDText
yueee_yt 2:32a2d06f4fe2 121 t2.start();
yueee_yt 3:528f73ce625e 122 if(SerialNo[0]==0)led1=0;
yueee_yt 3:528f73ce625e 123 else led1=1;
yueee_yt 2:32a2d06f4fe2 124 lcd.locate(0,0);
yueee_yt 2:32a2d06f4fe2 125 lcd.printf("1:%4.0fW 2:%4.0fW",WattData1[0],WattData2[0]);
yueee_yt 2:32a2d06f4fe2 126 lcd.locate(0,1);
yueee_yt 2:32a2d06f4fe2 127 lcd.printf("3:%4.0fW 4:%4.0fW",WattData3[0],WattData4[0]);
yueee_yt 2:32a2d06f4fe2 128 }
yueee_yt 3:528f73ce625e 129 if(t3>60) { //Data to FiapStorage
yueee_yt 5:96a70a8cebb9 130 led3=1;
yueee_yt 3:528f73ce625e 131 t3.start();
yueee_yt 3:528f73ce625e 132 char buffer[9];
yueee_yt 3:528f73ce625e 133 ctTime = time(NULL);
yueee_yt 3:528f73ce625e 134 strftime(buffer,9,"%X",localtime(&ctTime));
yueee_yt 3:528f73ce625e 135 printf("Storage Store %s \r\n",buffer);
yueee_yt 3:528f73ce625e 136 // Save to FIAPStorage
yueee_yt 3:528f73ce625e 137 struct tm t = *localtime(&ctTime);
yueee_yt 5:96a70a8cebb9 138 for(i=0; i<7; i++) {
yueee_yt 5:96a70a8cebb9 139 element[i].year=t.tm_year+1900;
yueee_yt 5:96a70a8cebb9 140 element[i].month=t.tm_mon+1;
yueee_yt 5:96a70a8cebb9 141 element[i].day=t.tm_mday;
yueee_yt 5:96a70a8cebb9 142 element[i].hour=t.tm_hour;
yueee_yt 5:96a70a8cebb9 143 element[i].minute=t.tm_min;
yueee_yt 5:96a70a8cebb9 144 element[i].second=t.tm_sec;
yueee_yt 3:528f73ce625e 145 }
yueee_yt 5:96a70a8cebb9 146 sprintf(atemp,"%4.1f",TempData[0]);
yueee_yt 5:96a70a8cebb9 147 sprintf(avolt,"%4.1f",VoltData[0]);
yueee_yt 5:96a70a8cebb9 148 sprintf(afreq,"%4.1f",FreqData[0]);
yueee_yt 5:96a70a8cebb9 149 sprintf(apower1,"%4.0f",WattData1[0]);
yueee_yt 5:96a70a8cebb9 150 sprintf(apower2,"%4.0f",WattData2[0]);
yueee_yt 5:96a70a8cebb9 151 sprintf(apower3,"%4.0f",WattData3[0]);
yueee_yt 5:96a70a8cebb9 152 sprintf(apower4,"%4.0f",WattData4[0]);
yueee_yt 5:96a70a8cebb9 153 fiap.post(element,7);
yueee_yt 5:96a70a8cebb9 154 led3=0;
yueee_yt 5:96a70a8cebb9 155 led2=!led2;
yueee_yt 3:528f73ce625e 156 }
yueee_yt 2:32a2d06f4fe2 157 }
peterbarrett1967 0:606b230e5b4a 158 }