MDX-20用の改造
Dependencies: FatFileSystemCpp
Revision 4:dc14f62cb09f, committed 2016-11-23
- Comitter:
- suupen
- Date:
- Wed Nov 23 09:12:30 2016 +0000
- Parent:
- 3:95e55809ecdb
- Child:
- 5:0ee37dbafd9a
- Commit message:
- usbmemory???prn?????????????
Changed in this revision
--- a/MSCFileSystem.cpp Mon Jul 30 13:49:56 2012 +0000 +++ b/MSCFileSystem.cpp Wed Nov 23 09:12:30 2016 +0000 @@ -9,10 +9,23 @@ * TODO: write one * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library */ - + #include "MSCFileSystem.h" #include "usbhost_inc.h" +/* +************************************************************************************************************** +* PRINT CONFIGURATION +************************************************************************************************************** +*/ +//#define DEBUG +#ifdef DEBUG +#define DEBUG_PRINT(...) printf(__VA_ARGS__) +#else +#define DEBUG_PRINT(...) +#endif // DEBUG + + MSCFileSystem::MSCFileSystem(const char* name) : FATFileSystem(name) { @@ -22,40 +35,40 @@ { // see USB Mass Storage Class – UFI Command Specification, // 4.2 INQUIRY Command - printf("Inquiry reply:\n"); + DEBUG_PRINT("Inquiry reply:\n"); uint8_t tmp = inqReply[0]&0x1F; - printf("Peripheral device type: %02Xh\n", tmp); + DEBUG_PRINT("Peripheral device type: %02Xh\n", tmp); if ( tmp == 0 ) - printf("\t- Direct access (floppy)\n"); + DEBUG_PRINT("\t- Direct access (floppy)\n"); else if ( tmp == 0x1F ) - printf("\t- none (no FDD connected)\n"); + DEBUG_PRINT("\t- none (no FDD connected)\n"); else - printf("\t- unknown type\n"); + DEBUG_PRINT("\t- unknown type\n"); tmp = inqReply[1] >> 7; - printf("Removable Media Bit: %d\n", tmp); + DEBUG_PRINT("Removable Media Bit: %d\n", tmp); tmp = inqReply[2] & 3; - printf("ANSI Version: %02Xh\n", tmp); + DEBUG_PRINT("ANSI Version: %02Xh\n", tmp); if ( tmp != 0 ) - printf("\t- warning! must be 0\n"); + DEBUG_PRINT("\t- warning! must be 0\n"); tmp = (inqReply[2]>>3) & 3; - printf("ECMA Version: %02Xh\n", tmp); + DEBUG_PRINT("ECMA Version: %02Xh\n", tmp); if ( tmp != 0 ) - printf("\t- warning! should be 0\n"); + DEBUG_PRINT("\t- warning! should be 0\n"); tmp = inqReply[2]>>6; - printf("ISO Version: %02Xh\n", tmp); + DEBUG_PRINT("ISO Version: %02Xh\n", tmp); if ( tmp != 0 ) - printf("\t- warning! should be 0\n"); + DEBUG_PRINT("\t- warning! should be 0\n"); tmp = inqReply[3] & 0xF; - printf("Response Data Format: %02Xh\n", tmp); + DEBUG_PRINT("Response Data Format: %02Xh\n", tmp); if ( tmp != 1 ) - printf("\t- warning! should be 1\n"); + DEBUG_PRINT("\t- warning! should be 1\n"); tmp = inqReply[4]; - printf("Additional length: %02Xh\n", tmp); + DEBUG_PRINT("Additional length: %02Xh\n", tmp); if ( tmp != 0x1F ) - printf("\t- warning! should be 1Fh\n"); - printf("Vendor Information: '%.8s'\n", &inqReply[8]); - printf("Product Identification: '%.16s'\n", &inqReply[16]); - printf("Product Revision: '%.4s'\n", &inqReply[32]); + DEBUG_PRINT("\t- warning! should be 1Fh\n"); + DEBUG_PRINT("Vendor Information: '%.8s'\n", &inqReply[8]); + DEBUG_PRINT("Product Identification: '%.16s'\n", &inqReply[16]); + DEBUG_PRINT("Product Revision: '%.4s'\n", &inqReply[32]); } int MSCFileSystem::initialise_msc() @@ -80,7 +93,7 @@ fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc); return rc; } - printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); + DEBUG_PRINT("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize); print_inquiry(inquiryResult); // FATFileSystem supports only 512-byte blocks return _blkSize == 512 ? OK : 1;
--- a/USBHostLite/usbhost_lpc17xx.h Mon Jul 30 13:49:56 2012 +0000 +++ b/USBHostLite/usbhost_lpc17xx.h Wed Nov 23 09:12:30 2016 +0000 @@ -33,7 +33,7 @@ ************************************************************************************************************** */ -#define PRINT_ENABLE 1 +#define PRINT_ENABLE 0 #if PRINT_ENABLE #define PRINT_Log(...) printf(__VA_ARGS__)
--- a/main.cpp Mon Jul 30 13:49:56 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -#include "mbed.h" -#include "MSCFileSystem.h" -//#include <stat.h> - -#define FSNAME "msc" -MSCFileSystem msc(FSNAME); - -int main() -{ - DIR *d; - struct dirent *p; - //struct stat st; - //char path[PATH_MAX]; - - printf("\n\n================================\n"); - printf("USB Mass storage demo program for mbed LPC1768\n"); - printf("================================\n\n"); - - d = opendir("/" FSNAME); - - printf("\nList of files on the flash drive:\n"); - if ( d != NULL ) - { - while ( (p = readdir(d)) != NULL ) - { - printf(" - %s\n", p->d_name); - /* no <stat.h> on mbed, it seems :/ - sprintf(path, "/"FSNAME"/%s", p->d_name); - if ( stat(path, &st) == 0 ) - { - if ( S_ISDIR(st.st_mode) ) - printf(" <directory>\n"); - else - printf(" %d\n", st.st_size); - } - else - { - printf(" ???\n"); - }*/ - } - } - else - { - error("Could not open directory!"); - } - printf("\nTesting file write:\n"); - FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w"); - if ( fp == NULL ) - { - error("Could not open file for write\n"); - } - fprintf(fp, "Hello mass storage!"); - fclose(fp); - printf("\n - OK\n"); - - printf("\nTesting file read:\n"); - fp = fopen( "/" FSNAME "/msctest.txt", "r"); - if ( fp == NULL ) - { - error("Could not open file for read\n"); - } - char buf[256]; - if ( NULL == fgets(buf, sizeof(buf), fp) ) - { - error("Error reading from file\n"); - } - fclose(fp); - printf("\n - OK, read string: '%s'\n\n", buf); -}
--- a/mbed.bld Mon Jul 30 13:49:56 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbMemory.cpp Wed Nov 23 09:12:30 2016 +0000 @@ -0,0 +1,104 @@ +#include "mbed.h" +#include "MSCFileSystem.h" +//#include <stat.h> +#include "string.h" + +/* +************************************************************************************************************** +* PRINT CONFIGURATION +************************************************************************************************************** +*/ + +//#define DEBUG +#ifdef DEBUG +#define DEBUG_PRINT(...) printf(__VA_ARGS__) +#else +#define DEBUG_PRINT(...) +#endif // DEBUG + + +#define FSNAME "msc" +MSCFileSystem msc(FSNAME); +FILE *fp; + + + +char fileName[20]; +char buffer[50]; + +int32_t fileDetect(char *fileName, uint32_t *numberLine) +{ + static uint32_t numMax = 0; + int32_t ans = false; + + DIR *d; + struct dirent *p; + + d = opendir("/" FSNAME); + + // directory check + if ( d != NULL ) { + while ( (p = readdir(d)) != NULL ) { + if(NULL != strstr(p->d_name, ".prn")) { + strcpy(fileName, p->d_name); + DEBUG_PRINT("detect = %s\n",fileName); + ans = true; + continue; + } + } + // file check + if (ans == true) { + sprintf(buffer,"/msc/%s",fileName); + fp = fopen( buffer, "r"); + if ( fp != NULL ) { + char buf[256]; + while ( NULL != fgets(buf, sizeof(buf), fp) ) { + DEBUG_PRINT("%s", buf); + numMax++; + } + *numberLine = numMax; + fclose(fp); + + } else { + // Don't file open + // nothing + } + } else { + // nothing Directory + } + } + return ans; + +} + +uint32_t fileOneLineRead(char *fileName, char *data, uint32_t dataNumber, uint32_t numberLine) +{ +// static FILE *fp; + int32_t ans = false; + #define bufferNumber 100 + char buffer[bufferNumber]; + + sprintf(buffer,"/msc/%s",fileName); + + fp = fopen( buffer, "r"); + if ( fp != NULL ) { + for(uint32_t i = 0; i < numberLine; i++){ + fgets(buffer, sizeof(buffer), fp); + } + + if(NULL != fgets(data, dataNumber, fp)){ + DEBUG_PRINT("line = %s\r\n", data); + fclose(fp); + ans = true; + } + else{ + // nothing + } + } else { + // Don't file open + // nothing + } + + return ans; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbMemory.h Wed Nov 23 09:12:30 2016 +0000 @@ -0,0 +1,12 @@ + +#ifndef USBMEMORY_H +#define USBMEMORY_H + +#include "usbMemory.h" + +int32_t fileDetect(char *fileName, uint32_t *numberLine); +uint32_t fileOneLineRead(char *fileName, char *data, uint32_t dataNumber, uint32_t numberLine); + + + +#endif // USBMEMORY_H \ No newline at end of file