スマートコンセント(富士通 FX-5204PS)をIEEE1888 StorageにWRITEするサンプルプログラムです。
Dependencies: EthernetInterface FiapV2 HTTPClientForSOAP NTPClient TextLCD mbed-rtos mbed spxml
Fork of BlueUSB_f by
スマートコンセント(富士通 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との整合により難しいかもしれません)
main.cpp@6:08a406cd2726, 2012-09-30 (annotated)
- Committer:
- yueee_yt
- Date:
- Sun Sep 30 12:45:05 2012 +0000
- Revision:
- 6:08a406cd2726
- Parent:
- 5:96a70a8cebb9
2????????????
Who changed what in which revision?
User | Revision | Line number | New 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 | */ |
yueee_yt | 6:08a406cd2726 | 22 | #ifndef OS_TICK |
yueee_yt | 6:08a406cd2726 | 23 | #define OS_TICK 50000 |
yueee_yt | 6:08a406cd2726 | 24 | #endif |
peterbarrett1967 | 0:606b230e5b4a | 25 | #include "USBHost.h" |
peterbarrett1967 | 0:606b230e5b4a | 26 | #include "Utils.h" |
yueee_yt | 2:32a2d06f4fe2 | 27 | #include "TextLCD.h" |
yueee_yt | 3:528f73ce625e | 28 | #include "EthernetInterface.h" |
yueee_yt | 3:528f73ce625e | 29 | #include "NTPClient.h" |
yueee_yt | 3:528f73ce625e | 30 | #include "fiap.h" |
yueee_yt | 3:528f73ce625e | 31 | #include "mbed.h" |
yueee_yt | 3:528f73ce625e | 32 | |
yueee_yt | 3:528f73ce625e | 33 | //#define NTPServer "ntp.nict.jp" |
yueee_yt | 3:528f73ce625e | 34 | #define NTPServer "ntp.cc.yamaguchi-u.ac.jp" |
yueee_yt | 3:528f73ce625e | 35 | |
yueee_yt | 3:528f73ce625e | 36 | EthernetInterface eth; |
yueee_yt | 3:528f73ce625e | 37 | NTPClient ntp; |
yueee_yt | 3:528f73ce625e | 38 | Ticker timer1; |
yueee_yt | 3:528f73ce625e | 39 | time_t ctTime; |
yueee_yt | 3:528f73ce625e | 40 | char timezone[] = "+09:00"; // JST |
yueee_yt | 6:08a406cd2726 | 41 | char atemp1[6],atemp2[6],avolt1[6],avolt2[6],afreq1[6],afreq2[6]; |
yueee_yt | 6:08a406cd2726 | 42 | char apower_a1[6],apower_a2[6],apower_b1[6],apower_b2[6],apower_c1[6],apower_c2[6],apower_d1[6],apower_d2[6]; |
yueee_yt | 5:96a70a8cebb9 | 43 | char atemp[6],avolt[6],afreq[6], apower1[6],apower2[6],apower3[6],apower4[6]; |
yueee_yt | 3:528f73ce625e | 44 | FIAP fiap("http://192.168.1.3/axis2/services/FIAPStorage"); |
yueee_yt | 3:528f73ce625e | 45 | struct fiap_element element[]= { |
yueee_yt | 6:08a406cd2726 | 46 | {"http://www.gutp.jp/SmartTap1/temp",atemp1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 47 | {"http://www.gutp.jp/SmartTap1/volt",avolt1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 48 | {"http://www.gutp.jp/SmartTap1/freq",afreq1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 49 | {"http://www.gutp.jp/SmartTap1/watt_1",apower_a1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 50 | {"http://www.gutp.jp/SmartTap1/watt_2",apower_b1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 51 | {"http://www.gutp.jp/SmartTap1/watt_3",apower_c1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 52 | {"http://www.gutp.jp/SmartTap1/watt_4",apower_d1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 53 | {"http://www.gutp.jp/SmartTap2/temp",atemp2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 54 | {"http://www.gutp.jp/SmartTap2/volt",avolt2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 55 | {"http://www.gutp.jp/SmartTap2/freq",afreq2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 56 | {"http://www.gutp.jp/SmartTap2/watt_1",apower_a2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 57 | {"http://www.gutp.jp/SmartTap2/watt_2",apower_b2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 58 | {"http://www.gutp.jp/SmartTap2/watt_3",apower_c2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 6:08a406cd2726 | 59 | {"http://www.gutp.jp/SmartTap2/watt_4",apower_d2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 5:96a70a8cebb9 | 60 | {"http://www.gutp.jp/SmartTap1/temp",atemp,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 5:96a70a8cebb9 | 61 | {"http://www.gutp.jp/SmartTap1/volt",avolt,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 5:96a70a8cebb9 | 62 | {"http://www.gutp.jp/SmartTap1/freq",afreq,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 5:96a70a8cebb9 | 63 | {"http://www.gutp.jp/SmartTap1/watt_1",apower1,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 5:96a70a8cebb9 | 64 | {"http://www.gutp.jp/SmartTap1/watt_2",apower2,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 5:96a70a8cebb9 | 65 | {"http://www.gutp.jp/SmartTap1/watt_3",apower3,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 5:96a70a8cebb9 | 66 | {"http://www.gutp.jp/SmartTap1/watt_4",apower4,NULL,NULL,NULL,NULL,NULL,NULL,timezone}, |
yueee_yt | 3:528f73ce625e | 67 | }; |
peterbarrett1967 | 0:606b230e5b4a | 68 | |
peterbarrett1967 | 0:606b230e5b4a | 69 | /* |
peterbarrett1967 | 0:606b230e5b4a | 70 | Simple test shell to exercise mouse,keyboard,mass storage and hubs. |
peterbarrett1967 | 0:606b230e5b4a | 71 | Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it. |
peterbarrett1967 | 0:606b230e5b4a | 72 | */ |
peterbarrett1967 | 0:606b230e5b4a | 73 | |
peterbarrett1967 | 0:606b230e5b4a | 74 | Serial pc(USBTX, USBRX); |
peterbarrett1967 | 0:606b230e5b4a | 75 | int GetConsoleChar() |
peterbarrett1967 | 0:606b230e5b4a | 76 | { |
peterbarrett1967 | 0:606b230e5b4a | 77 | if (!pc.readable()) |
peterbarrett1967 | 0:606b230e5b4a | 78 | return -1; |
peterbarrett1967 | 0:606b230e5b4a | 79 | char c = pc.getc(); |
peterbarrett1967 | 0:606b230e5b4a | 80 | pc.putc(c); // echo |
peterbarrett1967 | 0:606b230e5b4a | 81 | return c; |
peterbarrett1967 | 0:606b230e5b4a | 82 | } |
yueee_yt | 1:3f2890d103fb | 83 | void InitUSPS(); |
yueee_yt | 1:3f2890d103fb | 84 | void USPS_Refresh(); |
yueee_yt | 1:3f2890d103fb | 85 | DigitalOut led1(LED1); |
yueee_yt | 2:32a2d06f4fe2 | 86 | DigitalOut led2(LED2); |
yueee_yt | 2:32a2d06f4fe2 | 87 | DigitalOut led3(LED3); |
yueee_yt | 2:32a2d06f4fe2 | 88 | DigitalOut led4(LED4); |
yueee_yt | 1:3f2890d103fb | 89 | Timer t; |
yueee_yt | 2:32a2d06f4fe2 | 90 | Timer t2; |
yueee_yt | 3:528f73ce625e | 91 | Timer t3; |
yueee_yt | 2:32a2d06f4fe2 | 92 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
yueee_yt | 2:32a2d06f4fe2 | 93 | extern float WattData1[],WattData2[],WattData3[],WattData4[]; |
yueee_yt | 2:32a2d06f4fe2 | 94 | extern int SerialNo[]; |
yueee_yt | 3:528f73ce625e | 95 | extern float TempData[]; |
yueee_yt | 3:528f73ce625e | 96 | extern float VoltData[]; |
yueee_yt | 3:528f73ce625e | 97 | extern float FreqData[]; |
peterbarrett1967 | 0:606b230e5b4a | 98 | int main() |
peterbarrett1967 | 0:606b230e5b4a | 99 | { |
yueee_yt | 3:528f73ce625e | 100 | int i; |
yueee_yt | 3:528f73ce625e | 101 | lcd.cls(); |
yueee_yt | 3:528f73ce625e | 102 | lcd.printf("Watting...."); |
yueee_yt | 3:528f73ce625e | 103 | |
peterbarrett1967 | 0:606b230e5b4a | 104 | pc.baud(460800); |
yueee_yt | 3:528f73ce625e | 105 | |
yueee_yt | 3:528f73ce625e | 106 | eth.init(); //Use DHCP |
yueee_yt | 3:528f73ce625e | 107 | eth.connect(); |
yueee_yt | 3:528f73ce625e | 108 | printf("%s", eth.getIPAddress()); |
yueee_yt | 3:528f73ce625e | 109 | printf("Trying to update time...\r\n"); |
yueee_yt | 3:528f73ce625e | 110 | if (ntp.setTime(NTPServer) == 0) { |
yueee_yt | 3:528f73ce625e | 111 | printf("Set time successfully\r\n"); |
yueee_yt | 3:528f73ce625e | 112 | time_t ctTime; |
yueee_yt | 3:528f73ce625e | 113 | ctTime = time(NULL); |
yueee_yt | 3:528f73ce625e | 114 | ctTime+=32400; |
yueee_yt | 3:528f73ce625e | 115 | set_time(ctTime); |
yueee_yt | 3:528f73ce625e | 116 | ctTime = time(NULL); |
yueee_yt | 3:528f73ce625e | 117 | printf("Time is set to (JST): %s\r\n", ctime(&ctTime)); |
yueee_yt | 3:528f73ce625e | 118 | printf("finish \n"); |
yueee_yt | 3:528f73ce625e | 119 | } else { |
yueee_yt | 3:528f73ce625e | 120 | lcd.locate(0,1); |
yueee_yt | 3:528f73ce625e | 121 | lcd.printf("Error"); |
yueee_yt | 3:528f73ce625e | 122 | return -1; |
yueee_yt | 3:528f73ce625e | 123 | } |
yueee_yt | 3:528f73ce625e | 124 | |
yueee_yt | 1:3f2890d103fb | 125 | InitUSPS(); |
yueee_yt | 2:32a2d06f4fe2 | 126 | USBInit(); |
yueee_yt | 5:96a70a8cebb9 | 127 | fiap.debug_mode=1; |
yueee_yt | 2:32a2d06f4fe2 | 128 | t.start(); |
yueee_yt | 2:32a2d06f4fe2 | 129 | t2.start(); |
yueee_yt | 3:528f73ce625e | 130 | t3.start(); |
yueee_yt | 2:32a2d06f4fe2 | 131 | while(1) { |
yueee_yt | 2:32a2d06f4fe2 | 132 | USBLoop(); |
yueee_yt | 2:32a2d06f4fe2 | 133 | if(t>0.1 ) { |
yueee_yt | 2:32a2d06f4fe2 | 134 | t.start(); |
yueee_yt | 2:32a2d06f4fe2 | 135 | led4=!led4; |
yueee_yt | 2:32a2d06f4fe2 | 136 | USPS_Refresh(); |
yueee_yt | 2:32a2d06f4fe2 | 137 | } |
yueee_yt | 3:528f73ce625e | 138 | if(t2>1) { //Data to LCDText |
yueee_yt | 2:32a2d06f4fe2 | 139 | t2.start(); |
yueee_yt | 6:08a406cd2726 | 140 | if(SerialNo[0]==0)led1=0;else led1=1; |
yueee_yt | 6:08a406cd2726 | 141 | if(SerialNo[1]==0)led2=0;else led2=1; |
yueee_yt | 6:08a406cd2726 | 142 | lcd.locate(0,0); |
yueee_yt | 2:32a2d06f4fe2 | 143 | lcd.printf("1:%4.0fW 2:%4.0fW",WattData1[0],WattData2[0]); |
yueee_yt | 2:32a2d06f4fe2 | 144 | lcd.locate(0,1); |
yueee_yt | 2:32a2d06f4fe2 | 145 | lcd.printf("3:%4.0fW 4:%4.0fW",WattData3[0],WattData4[0]); |
yueee_yt | 2:32a2d06f4fe2 | 146 | } |
yueee_yt | 3:528f73ce625e | 147 | if(t3>60) { //Data to FiapStorage |
yueee_yt | 5:96a70a8cebb9 | 148 | led3=1; |
yueee_yt | 3:528f73ce625e | 149 | t3.start(); |
yueee_yt | 3:528f73ce625e | 150 | char buffer[9]; |
yueee_yt | 3:528f73ce625e | 151 | ctTime = time(NULL); |
yueee_yt | 3:528f73ce625e | 152 | strftime(buffer,9,"%X",localtime(&ctTime)); |
yueee_yt | 3:528f73ce625e | 153 | printf("Storage Store %s \r\n",buffer); |
yueee_yt | 3:528f73ce625e | 154 | // Save to FIAPStorage |
yueee_yt | 3:528f73ce625e | 155 | struct tm t = *localtime(&ctTime); |
yueee_yt | 6:08a406cd2726 | 156 | for(i=0; i<14; i++) { |
yueee_yt | 5:96a70a8cebb9 | 157 | element[i].year=t.tm_year+1900; |
yueee_yt | 5:96a70a8cebb9 | 158 | element[i].month=t.tm_mon+1; |
yueee_yt | 5:96a70a8cebb9 | 159 | element[i].day=t.tm_mday; |
yueee_yt | 5:96a70a8cebb9 | 160 | element[i].hour=t.tm_hour; |
yueee_yt | 5:96a70a8cebb9 | 161 | element[i].minute=t.tm_min; |
yueee_yt | 5:96a70a8cebb9 | 162 | element[i].second=t.tm_sec; |
yueee_yt | 3:528f73ce625e | 163 | } |
yueee_yt | 6:08a406cd2726 | 164 | for(i=0; i<2; i++) { |
yueee_yt | 6:08a406cd2726 | 165 | switch(SerialNo[i]) { |
yueee_yt | 6:08a406cd2726 | 166 | case 0x1737: |
yueee_yt | 6:08a406cd2726 | 167 | sprintf(atemp1,"%4.1f",TempData[i]); |
yueee_yt | 6:08a406cd2726 | 168 | sprintf(avolt1,"%4.1f",VoltData[i]); |
yueee_yt | 6:08a406cd2726 | 169 | sprintf(afreq1,"%4.1f",FreqData[i]); |
yueee_yt | 6:08a406cd2726 | 170 | sprintf(apower_a1,"%4.0f",WattData1[i]); |
yueee_yt | 6:08a406cd2726 | 171 | sprintf(apower_b1,"%4.0f",WattData2[i]); |
yueee_yt | 6:08a406cd2726 | 172 | sprintf(apower_c1,"%4.0f",WattData3[i]); |
yueee_yt | 6:08a406cd2726 | 173 | sprintf(apower_d1,"%4.0f",WattData4[i]); |
yueee_yt | 6:08a406cd2726 | 174 | break; |
yueee_yt | 6:08a406cd2726 | 175 | case 0x1871: |
yueee_yt | 6:08a406cd2726 | 176 | sprintf(atemp2,"%4.1f",TempData[i]); |
yueee_yt | 6:08a406cd2726 | 177 | sprintf(avolt2,"%4.1f",VoltData[i]); |
yueee_yt | 6:08a406cd2726 | 178 | sprintf(afreq2,"%4.1f",FreqData[i]); |
yueee_yt | 6:08a406cd2726 | 179 | sprintf(apower_a2,"%4.0f",WattData1[i]); |
yueee_yt | 6:08a406cd2726 | 180 | sprintf(apower_b2,"%4.0f",WattData2[i]); |
yueee_yt | 6:08a406cd2726 | 181 | sprintf(apower_c2,"%4.0f",WattData3[i]); |
yueee_yt | 6:08a406cd2726 | 182 | sprintf(apower_d2,"%4.0f",WattData4[i]); |
yueee_yt | 6:08a406cd2726 | 183 | break; |
yueee_yt | 6:08a406cd2726 | 184 | } |
yueee_yt | 6:08a406cd2726 | 185 | } |
yueee_yt | 6:08a406cd2726 | 186 | fiap.post(element,14); |
yueee_yt | 5:96a70a8cebb9 | 187 | led3=0; |
yueee_yt | 6:08a406cd2726 | 188 | |
yueee_yt | 3:528f73ce625e | 189 | } |
yueee_yt | 2:32a2d06f4fe2 | 190 | } |
peterbarrett1967 | 0:606b230e5b4a | 191 | } |