this camera C328 http sdcard file server example is for academy
Dependencies: CameraC328 SDFileSystem WIZnetInterface mbed
Insert below jpg file in your SDcard to take a picture in Web Server /media/uploads/IOP/take_a_picture.zip
filelib.h@3:e6025c5b25e4, 2015-08-11 (annotated)
- Committer:
- IOP
- Date:
- Tue Aug 11 05:36:28 2015 +0000
- Revision:
- 3:e6025c5b25e4
- Parent:
- 0:0a851a60b7a6
take picture function organization
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IOP | 0:0a851a60b7a6 | 1 | #ifndef filelib |
IOP | 0:0a851a60b7a6 | 2 | #define filelib |
IOP | 0:0a851a60b7a6 | 3 | |
IOP | 0:0a851a60b7a6 | 4 | #include "mbed.h" |
IOP | 0:0a851a60b7a6 | 5 | #include <time.h> |
IOP | 0:0a851a60b7a6 | 6 | #include <ff.h> //found in lib SDFileSystem->FATFileSystem/ChaN |
IOP | 0:0a851a60b7a6 | 7 | #include "SDFileSystem.h" |
IOP | 0:0a851a60b7a6 | 8 | |
IOP | 0:0a851a60b7a6 | 9 | |
IOP | 0:0a851a60b7a6 | 10 | /* |
IOP | 0:0a851a60b7a6 | 11 | typedef enum { |
IOP | 0:0a851a60b7a6 | 12 | FR_OK = 0, // (0) Succeeded |
IOP | 0:0a851a60b7a6 | 13 | FR_DISK_ERR, // (1) A hard error occurred in the low level disk I/O layer |
IOP | 0:0a851a60b7a6 | 14 | FR_INT_ERR, // (2) Assertion failed |
IOP | 0:0a851a60b7a6 | 15 | FR_NOT_READY, // (3) The physical drive cannot work |
IOP | 0:0a851a60b7a6 | 16 | FR_NO_FILE, // (4) Could not find the file |
IOP | 0:0a851a60b7a6 | 17 | FR_NO_PATH, // (5) Could not find the path |
IOP | 0:0a851a60b7a6 | 18 | FR_INVALID_NAME, // (6) The path name format is invalid |
IOP | 0:0a851a60b7a6 | 19 | FR_DENIED, // (7) Access denied due to prohibited access or directory full |
IOP | 0:0a851a60b7a6 | 20 | FR_EXIST, // (8) Access denied due to prohibited access |
IOP | 0:0a851a60b7a6 | 21 | FR_INVALID_OBJECT, // (9) The file/directory object is invalid |
IOP | 0:0a851a60b7a6 | 22 | FR_WRITE_PROTECTED, // (10) The physical drive is write protected |
IOP | 0:0a851a60b7a6 | 23 | FR_INVALID_DRIVE, // (11) The logical drive number is invalid |
IOP | 0:0a851a60b7a6 | 24 | FR_NOT_ENABLED, // (12) The volume has no work area |
IOP | 0:0a851a60b7a6 | 25 | FR_NO_FILESYSTEM, // (13) There is no valid FAT volume |
IOP | 0:0a851a60b7a6 | 26 | FR_MKFS_ABORTED, // (14) The f_mkfs() aborted due to any parameter error |
IOP | 0:0a851a60b7a6 | 27 | FR_TIMEOUT, // (15) Could not get a grant to access the volume within defined period |
IOP | 0:0a851a60b7a6 | 28 | FR_LOCKED, // (16) The operation is rejected according to the file sharing policy |
IOP | 0:0a851a60b7a6 | 29 | FR_NOT_ENOUGH_CORE, // (17) LFN working buffer could not be allocated |
IOP | 0:0a851a60b7a6 | 30 | FR_TOO_MANY_OPEN_FILES, // (18) Number of open files > _FS_SHARE |
IOP | 0:0a851a60b7a6 | 31 | FR_INVALID_PARAMETER // (19) Given parameter is invalid |
IOP | 0:0a851a60b7a6 | 32 | } FRESULT; |
IOP | 0:0a851a60b7a6 | 33 | |
IOP | 0:0a851a60b7a6 | 34 | */ |
IOP | 0:0a851a60b7a6 | 35 | /* |
IOP | 0:0a851a60b7a6 | 36 | mode_t values in octal |
IOP | 0:0a851a60b7a6 | 37 | S_IFREG 0100000 |
IOP | 0:0a851a60b7a6 | 38 | S_IFDIR 040000 |
IOP | 0:0a851a60b7a6 | 39 | S_IRUSR 0400 read permission, owner |
IOP | 0:0a851a60b7a6 | 40 | S_IWUSR 0200 write permission, owner |
IOP | 0:0a851a60b7a6 | 41 | S_IXUSR 0100 execute/search permission, owner |
IOP | 0:0a851a60b7a6 | 42 | S_IRGRP 040 read permission, group |
IOP | 0:0a851a60b7a6 | 43 | S_IWGRP 020 write permission, group |
IOP | 0:0a851a60b7a6 | 44 | S_IXGRP 010 execute/search permission, group |
IOP | 0:0a851a60b7a6 | 45 | S_IROTH 04 read permission, others |
IOP | 0:0a851a60b7a6 | 46 | S_IWOTH 02 write permission, others |
IOP | 0:0a851a60b7a6 | 47 | S_IXOTH 01 execute/search permission, others |
IOP | 0:0a851a60b7a6 | 48 | */ |
IOP | 0:0a851a60b7a6 | 49 | struct sMystat { |
IOP | 0:0a851a60b7a6 | 50 | // dev_t st_dev; /* ID of device containing file */ |
IOP | 0:0a851a60b7a6 | 51 | // ino_t st_ino; /* inode number */ |
IOP | 0:0a851a60b7a6 | 52 | mode_t st_mode; /* protection */ |
IOP | 0:0a851a60b7a6 | 53 | // nlink_t st_nlink; /* number of hard links */ |
IOP | 0:0a851a60b7a6 | 54 | // uid_t st_uid; /* user ID of owner */ |
IOP | 0:0a851a60b7a6 | 55 | // gid_t st_gid; /* group ID of owner */ |
IOP | 0:0a851a60b7a6 | 56 | // dev_t st_rdev; /* device ID (if special file) */ |
IOP | 0:0a851a60b7a6 | 57 | // off_t st_size; /* total size, in bytes */ |
IOP | 0:0a851a60b7a6 | 58 | DWORD st_size; /* total size, in bytes */ |
IOP | 0:0a851a60b7a6 | 59 | // blksize_t st_blksize; /* blocksize for file system I/O */ |
IOP | 0:0a851a60b7a6 | 60 | // blkcnt_t st_blocks; /* number of 512B blocks allocated */ |
IOP | 0:0a851a60b7a6 | 61 | // time_t st_atime; /* time of last access */ |
IOP | 0:0a851a60b7a6 | 62 | time_t st_mtime; /* time of last modification */ |
IOP | 0:0a851a60b7a6 | 63 | // time_t st_ctime; /* time of last status change */ |
IOP | 0:0a851a60b7a6 | 64 | }; |
IOP | 0:0a851a60b7a6 | 65 | |
IOP | 0:0a851a60b7a6 | 66 | sMystat myStatBuf; //store info for file |
IOP | 0:0a851a60b7a6 | 67 | FILINFO finfo; //global file info struct see ff.h |
IOP | 0:0a851a60b7a6 | 68 | FATFS_DIR dinfo; //global directoty info struct see ff.h |
IOP | 0:0a851a60b7a6 | 69 | |
IOP | 0:0a851a60b7a6 | 70 | FRESULT get_fileInfo(const char *path) //use finfo for get result fields |
IOP | 0:0a851a60b7a6 | 71 | { |
IOP | 0:0a851a60b7a6 | 72 | FRESULT res = f_stat(path,&finfo); /* Get file status */ |
IOP | 0:0a851a60b7a6 | 73 | if (EnDebugMSG) |
IOP | 0:0a851a60b7a6 | 74 | if (res) |
IOP | 0:0a851a60b7a6 | 75 | printf("\n-->get_fileInfo:%s ,res=%d ,Not Found!",path,res); |
IOP | 0:0a851a60b7a6 | 76 | else |
IOP | 0:0a851a60b7a6 | 77 | printf("\n-->get_fileInfo:%s ,res=%d ,Found!",path,res); |
IOP | 0:0a851a60b7a6 | 78 | return res; |
IOP | 0:0a851a60b7a6 | 79 | } |
IOP | 0:0a851a60b7a6 | 80 | |
IOP | 0:0a851a60b7a6 | 81 | FRESULT get_dirInfo(const char *path) |
IOP | 0:0a851a60b7a6 | 82 | { |
IOP | 0:0a851a60b7a6 | 83 | FRESULT res= f_opendir (&dinfo,path); /* FR_OK(0): successful, !=0: error code */ |
IOP | 0:0a851a60b7a6 | 84 | if (EnDebugMSG) |
IOP | 0:0a851a60b7a6 | 85 | if (res) |
IOP | 0:0a851a60b7a6 | 86 | printf("\n-->get_dirInfo :%s res=%d ,This is Not Directory!",path,res); |
IOP | 0:0a851a60b7a6 | 87 | else |
IOP | 0:0a851a60b7a6 | 88 | printf("\n-->get_dirInfo :%s res=%d ,This is Directory!",path,res); |
IOP | 0:0a851a60b7a6 | 89 | return res; |
IOP | 0:0a851a60b7a6 | 90 | } |
IOP | 0:0a851a60b7a6 | 91 | |
IOP | 0:0a851a60b7a6 | 92 | FRESULT Mystat(const char *path, struct sMystat *buf) |
IOP | 0:0a851a60b7a6 | 93 | { |
IOP | 0:0a851a60b7a6 | 94 | FRESULT res = f_stat(path,&finfo); /* Get file status */ |
IOP | 0:0a851a60b7a6 | 95 | if (res == FR_OK) { |
IOP | 0:0a851a60b7a6 | 96 | buf->st_size = finfo.fsize; |
IOP | 0:0a851a60b7a6 | 97 | buf->st_mtime = finfo.ftime; //fdate; |
IOP | 0:0a851a60b7a6 | 98 | buf->st_mode = 4; //? |
IOP | 0:0a851a60b7a6 | 99 | } |
IOP | 0:0a851a60b7a6 | 100 | if (EnDebugMSG) |
IOP | 0:0a851a60b7a6 | 101 | printf("\n--Mystat Path:%s ,filesize:%14lld ,res=%d",path, buf->st_size, res); |
IOP | 0:0a851a60b7a6 | 102 | return res; |
IOP | 0:0a851a60b7a6 | 103 | } |
IOP | 0:0a851a60b7a6 | 104 | |
IOP | 0:0a851a60b7a6 | 105 | |
IOP | 0:0a851a60b7a6 | 106 | static char* get_mime_type( char* filename ) |
IOP | 0:0a851a60b7a6 | 107 | { |
IOP | 0:0a851a60b7a6 | 108 | char* extension; |
IOP | 0:0a851a60b7a6 | 109 | extension = strrchr( filename, '.' ); //get string after last . |
IOP | 0:0a851a60b7a6 | 110 | if (EnDebugMSG) |
IOP | 0:0a851a60b7a6 | 111 | printf("\n-->get_mime_tipe filename:%s, extension:%s",filename, extension); |
IOP | 0:0a851a60b7a6 | 112 | if (extension !=NULL) { |
IOP | 0:0a851a60b7a6 | 113 | if (strcasecmp(extension,".htm")==0 || strcasecmp(extension,".html") ==0) |
IOP | 0:0a851a60b7a6 | 114 | return "text/html; charset=iso-8859-1"; |
IOP | 0:0a851a60b7a6 | 115 | if (strcasecmp(extension,".png")==0) |
IOP | 0:0a851a60b7a6 | 116 | return "image/png"; |
IOP | 0:0a851a60b7a6 | 117 | if (strcasecmp(extension,".css")==0) |
IOP | 0:0a851a60b7a6 | 118 | return "text/css"; |
IOP | 0:0a851a60b7a6 | 119 | if (strcasecmp(extension,".gif")==0) |
IOP | 0:0a851a60b7a6 | 120 | return "image/gif"; |
IOP | 0:0a851a60b7a6 | 121 | if (strcasecmp(extension,".jpg")==0 || strcasecmp(extension,".jpeg" )==0) |
IOP | 0:0a851a60b7a6 | 122 | return "image/jpeg"; |
IOP | 0:0a851a60b7a6 | 123 | } |
IOP | 0:0a851a60b7a6 | 124 | return "text/plain; charset=iso-8859-1"; |
IOP | 0:0a851a60b7a6 | 125 | } |
IOP | 0:0a851a60b7a6 | 126 | |
IOP | 0:0a851a60b7a6 | 127 | #endif |