スマートコンセント(富士通 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との整合により難しいかもしれません)
Revision 5:96a70a8cebb9, committed 2012-09-30
- Comitter:
- yueee_yt
- Date:
- Sun Sep 30 07:41:28 2012 +0000
- Parent:
- 4:357ea5242a16
- Child:
- 6:08a406cd2726
- Commit message:
- ?????1????????????OK?
;
Changed in this revision
--- a/AutoEvents.cpp Sun Sep 30 05:44:10 2012 +0000
+++ b/AutoEvents.cpp Sun Sep 30 07:41:28 2012 +0000
@@ -127,8 +127,6 @@
return 0;
}
-// Implemented in main.cpp
-int OnDiskInsert(int device);
// Implemented in TestShell.cpp
int OnBluetoothInsert(int device);
@@ -153,10 +151,6 @@
switch (interfaceDesc->bInterfaceClass)
{
- case CLASS_MASS_STORAGE:
- if (interfaceDesc->bInterfaceSubClass == 0x06 && interfaceDesc->bInterfaceProtocol == 0x50)
- OnDiskInsert(device); // it's SCSI!
- break;
case CLASS_WIRELESS_CONTROLLER:
if (interfaceDesc->bInterfaceSubClass == 0x01 && interfaceDesc->bInterfaceProtocol == 0x01)
OnBluetoothInsert(device); // it's bluetooth!
--- a/FatFileSystem.lib Sun Sep 30 05:44:10 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/igorsk/code/FatFileSystemCpp/#88f22c32a456
--- a/FiapV2.lib Sun Sep 30 05:44:10 2012 +0000 +++ b/FiapV2.lib Sun Sep 30 07:41:28 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/yueee_yt/code/FiapV2/#52e95ea60ec1 +http://mbed.org/users/yueee_yt/code/FiapV2/#cc924e783dff
--- a/MassStorage.cpp Sun Sep 30 05:44:10 2012 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,180 +0,0 @@
-
-/*
-Copyright (c) 2010 Peter Barrett
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
-
-#include "stdlib.h"
-#include "stdio.h"
-#include "string.h"
-
-#include "Utils.h"
-#include "USBHost.h"
-
-
-int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
-int MassStorage_ReadBlock(int device, u32 block, u8* dst);
-int MassStorage_WriteBlock(int device, u32 block, const u8* dst);
-
-
-#define ERR_BAD_CSW_SIGNATURE -200
-
-#define CBW_SIGNATURE 0x43425355
-#define CSW_SIGNATURE 0x53425355
-
-// Command Block
-typedef struct
-{
- u32 Signature;
- u32 Tag;
- u32 TransferLength;
- u8 Flags;
- u8 LUN;
- u8 CBLength;
- u8 CB[16]; // only 6 really
-} CBW;
-
-// Status block
-typedef struct
-{
- u32 Signature;
- u32 Tag;
- u32 DataResidue;
- u8 Status;
-} CSW;
-
-int SCSIRequestSense(int device);
-
-int DoSCSI(int device, const u8* cmd, int cmdLen, int flags, u8* data, u32 transferLen)
-{
- CBW cbw;
- cbw.Signature = CBW_SIGNATURE;
- cbw.Tag = 0;
- cbw.TransferLength = transferLen;
- cbw.Flags = flags;
- cbw.LUN = 0;
- cbw.CBLength = cmdLen;
- memset(cbw.CB,0,sizeof(cbw.CB));
- memcpy(cbw.CB,cmd,cmdLen);
-
- int r;
- r = USBBulkTransfer(device,0x01,(u8*)&cbw,31); // Send the command
- if (r < 0)
- return r;
-
- if (data)
- {
- r = USBBulkTransfer(device,flags | 1,data,transferLen);
- if (r < 0)
- return r;
- }
-
- CSW csw;
- csw.Signature = 0;
- r = USBBulkTransfer(device,0x81,(u8*)&csw,13);
- if (r < 0)
- return r;
-
- if (csw.Signature != CSW_SIGNATURE)
- return ERR_BAD_CSW_SIGNATURE;
-
- // ModeSense?
- if (csw.Status == 1 && cmd[0] != 3)
- return SCSIRequestSense(device);
-
- return csw.Status;
-}
-
-int SCSITestUnitReady(int device)
-{
- u8 cmd[6];
- memset(cmd,0,6);
- return DoSCSI(device,cmd,6,DEVICE_TO_HOST,0,0);
-}
-
-int SCSIRequestSense(int device)
-{
- u8 cmd[6] = {0x03,0,0,0,18,0};
- u8 result[18];
- int r = DoSCSI(device,cmd,6,DEVICE_TO_HOST,result,18);
- return r;
-}
-
-int SCSIInquiry(int device)
-{
- u8 cmd[6] = {0x12,0,0,0,36,0};
- u8 result[36+2];
- result[36] = '\n';
- result[37] = 0;
- int r = DoSCSI(device,cmd,6,DEVICE_TO_HOST,result,36);
- if (r == 0)
- printf((const char*)result + 8);
- return r;
-}
-
-int SCSIReadCapacity(int device, u32* blockCount, u32* blockSize)
-{
- u8 cmd[10] = {0x25,0,0,0,8,0,0,0,0,0};
- u8 result[8];
- *blockSize = 0;
- *blockCount = 0;
- int r = DoSCSI(device,cmd,10,DEVICE_TO_HOST,result,8);
- if (r == 0)
- {
- *blockCount = BE32(result);
- *blockSize = BE32(result+4);
- }
- return r;
-}
-
-int SCSITransfer(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize, int direction)
-{
- // USB hardware will only do 4k per transfer
- while (blockCount*blockSize > 4096)
- {
- int count = 4096/blockSize;
- int r = SCSITransfer(device,blockAddr,count,dst,blockSize,direction);
- dst += count*blockSize;
- blockAddr += count;
- blockCount -= count;
- }
-
- u8 cmd[10];
- memset(cmd,0,10);
- cmd[0] = (direction == DEVICE_TO_HOST) ? 0x28 : 0x2A;
- BE32(blockAddr,cmd+2);
- BE16(blockCount,cmd+7);
- return DoSCSI(device,cmd,10,direction,dst,blockSize*blockCount);
-}
-
-int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize)
-{
- return SCSIReadCapacity(device,blockCount,blockSize);
-}
-
-int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize = 512)
-{
- return SCSITransfer(device,blockAddr,blockCount,dst,blockSize,DEVICE_TO_HOST);
-}
-
-int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize = 512)
-{
- return SCSITransfer(device,blockAddr,blockCount,dst,blockSize,HOST_TO_DEVICE);
-}
--- a/USBHost.cpp Sun Sep 30 05:44:10 2012 +0000
+++ b/USBHost.cpp Sun Sep 30 07:41:28 2012 +0000
@@ -37,8 +37,9 @@
// USB host structures
-#define USB_RAM_SIZE 16*1024 // AHB SRAM block 1 TODO MACHINE DEPENDENT
-#define USB_RAM_BASE 0x20080000
+#define USB_RAM_SIZE 4096 // AHB SRAM block 1 TODO MACHINE DEPENDENT
+//#define USB_RAM_SIZE 16*1024 // AHB SRAM block 1 TODO MACHINE DEPENDENT
+//#define USB_RAM_BASE 0x20080000
//#define USB_RAM_BASE 0x2007C000
#define TOKEN_SETUP 0
@@ -894,7 +895,7 @@
// Host controller instance and Interrupt handler
//static HostController _controller __attribute__((at(USB_RAM_BASE)));
-static HostController _controller __attribute__((section(".ARM.__AT_0x20080000")));
+static __align(4096) HostController _controller __attribute__((section("AHBSRAM1")));
extern "C" void USB_IRQHandler(void) __irq;
void USB_IRQHandler (void) __irq
--- a/main.cpp Sun Sep 30 05:44:10 2012 +0000
+++ b/main.cpp Sun Sep 30 07:41:28 2012 +0000
@@ -22,7 +22,6 @@
#include "USBHost.h"
#include "Utils.h"
-#include "FATFileSystem.h"
#include "TextLCD.h"
#include "EthernetInterface.h"
#include "NTPClient.h"
@@ -37,89 +36,18 @@
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];
+char atemp[6],avolt[6],afreq[6], apower1[6],apower2[6],apower3[6],apower4[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},
+ {"http://www.gutp.jp/SmartTap1/temp",atemp,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/volt",avolt,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/freq",afreq,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_1",apower1,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_2",apower2,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_3",apower3,NULL,NULL,NULL,NULL,NULL,NULL,timezone},
+ {"http://www.gutp.jp/SmartTap1/watt_4",apower4,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);
-int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
-
-class USBFileSystem : public FATFileSystem
-{
- int _device;
- u32 _blockSize;
- u32 _blockCount;
-
-public:
- USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0) {
- }
-
- void SetDevice(int device) {
- _device = device;
- }
-
- virtual int disk_initialize() {
- return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
- }
-
- virtual int disk_write(const char *buffer, int block_number) {
- return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
- }
-
- virtual int disk_read(char *buffer, int block_number) {
- return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
- }
-
- virtual int disk_sectors() {
- return _blockCount;
- }
-};
-
-void DumpFS(int depth, int count)
-{
- DIR *d = opendir("/usb");
- if (!d) {
- printf("USB file system borked\n");
- return;
- }
-
- printf("\nDumping root dir\n");
- struct dirent *p;
- for(;;) {
- p = readdir(d);
- if (!p)
- break;
- int len = sizeof( dirent);
- printf("%s %d\n", p->d_name, len);
- }
- closedir(d);
-}
-
-int OnDiskInsert(int device)
-{
- USBFileSystem fs;
- fs.SetDevice(device);
- DumpFS(0,0);
- return 0;
-}
-
/*
Simple test shell to exercise mouse,keyboard,mass storage and hubs.
Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
@@ -178,6 +106,7 @@
InitUSPS();
USBInit();
+ fiap.debug_mode=1;
t.start();
t2.start();
t3.start();
@@ -192,16 +121,13 @@
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;
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
+ led3=1;
t3.start();
char buffer[9];
ctTime = time(NULL);
@@ -209,37 +135,24 @@
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<7; i++) {
+ element[i].year=t.tm_year+1900;
+ element[i].month=t.tm_mon+1;
+ element[i].day=t.tm_mday;
+ element[i].hour=t.tm_hour;
+ element[i].minute=t.tm_min;
+ element[i].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);
+ sprintf(atemp,"%4.1f",TempData[0]);
+ sprintf(avolt,"%4.1f",VoltData[0]);
+ sprintf(afreq,"%4.1f",FreqData[0]);
+ sprintf(apower1,"%4.0f",WattData1[0]);
+ sprintf(apower2,"%4.0f",WattData2[0]);
+ sprintf(apower3,"%4.0f",WattData3[0]);
+ sprintf(apower4,"%4.0f",WattData4[0]);
+ fiap.post(element,7);
+ led3=0;
+ led2=!led2;
}
}
}
