スマートコンセント(富士通 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との整合により難しいかもしれません)
Diff: main.cpp
- Revision:
- 3:528f73ce625e
- Parent:
- 2:32a2d06f4fe2
- Child:
- 5:96a70a8cebb9
--- a/main.cpp Thu Sep 27 13:04:36 2012 +0000
+++ b/main.cpp Fri Sep 28 07:10:54 2012 +0000
@@ -20,11 +20,42 @@
THE SOFTWARE.
*/
-#include "mbed.h"
#include "USBHost.h"
#include "Utils.h"
#include "FATFileSystem.h"
#include "TextLCD.h"
+#include "EthernetInterface.h"
+#include "NTPClient.h"
+#include "fiap.h"
+#include "mbed.h"
+
+//#define NTPServer "ntp.nict.jp"
+#define NTPServer "ntp.cc.yamaguchi-u.ac.jp"
+
+EthernetInterface eth;
+NTPClient ntp;
+Ticker timer1;
+time_t ctTime;
+char timezone[] = "+09:00"; // JST
+char atemp1[6],atemp2[6],avolt1[6],avolt2[6],afreq1[6],afreq2[6];
+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];
+FIAP fiap("http://192.168.1.3/axis2/services/FIAPStorage");
+struct fiap_element element[]= {
+ {"http://www.gutp.jp/SmartTap1/temp",atemp1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/volt",avolt1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/freq",afreq1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_1",apower_a1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_2",apower_b1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_3",apower_c1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_4",apower_d1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap2/temp",atemp2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap2/volt",avolt2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap2/freq",afreq2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap2/watt_1",apower_a2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap2/watt_2",apower_b2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap2/watt_3",apower_c2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap2/watt_4",apower_d2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+};
int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
@@ -111,18 +142,45 @@
DigitalOut led4(LED4);
Timer t;
Timer t2;
+Timer t3;
TextLCD lcd(p24, p26, p27, p28, p29, p30);
extern float WattData1[],WattData2[],WattData3[],WattData4[];
extern int SerialNo[];
+extern float TempData[];
+extern float VoltData[];
+extern float FreqData[];
int main()
{
+ int i;
+ lcd.cls();
+ lcd.printf("Watting....");
+
pc.baud(460800);
+
+ eth.init(); //Use DHCP
+ eth.connect();
+ printf("%s", eth.getIPAddress());
+ printf("Trying to update time...\r\n");
+ if (ntp.setTime(NTPServer) == 0) {
+ printf("Set time successfully\r\n");
+ time_t ctTime;
+ ctTime = time(NULL);
+ ctTime+=32400;
+ set_time(ctTime);
+ ctTime = time(NULL);
+ printf("Time is set to (JST): %s\r\n", ctime(&ctTime));
+ printf("finish \n");
+ } else {
+ lcd.locate(0,1);
+ lcd.printf("Error");
+ return -1;
+ }
+
InitUSPS();
USBInit();
t.start();
t2.start();
- lcd.cls();
- lcd.printf("Watting....");
+ t3.start();
while(1) {
USBLoop();
if(t>0.1 ) {
@@ -130,15 +188,58 @@
led4=!led4;
USPS_Refresh();
}
- if(t2>1){
+ if(t2>1) { //Data to LCDText
t2.start();
- if(SerialNo[0]==0)led1=0;else led1=1;
- if(SerialNo[1]==0)led2=0;else led2=1;
- if(SerialNo[2]==0)led3=0;else led3=1;
+ if(SerialNo[0]==0)led1=0;
+ else led1=1;
+ if(SerialNo[1]==0)led2=0;
+ else led2=1;
+ if(SerialNo[2]==0)led3=0;
+ else led3=1;
lcd.locate(0,0);
lcd.printf("1:%4.0fW 2:%4.0fW",WattData1[0],WattData2[0]);
lcd.locate(0,1);
lcd.printf("3:%4.0fW 4:%4.0fW",WattData3[0],WattData4[0]);
}
+ if(t3>60) { //Data to FiapStorage
+ t3.start();
+ char buffer[9];
+ ctTime = time(NULL);
+ strftime(buffer,9,"%X",localtime(&ctTime));
+ printf("Storage Store %s \r\n",buffer);
+// Save to FIAPStorage
+ struct tm t = *localtime(&ctTime);
+ for(i=0; i<14; i++) {
+ element[0].year=t.tm_year+1900;
+ element[0].month=t.tm_mon+1;
+ element[0].day=t.tm_mday;
+ element[0].hour=t.tm_hour;
+ element[0].minute=t.tm_min;
+ element[0].second=t.tm_sec;
+ }
+ for(i=0; i<2; i++) {
+ switch(SerialNo[i]) {
+ case 0x1737:
+ sprintf(atemp1,"%4.1f",TempData[i]);
+ sprintf(avolt1,"%4.1f",VoltData[i]);
+ sprintf(afreq1,"%4.1f",FreqData[i]);
+ sprintf(apower_a1,"%4.0f",WattData1[i]);
+ sprintf(apower_b1,"%4.0f",WattData2[i]);
+ sprintf(apower_c1,"%4.0f",WattData3[i]);
+ sprintf(apower_d1,"%4.0f",WattData4[i]);
+ break;
+ case 0x1871:
+ sprintf(atemp2,"%4.1f",TempData[i]);
+ sprintf(avolt2,"%4.1f",VoltData[i]);
+ sprintf(afreq2,"%4.1f",FreqData[i]);
+ sprintf(apower_a2,"%4.0f",WattData1[i]);
+ sprintf(apower_b2,"%4.0f",WattData2[i]);
+ sprintf(apower_c2,"%4.0f",WattData3[i]);
+ sprintf(apower_d2,"%4.0f",WattData4[i]);
+ break;
+ }
+ }
+ fiap.post(element,1);
+ }
}
}
