![](/media/cache/profiles/f0fcf351df4eb6786e9bb6fc4e2dee02.jpg.50x50_q85.jpg)
Test program for FlashAir with iSDIO
Dependencies: FlashAir_iSDIO SDFileSystem
FlashAir_monitor/mon.cpp@3:fc1908567f3b, 2019-08-28 (annotated)
- Committer:
- kenjiArai
- Date:
- Wed Aug 28 22:48:37 2019 +0000
- Revision:
- 3:fc1908567f3b
Test program for FlashAir/TOSHIBA with iSDIO
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 3:fc1908567f3b | 1 | /* |
kenjiArai | 3:fc1908567f3b | 2 | * mbed Application program for the mbed |
kenjiArai | 3:fc1908567f3b | 3 | * FlashAir Check program |
kenjiArai | 3:fc1908567f3b | 4 | * |
kenjiArai | 3:fc1908567f3b | 5 | * Copyright (c) 2015,'19 Kenji Arai / JH1PJL |
kenjiArai | 3:fc1908567f3b | 6 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 3:fc1908567f3b | 7 | * https://os.mbed.com/users/kenjiArai/ |
kenjiArai | 3:fc1908567f3b | 8 | * Created: May 5th, 2015 |
kenjiArai | 3:fc1908567f3b | 9 | * Revised: August 27th, 2019 |
kenjiArai | 3:fc1908567f3b | 10 | */ |
kenjiArai | 3:fc1908567f3b | 11 | |
kenjiArai | 3:fc1908567f3b | 12 | // Include -------------------------------------------------------------------- |
kenjiArai | 3:fc1908567f3b | 13 | #include "mbed.h" |
kenjiArai | 3:fc1908567f3b | 14 | #include "FlashAir_iSDIO.h" |
kenjiArai | 3:fc1908567f3b | 15 | #include "mon.h" |
kenjiArai | 3:fc1908567f3b | 16 | |
kenjiArai | 3:fc1908567f3b | 17 | // Definition ----------------------------------------------------------------- |
kenjiArai | 3:fc1908567f3b | 18 | #define DO_DEBUG 0 |
kenjiArai | 3:fc1908567f3b | 19 | |
kenjiArai | 3:fc1908567f3b | 20 | #if DO_DEBUG |
kenjiArai | 3:fc1908567f3b | 21 | #define DEBUG_LINE pc.printf("line:%d\r\n", __LINE__); |
kenjiArai | 3:fc1908567f3b | 22 | #else |
kenjiArai | 3:fc1908567f3b | 23 | #define DEBUG_LINE {;} |
kenjiArai | 3:fc1908567f3b | 24 | #endif |
kenjiArai | 3:fc1908567f3b | 25 | |
kenjiArai | 3:fc1908567f3b | 26 | // from ffconf.h |
kenjiArai | 3:fc1908567f3b | 27 | #define _VOLUMES 1 |
kenjiArai | 3:fc1908567f3b | 28 | |
kenjiArai | 3:fc1908567f3b | 29 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 3:fc1908567f3b | 30 | BYTE Buff[4096]; |
kenjiArai | 3:fc1908567f3b | 31 | char linebuf[64]; // Console input buffer |
kenjiArai | 3:fc1908567f3b | 32 | FATFS Fatfs[_VOLUMES]; // File system object for each logical drive |
kenjiArai | 3:fc1908567f3b | 33 | FIL File1, File2; // File objects |
kenjiArai | 3:fc1908567f3b | 34 | FATFS_DIR* Dirx; |
kenjiArai | 3:fc1908567f3b | 35 | FILINFO Finfo; |
kenjiArai | 3:fc1908567f3b | 36 | char Lfname[512]; |
kenjiArai | 3:fc1908567f3b | 37 | DWORD AccSize; // Work register for fs command |
kenjiArai | 3:fc1908567f3b | 38 | WORD AccFiles, AccDirs; |
kenjiArai | 3:fc1908567f3b | 39 | |
kenjiArai | 3:fc1908567f3b | 40 | uint8_t buffer[512]; |
kenjiArai | 3:fc1908567f3b | 41 | uint32_t nextSequenceId = 0; |
kenjiArai | 3:fc1908567f3b | 42 | |
kenjiArai | 3:fc1908567f3b | 43 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 3:fc1908567f3b | 44 | const char *const monmsg0 = |
kenjiArai | 3:fc1908567f3b | 45 | "Start monitor program for FlashAir & FatFs/SD File System\r\n"; |
kenjiArai | 3:fc1908567f3b | 46 | const char *const monmsg1 = |
kenjiArai | 3:fc1908567f3b | 47 | " <Please press any key to start the monitor>"; |
kenjiArai | 3:fc1908567f3b | 48 | const char *const hisdmsg0 = |
kenjiArai | 3:fc1908567f3b | 49 | "Entered FlashAir/TOSHIBA iSDIO control commands\r\n"; |
kenjiArai | 3:fc1908567f3b | 50 | const char *const hisdmsg1 = |
kenjiArai | 3:fc1908567f3b | 51 | " retrun=q Help=?\r\n"; |
kenjiArai | 3:fc1908567f3b | 52 | const char *const rtnmsg = |
kenjiArai | 3:fc1908567f3b | 53 | "Return to Root Mode\r\n"; |
kenjiArai | 3:fc1908567f3b | 54 | const char *const msg_ok = |
kenjiArai | 3:fc1908567f3b | 55 | "\r\nSuccess\r\n"; |
kenjiArai | 3:fc1908567f3b | 56 | const char *const msg_ng = |
kenjiArai | 3:fc1908567f3b | 57 | "\r\nFailed\r\n"; |
kenjiArai | 3:fc1908567f3b | 58 | |
kenjiArai | 3:fc1908567f3b | 59 | static const char HelpMsg0[] = |
kenjiArai | 3:fc1908567f3b | 60 | "i FlashAir, iSDIO\r\n" |
kenjiArai | 3:fc1908567f3b | 61 | "dir <full_pass>\r\n" |
kenjiArai | 3:fc1908567f3b | 62 | "type <file_name>\r\n" |
kenjiArai | 3:fc1908567f3b | 63 | "vol\r\n" |
kenjiArai | 3:fc1908567f3b | 64 | "ren <org_file_name> <new_file_name>\r\n" |
kenjiArai | 3:fc1908567f3b | 65 | "copy <file_name> <file_name>\r\n" |
kenjiArai | 3:fc1908567f3b | 66 | "mkdir <dir_name>\r\n" |
kenjiArai | 3:fc1908567f3b | 67 | "cd <dir_name>\r\n" |
kenjiArai | 3:fc1908567f3b | 68 | "q Return to main\r\n" |
kenjiArai | 3:fc1908567f3b | 69 | "t Show current time or Adjust time\r\n" |
kenjiArai | 3:fc1908567f3b | 70 | " e.g. t 19 8 24 14 15 16 -> August 24,'19, 14:15:16\r\n" |
kenjiArai | 3:fc1908567f3b | 71 | "? Help/You know the command\r\n" |
kenjiArai | 3:fc1908567f3b | 72 | "\r\n"; |
kenjiArai | 3:fc1908567f3b | 73 | |
kenjiArai | 3:fc1908567f3b | 74 | static const char HelpMsg1[] = |
kenjiArai | 3:fc1908567f3b | 75 | "a Set as AP(Access Point) mode / Act as Host\r\n" |
kenjiArai | 3:fc1908567f3b | 76 | "s Set as STA(Station) mode / Connect to Host\r\n" |
kenjiArai | 3:fc1908567f3b | 77 | "q Return to File control monitor\r\n" |
kenjiArai | 3:fc1908567f3b | 78 | "\r\n"; |
kenjiArai | 3:fc1908567f3b | 79 | |
kenjiArai | 3:fc1908567f3b | 80 | static const char HelpMsg2[] = |
kenjiArai | 3:fc1908567f3b | 81 | "Connect to Host: step d->s->c->g\r\n" |
kenjiArai | 3:fc1908567f3b | 82 | "s Scan sounded host\r\n" |
kenjiArai | 3:fc1908567f3b | 83 | "c Connect specific host\r\n" |
kenjiArai | 3:fc1908567f3b | 84 | "d Disconnect line\r\n" |
kenjiArai | 3:fc1908567f3b | 85 | "g Get status\r\n" |
kenjiArai | 3:fc1908567f3b | 86 | "t Current time(JST)\r\n" |
kenjiArai | 3:fc1908567f3b | 87 | "q Return to previous monitor\r\n" |
kenjiArai | 3:fc1908567f3b | 88 | "\r\n"; |
kenjiArai | 3:fc1908567f3b | 89 | |
kenjiArai | 3:fc1908567f3b | 90 | static const char HelpMsg3[] = |
kenjiArai | 3:fc1908567f3b | 91 | "Estblish as Host: step d->e->g\r\n" |
kenjiArai | 3:fc1908567f3b | 92 | "e Establish connection\r\n" |
kenjiArai | 3:fc1908567f3b | 93 | "d Disconnect line\r\n" |
kenjiArai | 3:fc1908567f3b | 94 | "g Get status\r\n" |
kenjiArai | 3:fc1908567f3b | 95 | "q Return to previous monitor\r\n" |
kenjiArai | 3:fc1908567f3b | 96 | "\r\n"; |
kenjiArai | 3:fc1908567f3b | 97 | |
kenjiArai | 3:fc1908567f3b | 98 | // Host information @ STA mode |
kenjiArai | 3:fc1908567f3b | 99 | const char *const ssid = "pr500m-c86a71-1"; |
kenjiArai | 3:fc1908567f3b | 100 | const char *const networkKey = "7daaa01146644"; |
kenjiArai | 3:fc1908567f3b | 101 | |
kenjiArai | 3:fc1908567f3b | 102 | // FlashAir Host name & password @ AP mode |
kenjiArai | 3:fc1908567f3b | 103 | const char *const name_as_host = "flashair"; |
kenjiArai | 3:fc1908567f3b | 104 | const char *const password_ap = "12345678"; |
kenjiArai | 3:fc1908567f3b | 105 | |
kenjiArai | 3:fc1908567f3b | 106 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 3:fc1908567f3b | 107 | |
kenjiArai | 3:fc1908567f3b | 108 | // Object --------------------------------------------------------------------- |
kenjiArai | 3:fc1908567f3b | 109 | extern Serial pc; |
kenjiArai | 3:fc1908567f3b | 110 | extern FlashAir_iSDIO sd; |
kenjiArai | 3:fc1908567f3b | 111 | Timer t; |
kenjiArai | 3:fc1908567f3b | 112 | |
kenjiArai | 3:fc1908567f3b | 113 | //------------------------------------------------------------------------------ |
kenjiArai | 3:fc1908567f3b | 114 | // Control Program |
kenjiArai | 3:fc1908567f3b | 115 | //------------------------------------------------------------------------------ |
kenjiArai | 3:fc1908567f3b | 116 | // Monitor program for File control |
kenjiArai | 3:fc1908567f3b | 117 | void mon () |
kenjiArai | 3:fc1908567f3b | 118 | { |
kenjiArai | 3:fc1908567f3b | 119 | char *ptr; |
kenjiArai | 3:fc1908567f3b | 120 | |
kenjiArai | 3:fc1908567f3b | 121 | Dirx = new FATFS_DIR; |
kenjiArai | 3:fc1908567f3b | 122 | /* Open Uart to communicate with Host PC */ |
kenjiArai | 3:fc1908567f3b | 123 | pc.puts(monmsg0); |
kenjiArai | 3:fc1908567f3b | 124 | pc.puts(monmsg1); |
kenjiArai | 3:fc1908567f3b | 125 | crlf(); |
kenjiArai | 3:fc1908567f3b | 126 | /* monitor is running all time when systen is running */ |
kenjiArai | 3:fc1908567f3b | 127 | char c = pc.getc(); |
kenjiArai | 3:fc1908567f3b | 128 | Finfo.lfname = Lfname; |
kenjiArai | 3:fc1908567f3b | 129 | Finfo.lfsize = sizeof Lfname; |
kenjiArai | 3:fc1908567f3b | 130 | //pc.printf("0x%x, 0x%x\r\n", mon, HelpMsg0); |
kenjiArai | 3:fc1908567f3b | 131 | for (;;) { |
kenjiArai | 3:fc1908567f3b | 132 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 133 | pc.putc('>'); |
kenjiArai | 3:fc1908567f3b | 134 | ptr = linebuf; |
kenjiArai | 3:fc1908567f3b | 135 | get_line( ptr, sizeof(linebuf) ); |
kenjiArai | 3:fc1908567f3b | 136 | switch ( *ptr++ ) { |
kenjiArai | 3:fc1908567f3b | 137 | // iSDIO, goto sub functions |
kenjiArai | 3:fc1908567f3b | 138 | case 'i' : |
kenjiArai | 3:fc1908567f3b | 139 | isdio_mon(ptr); |
kenjiArai | 3:fc1908567f3b | 140 | break; |
kenjiArai | 3:fc1908567f3b | 141 | // vol |
kenjiArai | 3:fc1908567f3b | 142 | case 'v' : |
kenjiArai | 3:fc1908567f3b | 143 | v_next(ptr); |
kenjiArai | 3:fc1908567f3b | 144 | break; |
kenjiArai | 3:fc1908567f3b | 145 | // dir |
kenjiArai | 3:fc1908567f3b | 146 | case 'd' : |
kenjiArai | 3:fc1908567f3b | 147 | d_next(ptr); |
kenjiArai | 3:fc1908567f3b | 148 | break; |
kenjiArai | 3:fc1908567f3b | 149 | // cd, copy |
kenjiArai | 3:fc1908567f3b | 150 | case 'c' : |
kenjiArai | 3:fc1908567f3b | 151 | c_next(ptr); |
kenjiArai | 3:fc1908567f3b | 152 | break; |
kenjiArai | 3:fc1908567f3b | 153 | // mkdir |
kenjiArai | 3:fc1908567f3b | 154 | case 'm' : |
kenjiArai | 3:fc1908567f3b | 155 | m_next(ptr); |
kenjiArai | 3:fc1908567f3b | 156 | break; |
kenjiArai | 3:fc1908567f3b | 157 | // ren |
kenjiArai | 3:fc1908567f3b | 158 | case 'r' : |
kenjiArai | 3:fc1908567f3b | 159 | r_next(ptr); |
kenjiArai | 3:fc1908567f3b | 160 | break; |
kenjiArai | 3:fc1908567f3b | 161 | // type, set time |
kenjiArai | 3:fc1908567f3b | 162 | case 't' : |
kenjiArai | 3:fc1908567f3b | 163 | t_next(ptr); |
kenjiArai | 3:fc1908567f3b | 164 | break; |
kenjiArai | 3:fc1908567f3b | 165 | // Help |
kenjiArai | 3:fc1908567f3b | 166 | case '?' : |
kenjiArai | 3:fc1908567f3b | 167 | pc.puts(HelpMsg0); |
kenjiArai | 3:fc1908567f3b | 168 | break; |
kenjiArai | 3:fc1908567f3b | 169 | // Exit monitor (return to main()) |
kenjiArai | 3:fc1908567f3b | 170 | case 'q' : |
kenjiArai | 3:fc1908567f3b | 171 | pc.puts("Return to main\r\n"); |
kenjiArai | 3:fc1908567f3b | 172 | return; |
kenjiArai | 3:fc1908567f3b | 173 | // Not a command |
kenjiArai | 3:fc1908567f3b | 174 | default: |
kenjiArai | 3:fc1908567f3b | 175 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 176 | pc.puts("? [HELP]=?"); |
kenjiArai | 3:fc1908567f3b | 177 | crlf(); |
kenjiArai | 3:fc1908567f3b | 178 | break; |
kenjiArai | 3:fc1908567f3b | 179 | } |
kenjiArai | 3:fc1908567f3b | 180 | } |
kenjiArai | 3:fc1908567f3b | 181 | } |
kenjiArai | 3:fc1908567f3b | 182 | |
kenjiArai | 3:fc1908567f3b | 183 | uint32_t get_disk_freespace(void) |
kenjiArai | 3:fc1908567f3b | 184 | { |
kenjiArai | 3:fc1908567f3b | 185 | long p1; |
kenjiArai | 3:fc1908567f3b | 186 | UINT s1, s2; |
kenjiArai | 3:fc1908567f3b | 187 | FATFS *fs; |
kenjiArai | 3:fc1908567f3b | 188 | BYTE res; |
kenjiArai | 3:fc1908567f3b | 189 | |
kenjiArai | 3:fc1908567f3b | 190 | if (Dirx == NULL) { |
kenjiArai | 3:fc1908567f3b | 191 | Dirx = new FATFS_DIR; |
kenjiArai | 3:fc1908567f3b | 192 | } |
kenjiArai | 3:fc1908567f3b | 193 | char p = NULL; |
kenjiArai | 3:fc1908567f3b | 194 | res = f_opendir(Dirx, &p); |
kenjiArai | 3:fc1908567f3b | 195 | if (res) { |
kenjiArai | 3:fc1908567f3b | 196 | return 0; |
kenjiArai | 3:fc1908567f3b | 197 | } |
kenjiArai | 3:fc1908567f3b | 198 | p1 = s1 = s2 = 0; |
kenjiArai | 3:fc1908567f3b | 199 | for(;;) { |
kenjiArai | 3:fc1908567f3b | 200 | res = f_readdir(Dirx, &Finfo); |
kenjiArai | 3:fc1908567f3b | 201 | if ((res != FR_OK) || !Finfo.fname[0]) break; |
kenjiArai | 3:fc1908567f3b | 202 | if (Finfo.fattrib & AM_DIR) { |
kenjiArai | 3:fc1908567f3b | 203 | s2++; |
kenjiArai | 3:fc1908567f3b | 204 | } else { |
kenjiArai | 3:fc1908567f3b | 205 | s1++; |
kenjiArai | 3:fc1908567f3b | 206 | p1 += Finfo.fsize; |
kenjiArai | 3:fc1908567f3b | 207 | } |
kenjiArai | 3:fc1908567f3b | 208 | } |
kenjiArai | 3:fc1908567f3b | 209 | res = f_getfree(&p, (DWORD*)&p1, &fs); |
kenjiArai | 3:fc1908567f3b | 210 | uint32_t size = p1 * fs->csize * 512; |
kenjiArai | 3:fc1908567f3b | 211 | if (res == FR_OK) { |
kenjiArai | 3:fc1908567f3b | 212 | return size; |
kenjiArai | 3:fc1908567f3b | 213 | } else { |
kenjiArai | 3:fc1908567f3b | 214 | return 0; |
kenjiArai | 3:fc1908567f3b | 215 | } |
kenjiArai | 3:fc1908567f3b | 216 | } |
kenjiArai | 3:fc1908567f3b | 217 | |
kenjiArai | 3:fc1908567f3b | 218 | static void isdio_mon(char *ptr) |
kenjiArai | 3:fc1908567f3b | 219 | { |
kenjiArai | 3:fc1908567f3b | 220 | pc.puts(hisdmsg0); |
kenjiArai | 3:fc1908567f3b | 221 | pc.puts(hisdmsg1); |
kenjiArai | 3:fc1908567f3b | 222 | for (uint32_t i=0; i==0; ) { |
kenjiArai | 3:fc1908567f3b | 223 | pc.puts("iSDIO>"); |
kenjiArai | 3:fc1908567f3b | 224 | ptr = linebuf; |
kenjiArai | 3:fc1908567f3b | 225 | get_line(ptr, sizeof(linebuf)); |
kenjiArai | 3:fc1908567f3b | 226 | switch(*ptr++) { |
kenjiArai | 3:fc1908567f3b | 227 | case 'a' : |
kenjiArai | 3:fc1908567f3b | 228 | ap_mon(ptr); |
kenjiArai | 3:fc1908567f3b | 229 | break; |
kenjiArai | 3:fc1908567f3b | 230 | case 's' : |
kenjiArai | 3:fc1908567f3b | 231 | sta_mon(ptr); |
kenjiArai | 3:fc1908567f3b | 232 | break; |
kenjiArai | 3:fc1908567f3b | 233 | case 'q' : |
kenjiArai | 3:fc1908567f3b | 234 | i = 1; // return |
kenjiArai | 3:fc1908567f3b | 235 | break; |
kenjiArai | 3:fc1908567f3b | 236 | case '?' : |
kenjiArai | 3:fc1908567f3b | 237 | pc.puts(HelpMsg1); |
kenjiArai | 3:fc1908567f3b | 238 | break; |
kenjiArai | 3:fc1908567f3b | 239 | default: |
kenjiArai | 3:fc1908567f3b | 240 | pc.putc('?'); |
kenjiArai | 3:fc1908567f3b | 241 | crlf(); |
kenjiArai | 3:fc1908567f3b | 242 | } |
kenjiArai | 3:fc1908567f3b | 243 | } |
kenjiArai | 3:fc1908567f3b | 244 | pc.puts(rtnmsg); |
kenjiArai | 3:fc1908567f3b | 245 | } |
kenjiArai | 3:fc1908567f3b | 246 | |
kenjiArai | 3:fc1908567f3b | 247 | // Station Mode (connect to Host) |
kenjiArai | 3:fc1908567f3b | 248 | static void sta_mon(char *ptr) |
kenjiArai | 3:fc1908567f3b | 249 | { |
kenjiArai | 3:fc1908567f3b | 250 | static char str[512]; |
kenjiArai | 3:fc1908567f3b | 251 | time_t seconds_jst; |
kenjiArai | 3:fc1908567f3b | 252 | |
kenjiArai | 3:fc1908567f3b | 253 | pc.puts("Enterd FlashAir STA(Station) Mode -> connect to Host Device\r\n"); |
kenjiArai | 3:fc1908567f3b | 254 | pc.puts(hisdmsg1); |
kenjiArai | 3:fc1908567f3b | 255 | //Initialise card |
kenjiArai | 3:fc1908567f3b | 256 | FILE *fp = fopen("/sd/mbed.txt", "a"); |
kenjiArai | 3:fc1908567f3b | 257 | sprintf((char *)buffer, ".."); |
kenjiArai | 3:fc1908567f3b | 258 | fprintf(fp,(char *)buffer); |
kenjiArai | 3:fc1908567f3b | 259 | fclose(fp); |
kenjiArai | 3:fc1908567f3b | 260 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 261 | // Read the previous sequence ID. |
kenjiArai | 3:fc1908567f3b | 262 | if (sd.readExtMemory(1, 1, 0x420, 0x34, buffer)) { |
kenjiArai | 3:fc1908567f3b | 263 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 264 | if (buffer[0x20] == 0x01) { |
kenjiArai | 3:fc1908567f3b | 265 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 266 | nextSequenceId = get_u32(buffer + 0x24); |
kenjiArai | 3:fc1908567f3b | 267 | sd.waitResponse(nextSequenceId); |
kenjiArai | 3:fc1908567f3b | 268 | nextSequenceId++; |
kenjiArai | 3:fc1908567f3b | 269 | } else { |
kenjiArai | 3:fc1908567f3b | 270 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 271 | nextSequenceId = 0; |
kenjiArai | 3:fc1908567f3b | 272 | } |
kenjiArai | 3:fc1908567f3b | 273 | } else { |
kenjiArai | 3:fc1908567f3b | 274 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 275 | pc.puts("Failed to read status\r\n"); |
kenjiArai | 3:fc1908567f3b | 276 | nextSequenceId = 0; |
kenjiArai | 3:fc1908567f3b | 277 | } |
kenjiArai | 3:fc1908567f3b | 278 | for (uint32_t i=0; i==0; ) { |
kenjiArai | 3:fc1908567f3b | 279 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 280 | pc.puts("STA>"); |
kenjiArai | 3:fc1908567f3b | 281 | ptr = linebuf; |
kenjiArai | 3:fc1908567f3b | 282 | get_line(ptr, sizeof(linebuf)); |
kenjiArai | 3:fc1908567f3b | 283 | switch(*ptr++) { |
kenjiArai | 3:fc1908567f3b | 284 | case 's' : |
kenjiArai | 3:fc1908567f3b | 285 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 286 | if (iSDIO_scan(nextSequenceId) && |
kenjiArai | 3:fc1908567f3b | 287 | iSDIO_waitResponse(nextSequenceId) && |
kenjiArai | 3:fc1908567f3b | 288 | iSDIO_showScanResult()) { |
kenjiArai | 3:fc1908567f3b | 289 | pc.puts(msg_ok); |
kenjiArai | 3:fc1908567f3b | 290 | } else { |
kenjiArai | 3:fc1908567f3b | 291 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 292 | } |
kenjiArai | 3:fc1908567f3b | 293 | nextSequenceId++; |
kenjiArai | 3:fc1908567f3b | 294 | break; |
kenjiArai | 3:fc1908567f3b | 295 | case 'c' : |
kenjiArai | 3:fc1908567f3b | 296 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 297 | if (iSDIO_connect(nextSequenceId, ssid, networkKey) && |
kenjiArai | 3:fc1908567f3b | 298 | iSDIO_waitResponse(nextSequenceId)) { |
kenjiArai | 3:fc1908567f3b | 299 | pc.puts(msg_ok); |
kenjiArai | 3:fc1908567f3b | 300 | } else { |
kenjiArai | 3:fc1908567f3b | 301 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 302 | } |
kenjiArai | 3:fc1908567f3b | 303 | nextSequenceId++; |
kenjiArai | 3:fc1908567f3b | 304 | break; |
kenjiArai | 3:fc1908567f3b | 305 | case 'e' : |
kenjiArai | 3:fc1908567f3b | 306 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 307 | if (iSDIO_establish(nextSequenceId)) { |
kenjiArai | 3:fc1908567f3b | 308 | pc.puts(msg_ok); |
kenjiArai | 3:fc1908567f3b | 309 | } else { |
kenjiArai | 3:fc1908567f3b | 310 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 311 | } |
kenjiArai | 3:fc1908567f3b | 312 | break; |
kenjiArai | 3:fc1908567f3b | 313 | case 'd' : |
kenjiArai | 3:fc1908567f3b | 314 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 315 | if (iSDIO_disconnect(nextSequenceId)) { |
kenjiArai | 3:fc1908567f3b | 316 | pc.puts(msg_ok); |
kenjiArai | 3:fc1908567f3b | 317 | } else { |
kenjiArai | 3:fc1908567f3b | 318 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 319 | } |
kenjiArai | 3:fc1908567f3b | 320 | break; |
kenjiArai | 3:fc1908567f3b | 321 | case 't' : |
kenjiArai | 3:fc1908567f3b | 322 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 323 | seconds_jst = time(NULL); // Read Int. RTC time |
kenjiArai | 3:fc1908567f3b | 324 | strftime( |
kenjiArai | 3:fc1908567f3b | 325 | str, 40, |
kenjiArai | 3:fc1908567f3b | 326 | "%B %d,'%y, %H:%M:%S", |
kenjiArai | 3:fc1908567f3b | 327 | localtime(&seconds_jst)); |
kenjiArai | 3:fc1908567f3b | 328 | pc.printf("Time(JST): %s\r\n", str); |
kenjiArai | 3:fc1908567f3b | 329 | break; |
kenjiArai | 3:fc1908567f3b | 330 | case 'g' : |
kenjiArai | 3:fc1908567f3b | 331 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 332 | if (iSDIO_status() == false) { |
kenjiArai | 3:fc1908567f3b | 333 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 334 | } |
kenjiArai | 3:fc1908567f3b | 335 | break; |
kenjiArai | 3:fc1908567f3b | 336 | case 'q' : |
kenjiArai | 3:fc1908567f3b | 337 | i = 1; // return |
kenjiArai | 3:fc1908567f3b | 338 | break; |
kenjiArai | 3:fc1908567f3b | 339 | case '?' : |
kenjiArai | 3:fc1908567f3b | 340 | pc.puts(HelpMsg2); |
kenjiArai | 3:fc1908567f3b | 341 | break; |
kenjiArai | 3:fc1908567f3b | 342 | default: |
kenjiArai | 3:fc1908567f3b | 343 | DEBUG_LINE |
kenjiArai | 3:fc1908567f3b | 344 | pc.putc('?'); |
kenjiArai | 3:fc1908567f3b | 345 | crlf(); |
kenjiArai | 3:fc1908567f3b | 346 | } |
kenjiArai | 3:fc1908567f3b | 347 | } |
kenjiArai | 3:fc1908567f3b | 348 | pc.puts(rtnmsg); |
kenjiArai | 3:fc1908567f3b | 349 | } |
kenjiArai | 3:fc1908567f3b | 350 | |
kenjiArai | 3:fc1908567f3b | 351 | // Access Point Mode (Act as Host) |
kenjiArai | 3:fc1908567f3b | 352 | static void ap_mon(char *ptr) |
kenjiArai | 3:fc1908567f3b | 353 | { |
kenjiArai | 3:fc1908567f3b | 354 | pc.puts("Enterd FlashAir AP(Access Point) Mode -> Act as Host\r\n"); |
kenjiArai | 3:fc1908567f3b | 355 | pc.puts(hisdmsg1); |
kenjiArai | 3:fc1908567f3b | 356 | for (uint32_t i=0; i==0; ) { |
kenjiArai | 3:fc1908567f3b | 357 | pc.puts("AP>"); |
kenjiArai | 3:fc1908567f3b | 358 | ptr = linebuf; |
kenjiArai | 3:fc1908567f3b | 359 | get_line(ptr, sizeof(linebuf)); |
kenjiArai | 3:fc1908567f3b | 360 | switch(*ptr++) { |
kenjiArai | 3:fc1908567f3b | 361 | case 'e' : |
kenjiArai | 3:fc1908567f3b | 362 | if (iSDIO_establish(nextSequenceId)) { |
kenjiArai | 3:fc1908567f3b | 363 | pc.puts(msg_ok); |
kenjiArai | 3:fc1908567f3b | 364 | } else { |
kenjiArai | 3:fc1908567f3b | 365 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 366 | } |
kenjiArai | 3:fc1908567f3b | 367 | break; |
kenjiArai | 3:fc1908567f3b | 368 | case 'd' : |
kenjiArai | 3:fc1908567f3b | 369 | if (iSDIO_disconnect(nextSequenceId)) { |
kenjiArai | 3:fc1908567f3b | 370 | pc.puts(msg_ok); |
kenjiArai | 3:fc1908567f3b | 371 | } else { |
kenjiArai | 3:fc1908567f3b | 372 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 373 | } |
kenjiArai | 3:fc1908567f3b | 374 | break; |
kenjiArai | 3:fc1908567f3b | 375 | case 'g' : |
kenjiArai | 3:fc1908567f3b | 376 | if (iSDIO_status() == false) { |
kenjiArai | 3:fc1908567f3b | 377 | pc.puts(msg_ng); |
kenjiArai | 3:fc1908567f3b | 378 | } |
kenjiArai | 3:fc1908567f3b | 379 | break; |
kenjiArai | 3:fc1908567f3b | 380 | case 'q' : |
kenjiArai | 3:fc1908567f3b | 381 | i = 1; // return |
kenjiArai | 3:fc1908567f3b | 382 | break; |
kenjiArai | 3:fc1908567f3b | 383 | case '?' : |
kenjiArai | 3:fc1908567f3b | 384 | pc.puts(HelpMsg3); |
kenjiArai | 3:fc1908567f3b | 385 | break; |
kenjiArai | 3:fc1908567f3b | 386 | default: |
kenjiArai | 3:fc1908567f3b | 387 | pc.putc('?'); |
kenjiArai | 3:fc1908567f3b | 388 | crlf(); |
kenjiArai | 3:fc1908567f3b | 389 | } |
kenjiArai | 3:fc1908567f3b | 390 | } |
kenjiArai | 3:fc1908567f3b | 391 | pc.puts(rtnmsg); |
kenjiArai | 3:fc1908567f3b | 392 | } |
kenjiArai | 3:fc1908567f3b | 393 | |
kenjiArai | 3:fc1908567f3b | 394 | //------------------------------------------------------------------------------ |
kenjiArai | 3:fc1908567f3b | 395 | // iSDIO |
kenjiArai | 3:fc1908567f3b | 396 | void printByte(uint8_t value) |
kenjiArai | 3:fc1908567f3b | 397 | { |
kenjiArai | 3:fc1908567f3b | 398 | pc.printf("%x", value >> 4); |
kenjiArai | 3:fc1908567f3b | 399 | pc.printf("%x", value & 0xF); |
kenjiArai | 3:fc1908567f3b | 400 | } |
kenjiArai | 3:fc1908567f3b | 401 | |
kenjiArai | 3:fc1908567f3b | 402 | void printBytes(uint8_t* p, uint32_t len) |
kenjiArai | 3:fc1908567f3b | 403 | { |
kenjiArai | 3:fc1908567f3b | 404 | for (uint32_t i = 0; i < len; ++i) { |
kenjiArai | 3:fc1908567f3b | 405 | printByte(p[i]); |
kenjiArai | 3:fc1908567f3b | 406 | } |
kenjiArai | 3:fc1908567f3b | 407 | } |
kenjiArai | 3:fc1908567f3b | 408 | void printIPAddress(uint8_t* p) |
kenjiArai | 3:fc1908567f3b | 409 | { |
kenjiArai | 3:fc1908567f3b | 410 | pc.printf("%d", p[0]); |
kenjiArai | 3:fc1908567f3b | 411 | pc.putc('.'); |
kenjiArai | 3:fc1908567f3b | 412 | pc.printf("%d", p[1]); |
kenjiArai | 3:fc1908567f3b | 413 | pc.putc('.'); |
kenjiArai | 3:fc1908567f3b | 414 | pc.printf("%d", p[2]); |
kenjiArai | 3:fc1908567f3b | 415 | pc.putc('.'); |
kenjiArai | 3:fc1908567f3b | 416 | pc.printf("%d", p[3]); |
kenjiArai | 3:fc1908567f3b | 417 | } |
kenjiArai | 3:fc1908567f3b | 418 | |
kenjiArai | 3:fc1908567f3b | 419 | void printHex(uint8_t* p, uint32_t len) |
kenjiArai | 3:fc1908567f3b | 420 | { |
kenjiArai | 3:fc1908567f3b | 421 | uint32_t i = 0; |
kenjiArai | 3:fc1908567f3b | 422 | while (i < len) { |
kenjiArai | 3:fc1908567f3b | 423 | if ((i & 0xf) == 0) { |
kenjiArai | 3:fc1908567f3b | 424 | pc.puts("\r\n"); |
kenjiArai | 3:fc1908567f3b | 425 | printByte(i >> 4); |
kenjiArai | 3:fc1908567f3b | 426 | pc.puts(": "); |
kenjiArai | 3:fc1908567f3b | 427 | } |
kenjiArai | 3:fc1908567f3b | 428 | printByte(*p++); |
kenjiArai | 3:fc1908567f3b | 429 | i++; |
kenjiArai | 3:fc1908567f3b | 430 | } |
kenjiArai | 3:fc1908567f3b | 431 | pc.puts("\r\n"); |
kenjiArai | 3:fc1908567f3b | 432 | } |
kenjiArai | 3:fc1908567f3b | 433 | |
kenjiArai | 3:fc1908567f3b | 434 | uint8_t iSDIO_establish(uint32_t sequenceId) |
kenjiArai | 3:fc1908567f3b | 435 | { |
kenjiArai | 3:fc1908567f3b | 436 | pc.puts("Establish command: \r\n"); |
kenjiArai | 3:fc1908567f3b | 437 | memset(buffer, 0, 512); |
kenjiArai | 3:fc1908567f3b | 438 | uint8_t* p = buffer; |
kenjiArai | 3:fc1908567f3b | 439 | p = put_command_header(p, 1, 0); |
kenjiArai | 3:fc1908567f3b | 440 | p = put_command_info_header(p, 0x03, sequenceId, 3); |
kenjiArai | 3:fc1908567f3b | 441 | p = put_str_arg(p, (const uint8_t*)name_as_host); |
kenjiArai | 3:fc1908567f3b | 442 | p = put_str_arg(p, (const uint8_t*)password_ap); |
kenjiArai | 3:fc1908567f3b | 443 | p = put_u8_arg(p, 0x06); |
kenjiArai | 3:fc1908567f3b | 444 | put_command_header(buffer, 1, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 445 | printHex(buffer, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 446 | return sd.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; |
kenjiArai | 3:fc1908567f3b | 447 | } |
kenjiArai | 3:fc1908567f3b | 448 | |
kenjiArai | 3:fc1908567f3b | 449 | uint8_t iSDIO_connect( |
kenjiArai | 3:fc1908567f3b | 450 | uint32_t sequenceId, |
kenjiArai | 3:fc1908567f3b | 451 | const char* ssid, |
kenjiArai | 3:fc1908567f3b | 452 | const char* networkKey |
kenjiArai | 3:fc1908567f3b | 453 | ) |
kenjiArai | 3:fc1908567f3b | 454 | { |
kenjiArai | 3:fc1908567f3b | 455 | pc.puts("Connect command: \r\n"); |
kenjiArai | 3:fc1908567f3b | 456 | memset(buffer, 0, 512); |
kenjiArai | 3:fc1908567f3b | 457 | uint8_t* p = buffer; |
kenjiArai | 3:fc1908567f3b | 458 | p = put_command_header(p, 1, 0); |
kenjiArai | 3:fc1908567f3b | 459 | p = put_command_info_header(p, 0x02, sequenceId, 2); |
kenjiArai | 3:fc1908567f3b | 460 | p = put_str_arg(p, (const uint8_t*)ssid); |
kenjiArai | 3:fc1908567f3b | 461 | p = put_str_arg(p, (const uint8_t*)networkKey); |
kenjiArai | 3:fc1908567f3b | 462 | put_command_header(buffer, 1, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 463 | printHex(buffer, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 464 | return sd.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; |
kenjiArai | 3:fc1908567f3b | 465 | } |
kenjiArai | 3:fc1908567f3b | 466 | |
kenjiArai | 3:fc1908567f3b | 467 | uint8_t iSDIO_disconnect(uint32_t sequenceId) |
kenjiArai | 3:fc1908567f3b | 468 | { |
kenjiArai | 3:fc1908567f3b | 469 | pc.puts("Disconnect command: \r\n"); |
kenjiArai | 3:fc1908567f3b | 470 | memset(buffer, 0, 512); |
kenjiArai | 3:fc1908567f3b | 471 | uint8_t* p = buffer; |
kenjiArai | 3:fc1908567f3b | 472 | p = put_command_header(p, 1, 0); |
kenjiArai | 3:fc1908567f3b | 473 | p = put_command_info_header(p, 0x07, sequenceId, 0); |
kenjiArai | 3:fc1908567f3b | 474 | put_command_header(buffer, 1, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 475 | printHex(buffer, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 476 | return sd.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; |
kenjiArai | 3:fc1908567f3b | 477 | } |
kenjiArai | 3:fc1908567f3b | 478 | |
kenjiArai | 3:fc1908567f3b | 479 | uint8_t iSDIO_waitResponse(uint32_t sequenceId) |
kenjiArai | 3:fc1908567f3b | 480 | { |
kenjiArai | 3:fc1908567f3b | 481 | pc.puts("Waiting response "); |
kenjiArai | 3:fc1908567f3b | 482 | uint8_t prev = 0xFF; |
kenjiArai | 3:fc1908567f3b | 483 | for (int i = 0; i < 20; ++i) { |
kenjiArai | 3:fc1908567f3b | 484 | memset(buffer, 0, 0x14); |
kenjiArai | 3:fc1908567f3b | 485 | |
kenjiArai | 3:fc1908567f3b | 486 | // Read command response status. |
kenjiArai | 3:fc1908567f3b | 487 | if (!sd.readExtMemory(1, 1, 0x440, 0x14, buffer)) { |
kenjiArai | 3:fc1908567f3b | 488 | return false; |
kenjiArai | 3:fc1908567f3b | 489 | } |
kenjiArai | 3:fc1908567f3b | 490 | uint8_t resp = get_u8(buffer + 8); |
kenjiArai | 3:fc1908567f3b | 491 | if (sequenceId == get_u32(buffer + 4)) { |
kenjiArai | 3:fc1908567f3b | 492 | if (prev != resp) { |
kenjiArai | 3:fc1908567f3b | 493 | switch (resp) { |
kenjiArai | 3:fc1908567f3b | 494 | case 0x00: |
kenjiArai | 3:fc1908567f3b | 495 | pc.puts(" Initial"); |
kenjiArai | 3:fc1908567f3b | 496 | break; |
kenjiArai | 3:fc1908567f3b | 497 | case 0x01: |
kenjiArai | 3:fc1908567f3b | 498 | pc.puts(" Command Processing"); |
kenjiArai | 3:fc1908567f3b | 499 | break; |
kenjiArai | 3:fc1908567f3b | 500 | case 0x02: |
kenjiArai | 3:fc1908567f3b | 501 | pc.puts(" Command Rejected"); |
kenjiArai | 3:fc1908567f3b | 502 | return false; |
kenjiArai | 3:fc1908567f3b | 503 | case 0x03: |
kenjiArai | 3:fc1908567f3b | 504 | pc.puts(" Process Succeeded"); |
kenjiArai | 3:fc1908567f3b | 505 | return true; |
kenjiArai | 3:fc1908567f3b | 506 | case 0x04: |
kenjiArai | 3:fc1908567f3b | 507 | pc.puts(" Process Terminated"); |
kenjiArai | 3:fc1908567f3b | 508 | return false; |
kenjiArai | 3:fc1908567f3b | 509 | default: |
kenjiArai | 3:fc1908567f3b | 510 | pc.puts(" Process Failed "); |
kenjiArai | 3:fc1908567f3b | 511 | return false; |
kenjiArai | 3:fc1908567f3b | 512 | } |
kenjiArai | 3:fc1908567f3b | 513 | prev = resp; |
kenjiArai | 3:fc1908567f3b | 514 | } |
kenjiArai | 3:fc1908567f3b | 515 | } |
kenjiArai | 3:fc1908567f3b | 516 | pc.putc('.'); |
kenjiArai | 3:fc1908567f3b | 517 | wait(1.0); |
kenjiArai | 3:fc1908567f3b | 518 | } |
kenjiArai | 3:fc1908567f3b | 519 | return false; |
kenjiArai | 3:fc1908567f3b | 520 | } |
kenjiArai | 3:fc1908567f3b | 521 | |
kenjiArai | 3:fc1908567f3b | 522 | uint8_t iSDIO_scan(uint32_t sequenceId) |
kenjiArai | 3:fc1908567f3b | 523 | { |
kenjiArai | 3:fc1908567f3b | 524 | pc.puts("Scan: \r\n"); |
kenjiArai | 3:fc1908567f3b | 525 | memset(buffer, 0, 512); |
kenjiArai | 3:fc1908567f3b | 526 | uint8_t* p = buffer; |
kenjiArai | 3:fc1908567f3b | 527 | p = put_command_header(p, 1, 0); |
kenjiArai | 3:fc1908567f3b | 528 | p = put_command_info_header(p, 0x01, sequenceId, 0); |
kenjiArai | 3:fc1908567f3b | 529 | put_command_header(buffer, 1, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 530 | printHex(buffer, (p - buffer)); |
kenjiArai | 3:fc1908567f3b | 531 | return sd.writeExtDataPort(1, 1, 0x000, buffer) ? true : false; |
kenjiArai | 3:fc1908567f3b | 532 | } |
kenjiArai | 3:fc1908567f3b | 533 | |
kenjiArai | 3:fc1908567f3b | 534 | uint8_t iSDIO_showScanResult(void) |
kenjiArai | 3:fc1908567f3b | 535 | { |
kenjiArai | 3:fc1908567f3b | 536 | // Try to output some wifi info. |
kenjiArai | 3:fc1908567f3b | 537 | if (!sd.readExtDataPort(1, 1, 0x200, buffer)) { |
kenjiArai | 3:fc1908567f3b | 538 | pc.puts("Scan result: False\r\n"); |
kenjiArai | 3:fc1908567f3b | 539 | return false; |
kenjiArai | 3:fc1908567f3b | 540 | } |
kenjiArai | 3:fc1908567f3b | 541 | uint8_t num = get_u8(buffer + 24); |
kenjiArai | 3:fc1908567f3b | 542 | pc.puts("\r\nScan result:Number of APs: "); |
kenjiArai | 3:fc1908567f3b | 543 | pc.printf("%u\r\n",num); |
kenjiArai | 3:fc1908567f3b | 544 | uint8_t* p = buffer + 28; |
kenjiArai | 3:fc1908567f3b | 545 | for (int i = 0; i < num; i++) { |
kenjiArai | 3:fc1908567f3b | 546 | pc.putc(' '); |
kenjiArai | 3:fc1908567f3b | 547 | pc.printf("%s",(const char*)p); |
kenjiArai | 3:fc1908567f3b | 548 | pc.puts(", "); |
kenjiArai | 3:fc1908567f3b | 549 | printBytes(p + 32, 6); |
kenjiArai | 3:fc1908567f3b | 550 | pc.puts(", "); |
kenjiArai | 3:fc1908567f3b | 551 | pc.printf("%u",get_u8(p + 38)); |
kenjiArai | 3:fc1908567f3b | 552 | pc.puts(", "); |
kenjiArai | 3:fc1908567f3b | 553 | switch (get_u8(p + 39)) { |
kenjiArai | 3:fc1908567f3b | 554 | case 0 : |
kenjiArai | 3:fc1908567f3b | 555 | pc.puts("NoSec"); |
kenjiArai | 3:fc1908567f3b | 556 | break; |
kenjiArai | 3:fc1908567f3b | 557 | case 1 : |
kenjiArai | 3:fc1908567f3b | 558 | pc.puts("WEP"); |
kenjiArai | 3:fc1908567f3b | 559 | break; |
kenjiArai | 3:fc1908567f3b | 560 | case 2 : |
kenjiArai | 3:fc1908567f3b | 561 | pc.puts("WPA"); |
kenjiArai | 3:fc1908567f3b | 562 | break; |
kenjiArai | 3:fc1908567f3b | 563 | case 3 : |
kenjiArai | 3:fc1908567f3b | 564 | pc.puts("WPA2"); |
kenjiArai | 3:fc1908567f3b | 565 | break; |
kenjiArai | 3:fc1908567f3b | 566 | default : |
kenjiArai | 3:fc1908567f3b | 567 | pc.puts("error"); |
kenjiArai | 3:fc1908567f3b | 568 | break; |
kenjiArai | 3:fc1908567f3b | 569 | } |
kenjiArai | 3:fc1908567f3b | 570 | pc.puts("\r\n"); |
kenjiArai | 3:fc1908567f3b | 571 | p += 44; |
kenjiArai | 3:fc1908567f3b | 572 | } |
kenjiArai | 3:fc1908567f3b | 573 | return true; |
kenjiArai | 3:fc1908567f3b | 574 | } |
kenjiArai | 3:fc1908567f3b | 575 | |
kenjiArai | 3:fc1908567f3b | 576 | uint8_t iSDIO_status(void) |
kenjiArai | 3:fc1908567f3b | 577 | { |
kenjiArai | 3:fc1908567f3b | 578 | pc.puts("Read iSDIO Status Register\r\n"); |
kenjiArai | 3:fc1908567f3b | 579 | // Read iSDIO Status Register (E7 1.10 2.2.2.1) |
kenjiArai | 3:fc1908567f3b | 580 | memset(buffer, 0, 0x200); |
kenjiArai | 3:fc1908567f3b | 581 | if (!sd.readExtMemory(1, 1, 0x400, 0x200, buffer)) { |
kenjiArai | 3:fc1908567f3b | 582 | pc.puts("Cannot read Ext Memory\r\n"); |
kenjiArai | 3:fc1908567f3b | 583 | return false; |
kenjiArai | 3:fc1908567f3b | 584 | } |
kenjiArai | 3:fc1908567f3b | 585 | #if 1 |
kenjiArai | 3:fc1908567f3b | 586 | uint16_t j = 0; |
kenjiArai | 3:fc1908567f3b | 587 | pc.puts("HEX 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n 0 "); |
kenjiArai | 3:fc1908567f3b | 588 | for (int i = 0; i < 0x200; i++) { |
kenjiArai | 3:fc1908567f3b | 589 | pc.printf("%2x ", buffer[i]); |
kenjiArai | 3:fc1908567f3b | 590 | if ((i & 0xf) == 0xf) { |
kenjiArai | 3:fc1908567f3b | 591 | if (i == 0x1ff) { |
kenjiArai | 3:fc1908567f3b | 592 | pc.puts("\r\n"); |
kenjiArai | 3:fc1908567f3b | 593 | } else { |
kenjiArai | 3:fc1908567f3b | 594 | pc.printf("\r\n%2x ", ++j); |
kenjiArai | 3:fc1908567f3b | 595 | } |
kenjiArai | 3:fc1908567f3b | 596 | } |
kenjiArai | 3:fc1908567f3b | 597 | } |
kenjiArai | 3:fc1908567f3b | 598 | #endif |
kenjiArai | 3:fc1908567f3b | 599 | // Show values in the common status area. |
kenjiArai | 3:fc1908567f3b | 600 | pc.puts("\r\n == iSDIO Status Registers == "); |
kenjiArai | 3:fc1908567f3b | 601 | pc.puts("\r\n [0400h] Command Write Status: "); |
kenjiArai | 3:fc1908567f3b | 602 | if (buffer[0x000] & 0x01) pc.puts("CWU "); |
kenjiArai | 3:fc1908567f3b | 603 | if (buffer[0x000] & 0x02) pc.puts("CWA "); |
kenjiArai | 3:fc1908567f3b | 604 | pc.puts("\r\n [0420h] iSDIO Status: "); |
kenjiArai | 3:fc1908567f3b | 605 | if (buffer[0x020] & 0x01) pc.puts("CRU "); |
kenjiArai | 3:fc1908567f3b | 606 | if (buffer[0x020] & 0x02) pc.puts("ESU "); |
kenjiArai | 3:fc1908567f3b | 607 | if (buffer[0x020] & 0x04) pc.puts("MCU "); |
kenjiArai | 3:fc1908567f3b | 608 | if (buffer[0x020] & 0x08) pc.puts("ASU "); |
kenjiArai | 3:fc1908567f3b | 609 | pc.puts("\r\n [0422h] iSDIO Int Enable: "); |
kenjiArai | 3:fc1908567f3b | 610 | if (buffer[0x022] & 0x01) pc.puts("CRU_ENA "); |
kenjiArai | 3:fc1908567f3b | 611 | if (buffer[0x022] & 0x02) pc.puts("ESU_ENA "); |
kenjiArai | 3:fc1908567f3b | 612 | if (buffer[0x022] & 0x04) pc.puts("MCU_ENA "); |
kenjiArai | 3:fc1908567f3b | 613 | if (buffer[0x022] & 0x08) pc.puts("ASU_ENA "); |
kenjiArai | 3:fc1908567f3b | 614 | pc.puts("\r\n [0424h] Error Status: "); |
kenjiArai | 3:fc1908567f3b | 615 | if (buffer[0x024] & 0x01) pc.puts("CRE "); |
kenjiArai | 3:fc1908567f3b | 616 | if (buffer[0x024] & 0x02) pc.puts("CWE "); |
kenjiArai | 3:fc1908567f3b | 617 | if (buffer[0x024] & 0x04) pc.puts("RRE "); |
kenjiArai | 3:fc1908567f3b | 618 | if (buffer[0x024] & 0x08) pc.puts("APE "); |
kenjiArai | 3:fc1908567f3b | 619 | pc.puts("\r\n [0426h] Memory Status: "); |
kenjiArai | 3:fc1908567f3b | 620 | if (buffer[0x026] & 0x01) pc.puts("MEX "); |
kenjiArai | 3:fc1908567f3b | 621 | if (buffer[0x026] & 0x02) pc.puts("FAT "); |
kenjiArai | 3:fc1908567f3b | 622 | for (int i = 0; i < 8; ++i) { |
kenjiArai | 3:fc1908567f3b | 623 | uint8_t addr = 0x40 + i * 0x14; |
kenjiArai | 3:fc1908567f3b | 624 | pc.puts("\r\n [04"); |
kenjiArai | 3:fc1908567f3b | 625 | printByte(addr); |
kenjiArai | 3:fc1908567f3b | 626 | pc.puts("h] Command Response Status #"); |
kenjiArai | 3:fc1908567f3b | 627 | pc.printf("%d", i + 1); |
kenjiArai | 3:fc1908567f3b | 628 | pc.puts(": "); |
kenjiArai | 3:fc1908567f3b | 629 | if (buffer[addr] & 0x01) { |
kenjiArai | 3:fc1908567f3b | 630 | pc.puts("id = "); |
kenjiArai | 3:fc1908567f3b | 631 | pc.printf("%d", get_u16(buffer + addr + 2)); |
kenjiArai | 3:fc1908567f3b | 632 | pc.puts(", sequence id = "); |
kenjiArai | 3:fc1908567f3b | 633 | pc.printf("%d", get_u32(buffer + addr + 4)); |
kenjiArai | 3:fc1908567f3b | 634 | pc.puts(", status = "); |
kenjiArai | 3:fc1908567f3b | 635 | switch (buffer[addr + 8]) { |
kenjiArai | 3:fc1908567f3b | 636 | case 0x00: |
kenjiArai | 3:fc1908567f3b | 637 | pc.puts("Initial"); |
kenjiArai | 3:fc1908567f3b | 638 | break; |
kenjiArai | 3:fc1908567f3b | 639 | case 0x01: |
kenjiArai | 3:fc1908567f3b | 640 | pc.puts("Command Processing"); |
kenjiArai | 3:fc1908567f3b | 641 | break; |
kenjiArai | 3:fc1908567f3b | 642 | case 0x02: |
kenjiArai | 3:fc1908567f3b | 643 | pc.puts("Command Rejected"); |
kenjiArai | 3:fc1908567f3b | 644 | break; |
kenjiArai | 3:fc1908567f3b | 645 | case 0x03: |
kenjiArai | 3:fc1908567f3b | 646 | pc.puts("Process Succeeded"); |
kenjiArai | 3:fc1908567f3b | 647 | break; |
kenjiArai | 3:fc1908567f3b | 648 | case 0x04: |
kenjiArai | 3:fc1908567f3b | 649 | pc.puts("Process Terminated"); |
kenjiArai | 3:fc1908567f3b | 650 | break; |
kenjiArai | 3:fc1908567f3b | 651 | default: |
kenjiArai | 3:fc1908567f3b | 652 | pc.puts("Process Failed "); |
kenjiArai | 3:fc1908567f3b | 653 | pc.printf("0x%x", buffer[addr + 8]); |
kenjiArai | 3:fc1908567f3b | 654 | break; |
kenjiArai | 3:fc1908567f3b | 655 | } |
kenjiArai | 3:fc1908567f3b | 656 | } else { |
kenjiArai | 3:fc1908567f3b | 657 | pc.puts("Not registered"); |
kenjiArai | 3:fc1908567f3b | 658 | } |
kenjiArai | 3:fc1908567f3b | 659 | } |
kenjiArai | 3:fc1908567f3b | 660 | // Show values in the application status area. |
kenjiArai | 3:fc1908567f3b | 661 | pc.puts("\r\n == Wireless LAN Status Registers =="); |
kenjiArai | 3:fc1908567f3b | 662 | pc.puts("\r\n [0500h] DLNA Status: "); |
kenjiArai | 3:fc1908567f3b | 663 | if (buffer[0x100] & 0x01) pc.puts("ULR "); |
kenjiArai | 3:fc1908567f3b | 664 | if (buffer[0x100] & 0x02) pc.puts("DLU "); |
kenjiArai | 3:fc1908567f3b | 665 | if (buffer[0x100] & 0x04) pc.puts("CBR "); |
kenjiArai | 3:fc1908567f3b | 666 | if (buffer[0x100] & 0x08) pc.puts("CDR "); |
kenjiArai | 3:fc1908567f3b | 667 | pc.puts("\r\n [0501h] P2P Status: "); |
kenjiArai | 3:fc1908567f3b | 668 | if (buffer[0x101] & 0x01) pc.puts("ILU "); |
kenjiArai | 3:fc1908567f3b | 669 | if (buffer[0x101] & 0x02) pc.puts("FLU "); |
kenjiArai | 3:fc1908567f3b | 670 | pc.puts("\r\n [0502h] PTP Status: "); |
kenjiArai | 3:fc1908567f3b | 671 | if (buffer[0x102] & 0x01) pc.puts("RPO "); |
kenjiArai | 3:fc1908567f3b | 672 | if (buffer[0x102] & 0x02) pc.puts("RPD "); |
kenjiArai | 3:fc1908567f3b | 673 | if (buffer[0x102] & 0x04) pc.puts("RPC "); |
kenjiArai | 3:fc1908567f3b | 674 | if (buffer[0x102] & 0x08) pc.puts("CPI "); |
kenjiArai | 3:fc1908567f3b | 675 | if (buffer[0x102] & 0x10) pc.puts("DPI "); |
kenjiArai | 3:fc1908567f3b | 676 | if (buffer[0x102] & 0x20) pc.puts("CIL "); |
kenjiArai | 3:fc1908567f3b | 677 | pc.puts("\r\n [0504h] Application: "); |
kenjiArai | 3:fc1908567f3b | 678 | pc.printf("0x%x", buffer[0x104]); |
kenjiArai | 3:fc1908567f3b | 679 | pc.puts("\r\n [0506h] WLAN: "); |
kenjiArai | 3:fc1908567f3b | 680 | if ((buffer[0x106] & 0x01) == 0x00) pc.puts("No Scan, "); |
kenjiArai | 3:fc1908567f3b | 681 | if ((buffer[0x106] & 0x01) == 0x01) pc.puts("Scanning, "); |
kenjiArai | 3:fc1908567f3b | 682 | if ((buffer[0x106] & 0x06) == 0x00) pc.puts("No WPS, "); |
kenjiArai | 3:fc1908567f3b | 683 | if ((buffer[0x106] & 0x06) == 0x02) pc.puts("WPS with PIN, "); |
kenjiArai | 3:fc1908567f3b | 684 | if ((buffer[0x106] & 0x06) == 0x04) pc.puts("WPS with PBC, "); |
kenjiArai | 3:fc1908567f3b | 685 | if ((buffer[0x106] & 0x08) == 0x00) pc.puts("Group Client, "); |
kenjiArai | 3:fc1908567f3b | 686 | if ((buffer[0x106] & 0x08) == 0x08) pc.puts("Group Owner "); |
kenjiArai | 3:fc1908567f3b | 687 | if ((buffer[0x106] & 0x10) == 0x00) pc.puts("STA, "); |
kenjiArai | 3:fc1908567f3b | 688 | if ((buffer[0x106] & 0x10) == 0x10) pc.puts("AP, "); |
kenjiArai | 3:fc1908567f3b | 689 | if ((buffer[0x106] & 0x60) == 0x00) pc.puts("Initial, "); |
kenjiArai | 3:fc1908567f3b | 690 | if ((buffer[0x106] & 0x60) == 0x20) pc.puts("Infrastructure, "); |
kenjiArai | 3:fc1908567f3b | 691 | if ((buffer[0x106] & 0x60) == 0x40) pc.puts("Wi-Fi Direct, "); |
kenjiArai | 3:fc1908567f3b | 692 | if ((buffer[0x106] & 0x80) == 0x00) pc.puts("No Connection, "); |
kenjiArai | 3:fc1908567f3b | 693 | if ((buffer[0x106] & 0x80) == 0x80) pc.puts("Connected, "); |
kenjiArai | 3:fc1908567f3b | 694 | pc.puts("\r\n [0508h] SSID: "); |
kenjiArai | 3:fc1908567f3b | 695 | for (int i = 0; i < 32 && buffer[0x108 + i] != 0; ++i) { |
kenjiArai | 3:fc1908567f3b | 696 | pc.printf("%c", (char)buffer[0x108 + i]); |
kenjiArai | 3:fc1908567f3b | 697 | } |
kenjiArai | 3:fc1908567f3b | 698 | pc.puts("\r\n [0528h] Encryption Mode: "); |
kenjiArai | 3:fc1908567f3b | 699 | switch (buffer[0x128]) { |
kenjiArai | 3:fc1908567f3b | 700 | case 0 : |
kenjiArai | 3:fc1908567f3b | 701 | pc.puts("Open System and no encryption"); |
kenjiArai | 3:fc1908567f3b | 702 | break; |
kenjiArai | 3:fc1908567f3b | 703 | case 1 : |
kenjiArai | 3:fc1908567f3b | 704 | pc.puts("Open System and WEP"); |
kenjiArai | 3:fc1908567f3b | 705 | break; |
kenjiArai | 3:fc1908567f3b | 706 | case 2 : |
kenjiArai | 3:fc1908567f3b | 707 | pc.puts("Shared Key and WEP"); |
kenjiArai | 3:fc1908567f3b | 708 | break; |
kenjiArai | 3:fc1908567f3b | 709 | case 3 : |
kenjiArai | 3:fc1908567f3b | 710 | pc.puts("WPA-PSK and TKIP"); |
kenjiArai | 3:fc1908567f3b | 711 | break; |
kenjiArai | 3:fc1908567f3b | 712 | case 4 : |
kenjiArai | 3:fc1908567f3b | 713 | pc.puts("WPA-PSK and AES"); |
kenjiArai | 3:fc1908567f3b | 714 | break; |
kenjiArai | 3:fc1908567f3b | 715 | case 5 : |
kenjiArai | 3:fc1908567f3b | 716 | pc.puts("WPA2-PSK and TKIP"); |
kenjiArai | 3:fc1908567f3b | 717 | break; |
kenjiArai | 3:fc1908567f3b | 718 | case 6 : |
kenjiArai | 3:fc1908567f3b | 719 | pc.puts("WPA2-PSK and AES"); |
kenjiArai | 3:fc1908567f3b | 720 | break; |
kenjiArai | 3:fc1908567f3b | 721 | default: |
kenjiArai | 3:fc1908567f3b | 722 | pc.puts("Unknown"); |
kenjiArai | 3:fc1908567f3b | 723 | } |
kenjiArai | 3:fc1908567f3b | 724 | pc.puts("\r\n [0529h] Signal Strength: "); |
kenjiArai | 3:fc1908567f3b | 725 | pc.printf("%d", buffer[0x129]); |
kenjiArai | 3:fc1908567f3b | 726 | pc.puts("\r\n [052Ah] Channel: "); |
kenjiArai | 3:fc1908567f3b | 727 | if (buffer[0x12A] == 0) pc.puts("No connection"); |
kenjiArai | 3:fc1908567f3b | 728 | else pc.printf("%d", buffer[0x12A]); |
kenjiArai | 3:fc1908567f3b | 729 | pc.puts("\r\n [0530h] MAC Address: "); |
kenjiArai | 3:fc1908567f3b | 730 | printBytes(buffer + 0x130, 6); |
kenjiArai | 3:fc1908567f3b | 731 | pc.puts("\r\n [0540h] ID: "); |
kenjiArai | 3:fc1908567f3b | 732 | for (int i = 0; i < 16 && buffer[0x140 + i] != 0; ++i) { |
kenjiArai | 3:fc1908567f3b | 733 | pc.printf("%c", (char)buffer[0x140 + i]); |
kenjiArai | 3:fc1908567f3b | 734 | } |
kenjiArai | 3:fc1908567f3b | 735 | pc.puts("\r\n [0550h] IP Address: "); |
kenjiArai | 3:fc1908567f3b | 736 | printIPAddress(buffer + 0x150); |
kenjiArai | 3:fc1908567f3b | 737 | pc.puts("\r\n [0554h] Subnet Mask: "); |
kenjiArai | 3:fc1908567f3b | 738 | printIPAddress(buffer + 0x154); |
kenjiArai | 3:fc1908567f3b | 739 | pc.puts("\r\n [0558h] Default Gateway: "); |
kenjiArai | 3:fc1908567f3b | 740 | printIPAddress(buffer + 0x158); |
kenjiArai | 3:fc1908567f3b | 741 | pc.puts("\r\n [055Ch] Preferred DNS Server: "); |
kenjiArai | 3:fc1908567f3b | 742 | printIPAddress(buffer + 0x15C); |
kenjiArai | 3:fc1908567f3b | 743 | pc.puts("\r\n [0560h] Alternate DNS Server: "); |
kenjiArai | 3:fc1908567f3b | 744 | printIPAddress(buffer + 0x160); |
kenjiArai | 3:fc1908567f3b | 745 | pc.puts("\r\n [0564h] Proxy Server: "); |
kenjiArai | 3:fc1908567f3b | 746 | if ((buffer[0x164] & 0x01) == 0x00) pc.puts("Disabled"); |
kenjiArai | 3:fc1908567f3b | 747 | if ((buffer[0x164] & 0x01) == 0x01) pc.puts("Enabled"); |
kenjiArai | 3:fc1908567f3b | 748 | pc.puts("\r\n [0570h] Date: "); |
kenjiArai | 3:fc1908567f3b | 749 | pc.printf("%d", buffer[0x171] + 1980); |
kenjiArai | 3:fc1908567f3b | 750 | pc.putc('-'); |
kenjiArai | 3:fc1908567f3b | 751 | pc.printf("%d", buffer[0x170] >> 4); |
kenjiArai | 3:fc1908567f3b | 752 | pc.putc('-'); |
kenjiArai | 3:fc1908567f3b | 753 | pc.printf("%d", buffer[0x170] & 0xF); |
kenjiArai | 3:fc1908567f3b | 754 | pc.puts("\r\n [0572h] Time: "); |
kenjiArai | 3:fc1908567f3b | 755 | pc.printf("%d", buffer[0x173] >> 3); |
kenjiArai | 3:fc1908567f3b | 756 | pc.putc(':'); |
kenjiArai | 3:fc1908567f3b | 757 | pc.printf("%d", buffer[0x172] << 3 | buffer[0x170] >> 3); |
kenjiArai | 3:fc1908567f3b | 758 | pc.putc(':'); |
kenjiArai | 3:fc1908567f3b | 759 | pc.printf("%d", (buffer[0x172] & 0x1F) * 2); |
kenjiArai | 3:fc1908567f3b | 760 | pc.puts("\r\n [0574h] HTTP Status: "); |
kenjiArai | 3:fc1908567f3b | 761 | pc.printf("%d", buffer[0x174] & 0xEF); |
kenjiArai | 3:fc1908567f3b | 762 | if ((buffer[0x174] & 0x80) == 0x00) pc.puts(" (No Processing)"); |
kenjiArai | 3:fc1908567f3b | 763 | if ((buffer[0x174] & 0x80) == 0x80) pc.puts(" (Processing)"); |
kenjiArai | 3:fc1908567f3b | 764 | pc.puts("\r\n [0575h] Power Save Management: "); |
kenjiArai | 3:fc1908567f3b | 765 | if ((buffer[0x175] & 0x01) == 0x00) pc.puts("Power Save Mode Off"); |
kenjiArai | 3:fc1908567f3b | 766 | if ((buffer[0x175] & 0x01) == 0x01) pc.puts("Power Save Mode On"); |
kenjiArai | 3:fc1908567f3b | 767 | pc.puts("\r\n [0576h] File System Management: "); |
kenjiArai | 3:fc1908567f3b | 768 | if ((buffer[0x176] & 0x01) == 0x00) { |
kenjiArai | 3:fc1908567f3b | 769 | pc.puts("FS Information may be modified"); |
kenjiArai | 3:fc1908567f3b | 770 | } |
kenjiArai | 3:fc1908567f3b | 771 | if ((buffer[0x176] & 0x01) == 0x01) { |
kenjiArai | 3:fc1908567f3b | 772 | pc.puts("FS Information shall not be modified"); |
kenjiArai | 3:fc1908567f3b | 773 | } |
kenjiArai | 3:fc1908567f3b | 774 | pc.puts("\r\n"); |
kenjiArai | 3:fc1908567f3b | 775 | return true; |
kenjiArai | 3:fc1908567f3b | 776 | } |
kenjiArai | 3:fc1908567f3b | 777 | |
kenjiArai | 3:fc1908567f3b | 778 | //------------------------------------------------------------------------------ |
kenjiArai | 3:fc1908567f3b | 779 | // General monitor functions |
kenjiArai | 3:fc1908567f3b | 780 | static void v_next(char *ptr) |
kenjiArai | 3:fc1908567f3b | 781 | { |
kenjiArai | 3:fc1908567f3b | 782 | switch (*ptr++) { |
kenjiArai | 3:fc1908567f3b | 783 | case 'o' : |
kenjiArai | 3:fc1908567f3b | 784 | if (*ptr == 'l') { |
kenjiArai | 3:fc1908567f3b | 785 | *ptr = 's'; |
kenjiArai | 3:fc1908567f3b | 786 | file_inf(ptr); // fs [<path>] - Show volume status |
kenjiArai | 3:fc1908567f3b | 787 | } |
kenjiArai | 3:fc1908567f3b | 788 | break; |
kenjiArai | 3:fc1908567f3b | 789 | default: |
kenjiArai | 3:fc1908567f3b | 790 | pc.puts( "?\r\n" ); |
kenjiArai | 3:fc1908567f3b | 791 | } |
kenjiArai | 3:fc1908567f3b | 792 | } |
kenjiArai | 3:fc1908567f3b | 793 | |
kenjiArai | 3:fc1908567f3b | 794 | static void d_next(char *ptr) |
kenjiArai | 3:fc1908567f3b | 795 | { |
kenjiArai | 3:fc1908567f3b | 796 | switch (*ptr++) { |
kenjiArai | 3:fc1908567f3b | 797 | case 'i' : |
kenjiArai | 3:fc1908567f3b | 798 | if (*ptr == 'r') { |
kenjiArai | 3:fc1908567f3b | 799 | *ptr = 'l'; |
kenjiArai | 3:fc1908567f3b | 800 | file_inf(ptr); // fl [<path>] - Directory listing |
kenjiArai | 3:fc1908567f3b | 801 | } |
kenjiArai | 3:fc1908567f3b | 802 | break; |
kenjiArai | 3:fc1908567f3b | 803 | default: |
kenjiArai | 3:fc1908567f3b | 804 | pc.puts( "?\r\n" ); |
kenjiArai | 3:fc1908567f3b | 805 | } |
kenjiArai | 3:fc1908567f3b | 806 | } |
kenjiArai | 3:fc1908567f3b | 807 | |
kenjiArai | 3:fc1908567f3b | 808 | static void c_next(char *ptr) |
kenjiArai | 3:fc1908567f3b | 809 | { |
kenjiArai | 3:fc1908567f3b | 810 | switch (*ptr++) { |
kenjiArai | 3:fc1908567f3b | 811 | case 'o' : |
kenjiArai | 3:fc1908567f3b | 812 | if ((*ptr == 'p') && (*(ptr + 1) == 'y')) { |
kenjiArai | 3:fc1908567f3b | 813 | ptr++; |
kenjiArai | 3:fc1908567f3b | 814 | *ptr = 'x'; |
kenjiArai | 3:fc1908567f3b | 815 | file_inf(ptr); // fx <src_name> <dst_name> - Copy file |
kenjiArai | 3:fc1908567f3b | 816 | } |
kenjiArai | 3:fc1908567f3b | 817 | break; |
kenjiArai | 3:fc1908567f3b | 818 | case 'd' : |
kenjiArai | 3:fc1908567f3b | 819 | *ptr = 'g'; |
kenjiArai | 3:fc1908567f3b | 820 | file_inf(ptr); // fg Change directory |
kenjiArai | 3:fc1908567f3b | 821 | break; |
kenjiArai | 3:fc1908567f3b | 822 | default: |
kenjiArai | 3:fc1908567f3b | 823 | pc.puts( "?\r\n" ); |
kenjiArai | 3:fc1908567f3b | 824 | } |
kenjiArai | 3:fc1908567f3b | 825 | } |
kenjiArai | 3:fc1908567f3b | 826 | |
kenjiArai | 3:fc1908567f3b | 827 | static void m_next(char *ptr) |
kenjiArai | 3:fc1908567f3b | 828 | { |
kenjiArai | 3:fc1908567f3b | 829 | switch (*ptr++) { |
kenjiArai | 3:fc1908567f3b | 830 | case 'k' : |
kenjiArai | 3:fc1908567f3b | 831 | if ((*ptr == 'd') && (*(ptr + 1) == 'i') && (*(ptr + 2) == 'r')) { |
kenjiArai | 3:fc1908567f3b | 832 | ptr += 2; |
kenjiArai | 3:fc1908567f3b | 833 | *ptr = 'k'; |
kenjiArai | 3:fc1908567f3b | 834 | file_inf(ptr); // fk <name> - Create a directory |
kenjiArai | 3:fc1908567f3b | 835 | } |
kenjiArai | 3:fc1908567f3b | 836 | break; |
kenjiArai | 3:fc1908567f3b | 837 | default: |
kenjiArai | 3:fc1908567f3b | 838 | pc.puts("?\r\n"); |
kenjiArai | 3:fc1908567f3b | 839 | } |
kenjiArai | 3:fc1908567f3b | 840 | } |
kenjiArai | 3:fc1908567f3b | 841 | |
kenjiArai | 3:fc1908567f3b | 842 | static void r_next(char *ptr) |
kenjiArai | 3:fc1908567f3b | 843 | { |
kenjiArai | 3:fc1908567f3b | 844 | switch (*ptr++) { |
kenjiArai | 3:fc1908567f3b | 845 | case 'e' : |
kenjiArai | 3:fc1908567f3b | 846 | // fn <old_name> <new_name> - Change file/dir name |
kenjiArai | 3:fc1908567f3b | 847 | if (*ptr == 'n') { |
kenjiArai | 3:fc1908567f3b | 848 | file_inf(ptr); |
kenjiArai | 3:fc1908567f3b | 849 | } |
kenjiArai | 3:fc1908567f3b | 850 | break; |
kenjiArai | 3:fc1908567f3b | 851 | default: |
kenjiArai | 3:fc1908567f3b | 852 | pc.puts("?\r\n"); |
kenjiArai | 3:fc1908567f3b | 853 | } |
kenjiArai | 3:fc1908567f3b | 854 | } |
kenjiArai | 3:fc1908567f3b | 855 | |
kenjiArai | 3:fc1908567f3b | 856 | static void t_next(char *ptr) |
kenjiArai | 3:fc1908567f3b | 857 | { |
kenjiArai | 3:fc1908567f3b | 858 | switch (*ptr++) { |
kenjiArai | 3:fc1908567f3b | 859 | case ' ' : |
kenjiArai | 3:fc1908567f3b | 860 | case 0x0d: |
kenjiArai | 3:fc1908567f3b | 861 | chk_and_set_time(ptr); |
kenjiArai | 3:fc1908567f3b | 862 | case 'y' : |
kenjiArai | 3:fc1908567f3b | 863 | if ((*ptr == 'p') && (*(ptr + 1) == 'e')) { |
kenjiArai | 3:fc1908567f3b | 864 | ptr++; |
kenjiArai | 3:fc1908567f3b | 865 | *ptr = '&'; |
kenjiArai | 3:fc1908567f3b | 866 | file_inf(ptr); |
kenjiArai | 3:fc1908567f3b | 867 | } |
kenjiArai | 3:fc1908567f3b | 868 | break; |
kenjiArai | 3:fc1908567f3b | 869 | default: |
kenjiArai | 3:fc1908567f3b | 870 | pc.puts("?\r\n"); |
kenjiArai | 3:fc1908567f3b | 871 | } |
kenjiArai | 3:fc1908567f3b | 872 | } |
kenjiArai | 3:fc1908567f3b | 873 | |
kenjiArai | 3:fc1908567f3b | 874 | static FRESULT scan_files( |
kenjiArai | 3:fc1908567f3b | 875 | char* path /* Pointer to the path name working buffer */ |
kenjiArai | 3:fc1908567f3b | 876 | ) |
kenjiArai | 3:fc1908567f3b | 877 | { |
kenjiArai | 3:fc1908567f3b | 878 | FATFS_DIR dirs; |
kenjiArai | 3:fc1908567f3b | 879 | FRESULT res; |
kenjiArai | 3:fc1908567f3b | 880 | BYTE i; |
kenjiArai | 3:fc1908567f3b | 881 | char *fn; |
kenjiArai | 3:fc1908567f3b | 882 | |
kenjiArai | 3:fc1908567f3b | 883 | if ((res = f_opendir(&dirs, path)) == FR_OK) { |
kenjiArai | 3:fc1908567f3b | 884 | i = strlen(path); |
kenjiArai | 3:fc1908567f3b | 885 | pc.printf("path: %s, n=%u\r\n", path, i); |
kenjiArai | 3:fc1908567f3b | 886 | while (((res = f_readdir(&dirs, &Finfo)) == FR_OK) && Finfo.fname[0]) { |
kenjiArai | 3:fc1908567f3b | 887 | if (_FS_RPATH && Finfo.fname[0] == '.') { |
kenjiArai | 3:fc1908567f3b | 888 | continue; |
kenjiArai | 3:fc1908567f3b | 889 | } |
kenjiArai | 3:fc1908567f3b | 890 | fn = *Finfo.lfname ? Finfo.lfname : Finfo.fname; |
kenjiArai | 3:fc1908567f3b | 891 | if (Finfo.fattrib & AM_DIR) { |
kenjiArai | 3:fc1908567f3b | 892 | AccDirs++; |
kenjiArai | 3:fc1908567f3b | 893 | *(path+i) = '/'; |
kenjiArai | 3:fc1908567f3b | 894 | strcpy(path+i+1, fn); |
kenjiArai | 3:fc1908567f3b | 895 | res = scan_files(path); |
kenjiArai | 3:fc1908567f3b | 896 | *(path+i) = '\0'; |
kenjiArai | 3:fc1908567f3b | 897 | if (res != FR_OK) break; |
kenjiArai | 3:fc1908567f3b | 898 | } else { |
kenjiArai | 3:fc1908567f3b | 899 | pc.printf("%s/%s\r\n", path, fn); |
kenjiArai | 3:fc1908567f3b | 900 | AccFiles++; |
kenjiArai | 3:fc1908567f3b | 901 | AccSize += Finfo.fsize; |
kenjiArai | 3:fc1908567f3b | 902 | } |
kenjiArai | 3:fc1908567f3b | 903 | } |
kenjiArai | 3:fc1908567f3b | 904 | } |
kenjiArai | 3:fc1908567f3b | 905 | return res; |
kenjiArai | 3:fc1908567f3b | 906 | } |
kenjiArai | 3:fc1908567f3b | 907 | |
kenjiArai | 3:fc1908567f3b | 908 | static void put_rc(FRESULT rc) |
kenjiArai | 3:fc1908567f3b | 909 | { |
kenjiArai | 3:fc1908567f3b | 910 | const char *str = |
kenjiArai | 3:fc1908567f3b | 911 | "OK\0" "DISK_ERR\0" "INT_ERR\0" "NOT_READY\0" "NO_FILE\0" "NO_PATH\0" |
kenjiArai | 3:fc1908567f3b | 912 | "INVALID_NAME\0" "DENIED\0" "EXIST\0" "INVALID_OBJECT\0" |
kenjiArai | 3:fc1908567f3b | 913 | "WRITE_PROTECTED\0" "INVALID_DRIVE\0" "NOT_ENABLED\0" |
kenjiArai | 3:fc1908567f3b | 914 | "NO_FILE_SYSTEM\0" "MKFS_ABORTED\0" "TIMEOUT\0" |
kenjiArai | 3:fc1908567f3b | 915 | "LOCKED\0" "NOT_ENOUGH_CORE\0" "TOO_MANY_OPEN_FILES\0"; |
kenjiArai | 3:fc1908567f3b | 916 | for (uint32_t i = 0; i != rc && *str; i++ ) { |
kenjiArai | 3:fc1908567f3b | 917 | while ( *str++ ) { ;} |
kenjiArai | 3:fc1908567f3b | 918 | } |
kenjiArai | 3:fc1908567f3b | 919 | pc.printf( "rc=%u FR_%s\r\n", (UINT)rc, str ); |
kenjiArai | 3:fc1908567f3b | 920 | } |
kenjiArai | 3:fc1908567f3b | 921 | |
kenjiArai | 3:fc1908567f3b | 922 | static void file_inf(char *ptr) |
kenjiArai | 3:fc1908567f3b | 923 | { |
kenjiArai | 3:fc1908567f3b | 924 | DDWORD pf; |
kenjiArai | 3:fc1908567f3b | 925 | long p1, p2, p3; |
kenjiArai | 3:fc1908567f3b | 926 | CHAR *ptr2; |
kenjiArai | 3:fc1908567f3b | 927 | BYTE f_res; |
kenjiArai | 3:fc1908567f3b | 928 | UINT s1, s2, cnt, blen = sizeof Buff; |
kenjiArai | 3:fc1908567f3b | 929 | FATFS *fs; |
kenjiArai | 3:fc1908567f3b | 930 | static const BYTE ft[] = {0, 12, 16, 32}; |
kenjiArai | 3:fc1908567f3b | 931 | BYTE res; |
kenjiArai | 3:fc1908567f3b | 932 | DWORD ofs = 0; |
kenjiArai | 3:fc1908567f3b | 933 | uint32_t tim; |
kenjiArai | 3:fc1908567f3b | 934 | |
kenjiArai | 3:fc1908567f3b | 935 | switch (*ptr++) { |
kenjiArai | 3:fc1908567f3b | 936 | case '&' : |
kenjiArai | 3:fc1908567f3b | 937 | DEBUG_LINE; |
kenjiArai | 3:fc1908567f3b | 938 | while (*ptr == ' ') ptr++; |
kenjiArai | 3:fc1908567f3b | 939 | /* Open a file */ |
kenjiArai | 3:fc1908567f3b | 940 | f_res = f_open(&File1, ptr, FA_READ); |
kenjiArai | 3:fc1908567f3b | 941 | if ( f_res ) { |
kenjiArai | 3:fc1908567f3b | 942 | put_rc((FRESULT)f_res); |
kenjiArai | 3:fc1908567f3b | 943 | break; |
kenjiArai | 3:fc1908567f3b | 944 | } |
kenjiArai | 3:fc1908567f3b | 945 | DEBUG_LINE; |
kenjiArai | 3:fc1908567f3b | 946 | /* Read all lines and display it */ |
kenjiArai | 3:fc1908567f3b | 947 | while(true) { |
kenjiArai | 3:fc1908567f3b | 948 | f_res = f_read(&File1, (TCHAR*)Buff, blen, &cnt); |
kenjiArai | 3:fc1908567f3b | 949 | if ( f_res ) { |
kenjiArai | 3:fc1908567f3b | 950 | put_rc((FRESULT)f_res); |
kenjiArai | 3:fc1908567f3b | 951 | break; |
kenjiArai | 3:fc1908567f3b | 952 | } |
kenjiArai | 3:fc1908567f3b | 953 | for (s1 = 0; s1 < cnt; s1++) { |
kenjiArai | 3:fc1908567f3b | 954 | pc.putc(Buff[s1]); |
kenjiArai | 3:fc1908567f3b | 955 | } |
kenjiArai | 3:fc1908567f3b | 956 | if (cnt != blen) { |
kenjiArai | 3:fc1908567f3b | 957 | break; |
kenjiArai | 3:fc1908567f3b | 958 | } |
kenjiArai | 3:fc1908567f3b | 959 | } |
kenjiArai | 3:fc1908567f3b | 960 | DEBUG_LINE; |
kenjiArai | 3:fc1908567f3b | 961 | /* Close the file */ |
kenjiArai | 3:fc1908567f3b | 962 | f_close(&File1); |
kenjiArai | 3:fc1908567f3b | 963 | break; |
kenjiArai | 3:fc1908567f3b | 964 | case 'i' : /* fi [<opt>]- Initialize logical drive */ |
kenjiArai | 3:fc1908567f3b | 965 | if ( !xatoi(&ptr, &p1) ) { |
kenjiArai | 3:fc1908567f3b | 966 | break; |
kenjiArai | 3:fc1908567f3b | 967 | } |
kenjiArai | 3:fc1908567f3b | 968 | if (!xatoi(&ptr, &p2)) p2 = 0; |
kenjiArai | 3:fc1908567f3b | 969 | put_rc(f_mount(&Fatfs[p1], (const TCHAR*)p1, 0)); |
kenjiArai | 3:fc1908567f3b | 970 | break; |
kenjiArai | 3:fc1908567f3b | 971 | case 's' : /* fs [<path>] - Show volume status */ |
kenjiArai | 3:fc1908567f3b | 972 | f_res = f_getfree( ptr, (DWORD*)&p2, &fs ); |
kenjiArai | 3:fc1908567f3b | 973 | if ( f_res ) { |
kenjiArai | 3:fc1908567f3b | 974 | put_rc((FRESULT)f_res); |
kenjiArai | 3:fc1908567f3b | 975 | break; |
kenjiArai | 3:fc1908567f3b | 976 | } |
kenjiArai | 3:fc1908567f3b | 977 | pc.printf |
kenjiArai | 3:fc1908567f3b | 978 | ( |
kenjiArai | 3:fc1908567f3b | 979 | "\rFAT type = FAT%u\r\nBytes/Cluster" |
kenjiArai | 3:fc1908567f3b | 980 | " = %lu\r\nNumber of FATs = %u\r\n" |
kenjiArai | 3:fc1908567f3b | 981 | "Root DIR entries = %u\r\n" |
kenjiArai | 3:fc1908567f3b | 982 | "Sectors/FAT = %lu\r\n" |
kenjiArai | 3:fc1908567f3b | 983 | "Number of clusters = %lu\r\n" |
kenjiArai | 3:fc1908567f3b | 984 | "FAT start (lba) = %lu\r\n" |
kenjiArai | 3:fc1908567f3b | 985 | "DIR start (lba,clustor) = %lu\r\n" |
kenjiArai | 3:fc1908567f3b | 986 | "Data start (lba) = %lu\r\n", |
kenjiArai | 3:fc1908567f3b | 987 | ft[fs->fs_type & 3], (DWORD)fs->csize * 512, fs->n_fats, |
kenjiArai | 3:fc1908567f3b | 988 | fs->n_rootdir, fs->fsize, (DWORD)fs->n_fatent - 2, |
kenjiArai | 3:fc1908567f3b | 989 | fs->fatbase, fs->dirbase, fs->database |
kenjiArai | 3:fc1908567f3b | 990 | ); |
kenjiArai | 3:fc1908567f3b | 991 | AccSize = AccFiles = AccDirs = 0; |
kenjiArai | 3:fc1908567f3b | 992 | break; |
kenjiArai | 3:fc1908567f3b | 993 | case 'l' : /* fl [<path>] - Directory listing */ |
kenjiArai | 3:fc1908567f3b | 994 | while ( *ptr == ' ' ) { |
kenjiArai | 3:fc1908567f3b | 995 | ptr++; |
kenjiArai | 3:fc1908567f3b | 996 | } |
kenjiArai | 3:fc1908567f3b | 997 | f_res = f_opendir( Dirx, ptr ); |
kenjiArai | 3:fc1908567f3b | 998 | if ( f_res ) { |
kenjiArai | 3:fc1908567f3b | 999 | put_rc( (FRESULT)f_res ); |
kenjiArai | 3:fc1908567f3b | 1000 | break; |
kenjiArai | 3:fc1908567f3b | 1001 | } |
kenjiArai | 3:fc1908567f3b | 1002 | pf = 0; |
kenjiArai | 3:fc1908567f3b | 1003 | p1 = s1 = s2 = 0; |
kenjiArai | 3:fc1908567f3b | 1004 | for(;;) { |
kenjiArai | 3:fc1908567f3b | 1005 | f_res = f_readdir( Dirx, &Finfo ); |
kenjiArai | 3:fc1908567f3b | 1006 | if ( (f_res != FR_OK) || !Finfo.fname[0] ) { |
kenjiArai | 3:fc1908567f3b | 1007 | break; |
kenjiArai | 3:fc1908567f3b | 1008 | } |
kenjiArai | 3:fc1908567f3b | 1009 | if ( Finfo.fattrib & AM_DIR ) { |
kenjiArai | 3:fc1908567f3b | 1010 | s2++; |
kenjiArai | 3:fc1908567f3b | 1011 | } else { |
kenjiArai | 3:fc1908567f3b | 1012 | s1++; |
kenjiArai | 3:fc1908567f3b | 1013 | pf += Finfo.fsize; |
kenjiArai | 3:fc1908567f3b | 1014 | } |
kenjiArai | 3:fc1908567f3b | 1015 | pc.printf( |
kenjiArai | 3:fc1908567f3b | 1016 | "%c%c%c%c%c %u/%02u/%02u %02u:%02u %9lu %-12s %s\r\n", |
kenjiArai | 3:fc1908567f3b | 1017 | (Finfo.fattrib & AM_DIR) ? 'D' : '-', |
kenjiArai | 3:fc1908567f3b | 1018 | (Finfo.fattrib & AM_RDO) ? 'R' : '-', |
kenjiArai | 3:fc1908567f3b | 1019 | (Finfo.fattrib & AM_HID) ? 'H' : '-', |
kenjiArai | 3:fc1908567f3b | 1020 | (Finfo.fattrib & AM_SYS) ? 'S' : '-', |
kenjiArai | 3:fc1908567f3b | 1021 | (Finfo.fattrib & AM_ARC) ? 'A' : '-', |
kenjiArai | 3:fc1908567f3b | 1022 | (Finfo.fdate >> 9) + 1980, (Finfo.fdate >> 5) & 15, |
kenjiArai | 3:fc1908567f3b | 1023 | Finfo.fdate & 31, |
kenjiArai | 3:fc1908567f3b | 1024 | (Finfo.ftime >> 11), (Finfo.ftime >> 5) & 63, |
kenjiArai | 3:fc1908567f3b | 1025 | Finfo.fsize, Finfo.fname, |
kenjiArai | 3:fc1908567f3b | 1026 | Lfname ); |
kenjiArai | 3:fc1908567f3b | 1027 | } |
kenjiArai | 3:fc1908567f3b | 1028 | p1 = pf%100; |
kenjiArai | 3:fc1908567f3b | 1029 | pc.printf( |
kenjiArai | 3:fc1908567f3b | 1030 | "%4u file(s),%10lu%02lu bytes total\r\n%4u Dir(s)", |
kenjiArai | 3:fc1908567f3b | 1031 | s1, (DWORD)(pf/100), p1, s2 |
kenjiArai | 3:fc1908567f3b | 1032 | ); |
kenjiArai | 3:fc1908567f3b | 1033 | if ( f_getfree(ptr, (DWORD *)&p1, &fs) == FR_OK ) { |
kenjiArai | 3:fc1908567f3b | 1034 | pc.printf( ", %10lu bytes free\r\n", p1 * fs->csize * 512 ); |
kenjiArai | 3:fc1908567f3b | 1035 | } else { |
kenjiArai | 3:fc1908567f3b | 1036 | put_rc( (FRESULT)f_res ); |
kenjiArai | 3:fc1908567f3b | 1037 | } |
kenjiArai | 3:fc1908567f3b | 1038 | break; |
kenjiArai | 3:fc1908567f3b | 1039 | case 'o' : /* fo <mode> <file> - Open a file */ |
kenjiArai | 3:fc1908567f3b | 1040 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 3:fc1908567f3b | 1041 | while (*ptr == ' ') ptr++; |
kenjiArai | 3:fc1908567f3b | 1042 | put_rc(f_open(&File1, ptr, (BYTE)p1)); |
kenjiArai | 3:fc1908567f3b | 1043 | break; |
kenjiArai | 3:fc1908567f3b | 1044 | case 'c' : /* fc - Close a file */ |
kenjiArai | 3:fc1908567f3b | 1045 | put_rc(f_close(&File1)); |
kenjiArai | 3:fc1908567f3b | 1046 | break; |
kenjiArai | 3:fc1908567f3b | 1047 | case 'e' : /* fe - Seek file pointer */ |
kenjiArai | 3:fc1908567f3b | 1048 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 3:fc1908567f3b | 1049 | res = f_lseek(&File1, p1); |
kenjiArai | 3:fc1908567f3b | 1050 | put_rc((FRESULT)res); |
kenjiArai | 3:fc1908567f3b | 1051 | if (res == FR_OK) |
kenjiArai | 3:fc1908567f3b | 1052 | pc.printf("fptr=%lu(0x%lX)\r\n", File1.fptr, File1.fptr); |
kenjiArai | 3:fc1908567f3b | 1053 | break; |
kenjiArai | 3:fc1908567f3b | 1054 | case 'd' : /* fd <len> - read and dump file from current fp */ |
kenjiArai | 3:fc1908567f3b | 1055 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 3:fc1908567f3b | 1056 | ofs = File1.fptr; |
kenjiArai | 3:fc1908567f3b | 1057 | while (p1) { |
kenjiArai | 3:fc1908567f3b | 1058 | if ((UINT)p1 >= 16) { |
kenjiArai | 3:fc1908567f3b | 1059 | cnt = 16; |
kenjiArai | 3:fc1908567f3b | 1060 | p1 -= 16; |
kenjiArai | 3:fc1908567f3b | 1061 | } else { |
kenjiArai | 3:fc1908567f3b | 1062 | cnt = p1; |
kenjiArai | 3:fc1908567f3b | 1063 | p1 = 0; |
kenjiArai | 3:fc1908567f3b | 1064 | } |
kenjiArai | 3:fc1908567f3b | 1065 | res = f_read(&File1, Buff, cnt, &cnt); |
kenjiArai | 3:fc1908567f3b | 1066 | if (res != FR_OK) { |
kenjiArai | 3:fc1908567f3b | 1067 | put_rc((FRESULT)res); |
kenjiArai | 3:fc1908567f3b | 1068 | break; |
kenjiArai | 3:fc1908567f3b | 1069 | } |
kenjiArai | 3:fc1908567f3b | 1070 | if (!cnt) break; |
kenjiArai | 3:fc1908567f3b | 1071 | put_dump(Buff, ofs, cnt, DW_CHAR); |
kenjiArai | 3:fc1908567f3b | 1072 | ofs += 16; |
kenjiArai | 3:fc1908567f3b | 1073 | } |
kenjiArai | 3:fc1908567f3b | 1074 | break; |
kenjiArai | 3:fc1908567f3b | 1075 | case 'r' : /* fr <len> - read file */ |
kenjiArai | 3:fc1908567f3b | 1076 | if (!xatoi(&ptr, &p1)) break; |
kenjiArai | 3:fc1908567f3b | 1077 | p2 = 0; |
kenjiArai | 3:fc1908567f3b | 1078 | t.reset(); |
kenjiArai | 3:fc1908567f3b | 1079 | t.start(); |
kenjiArai | 3:fc1908567f3b | 1080 | while (p1) { |
kenjiArai | 3:fc1908567f3b | 1081 | if ((UINT)p1 >= blen) { |
kenjiArai | 3:fc1908567f3b | 1082 | cnt = blen; |
kenjiArai | 3:fc1908567f3b | 1083 | p1 -= blen; |
kenjiArai | 3:fc1908567f3b | 1084 | } else { |
kenjiArai | 3:fc1908567f3b | 1085 | cnt = p1; |
kenjiArai | 3:fc1908567f3b | 1086 | p1 = 0; |
kenjiArai | 3:fc1908567f3b | 1087 | } |
kenjiArai | 3:fc1908567f3b | 1088 | res = f_read(&File1, Buff, cnt, &s2); |
kenjiArai | 3:fc1908567f3b | 1089 | if (res != FR_OK) { |
kenjiArai | 3:fc1908567f3b | 1090 | put_rc((FRESULT)res); |
kenjiArai | 3:fc1908567f3b | 1091 | break; |
kenjiArai | 3:fc1908567f3b | 1092 | } |
kenjiArai | 3:fc1908567f3b | 1093 | p2 += s2; |
kenjiArai | 3:fc1908567f3b | 1094 | if (cnt != s2) break; |
kenjiArai | 3:fc1908567f3b | 1095 | } |
kenjiArai | 3:fc1908567f3b | 1096 | tim = t.read_ms(); |
kenjiArai | 3:fc1908567f3b | 1097 | pc.printf("%lu bytes read with %lu kB/sec.\r\n", |
kenjiArai | 3:fc1908567f3b | 1098 | p2, tim ? (p2 / tim) : 0); |
kenjiArai | 3:fc1908567f3b | 1099 | break; |
kenjiArai | 3:fc1908567f3b | 1100 | case 'w' : /* fw <len> <val> - write file */ |
kenjiArai | 3:fc1908567f3b | 1101 | if (!xatoi(&ptr, &p1) || !xatoi(&ptr, &p2)) break; |
kenjiArai | 3:fc1908567f3b | 1102 | memset(Buff, (BYTE)p2, blen); |
kenjiArai | 3:fc1908567f3b | 1103 | p2 = 0; |
kenjiArai | 3:fc1908567f3b | 1104 | t.reset(); |
kenjiArai | 3:fc1908567f3b | 1105 | t.start(); |
kenjiArai | 3:fc1908567f3b | 1106 | while (p1) { |
kenjiArai | 3:fc1908567f3b | 1107 | if ((UINT)p1 >= blen) { |
kenjiArai | 3:fc1908567f3b | 1108 | cnt = blen; |
kenjiArai | 3:fc1908567f3b | 1109 | p1 -= blen; |
kenjiArai | 3:fc1908567f3b | 1110 | } else { |
kenjiArai | 3:fc1908567f3b | 1111 | cnt = p1; |
kenjiArai | 3:fc1908567f3b | 1112 | p1 = 0; |
kenjiArai | 3:fc1908567f3b | 1113 | } |
kenjiArai | 3:fc1908567f3b | 1114 | res = f_write(&File1, Buff, cnt, &s2); |
kenjiArai | 3:fc1908567f3b | 1115 | if (res != FR_OK) { |
kenjiArai | 3:fc1908567f3b | 1116 | put_rc((FRESULT)res); |
kenjiArai | 3:fc1908567f3b | 1117 | break; |
kenjiArai | 3:fc1908567f3b | 1118 | } |
kenjiArai | 3:fc1908567f3b | 1119 | p2 += s2; |
kenjiArai | 3:fc1908567f3b | 1120 | if (cnt != s2) break; |
kenjiArai | 3:fc1908567f3b | 1121 | } |
kenjiArai | 3:fc1908567f3b | 1122 | tim = t.read_ms(); |
kenjiArai | 3:fc1908567f3b | 1123 | pc.printf("%lu bytes written with %lu kB/sec.\r\n", |
kenjiArai | 3:fc1908567f3b | 1124 | p2, tim ? (p2 / tim) : 0); |
kenjiArai | 3:fc1908567f3b | 1125 | break; |
kenjiArai | 3:fc1908567f3b | 1126 | case 'n' : /* fn <org.name> <new.name> - Change name of an object */ |
kenjiArai | 3:fc1908567f3b | 1127 | while (*ptr == ' ') ptr++; |
kenjiArai | 3:fc1908567f3b | 1128 | ptr2 = strchr(ptr, ' '); |
kenjiArai | 3:fc1908567f3b | 1129 | if (!ptr2) break; |
kenjiArai | 3:fc1908567f3b | 1130 | *ptr2++ = 0; |
kenjiArai | 3:fc1908567f3b | 1131 | while (*ptr2 == ' ') ptr2++; |
kenjiArai | 3:fc1908567f3b | 1132 | put_rc(f_rename(ptr, ptr2)); |
kenjiArai | 3:fc1908567f3b | 1133 | break; |
kenjiArai | 3:fc1908567f3b | 1134 | case 'u' : /* fu <name> - Unlink an object */ |
kenjiArai | 3:fc1908567f3b | 1135 | while (*ptr == ' ') ptr++; |
kenjiArai | 3:fc1908567f3b | 1136 | put_rc(f_unlink(ptr)); |
kenjiArai | 3:fc1908567f3b | 1137 | break; |
kenjiArai | 3:fc1908567f3b | 1138 | case 'v' : /* fv - Truncate file */ |
kenjiArai | 3:fc1908567f3b | 1139 | put_rc(f_truncate(&File1)); |
kenjiArai | 3:fc1908567f3b | 1140 | break; |
kenjiArai | 3:fc1908567f3b | 1141 | case 'k' : /* fk <name> - Create a directory */ |
kenjiArai | 3:fc1908567f3b | 1142 | while (*ptr == ' ') ptr++; |
kenjiArai | 3:fc1908567f3b | 1143 | put_rc(f_mkdir(ptr)); |
kenjiArai | 3:fc1908567f3b | 1144 | break; |
kenjiArai | 3:fc1908567f3b | 1145 | #if FILCPY_NOTUSE == 0 |
kenjiArai | 3:fc1908567f3b | 1146 | case 'x' : /* fx <src_name> <dst_name> - Copy file */ |
kenjiArai | 3:fc1908567f3b | 1147 | while ( *ptr == ' ' ) { |
kenjiArai | 3:fc1908567f3b | 1148 | ptr++; |
kenjiArai | 3:fc1908567f3b | 1149 | } |
kenjiArai | 3:fc1908567f3b | 1150 | ptr2 = strchr( ptr, ' ' ); |
kenjiArai | 3:fc1908567f3b | 1151 | if ( !ptr2 ) { |
kenjiArai | 3:fc1908567f3b | 1152 | break; |
kenjiArai | 3:fc1908567f3b | 1153 | } |
kenjiArai | 3:fc1908567f3b | 1154 | *ptr2++ = 0; |
kenjiArai | 3:fc1908567f3b | 1155 | while ( *ptr2 == ' ' ) { |
kenjiArai | 3:fc1908567f3b | 1156 | ptr2++; |
kenjiArai | 3:fc1908567f3b | 1157 | } |
kenjiArai | 3:fc1908567f3b | 1158 | f_res = f_open( &File1, ptr, FA_OPEN_EXISTING | FA_READ ); |
kenjiArai | 3:fc1908567f3b | 1159 | pc.printf("Opening %s \r\n", ptr); |
kenjiArai | 3:fc1908567f3b | 1160 | if ( f_res ) { |
kenjiArai | 3:fc1908567f3b | 1161 | put_rc( (FRESULT)f_res ); |
kenjiArai | 3:fc1908567f3b | 1162 | break; |
kenjiArai | 3:fc1908567f3b | 1163 | } |
kenjiArai | 3:fc1908567f3b | 1164 | f_res = f_open( &File2, ptr2, FA_CREATE_ALWAYS | FA_WRITE ); |
kenjiArai | 3:fc1908567f3b | 1165 | pc.printf(" Creating %s \r\n", ptr2); |
kenjiArai | 3:fc1908567f3b | 1166 | if ( f_res ) { |
kenjiArai | 3:fc1908567f3b | 1167 | put_rc( (FRESULT)f_res ); |
kenjiArai | 3:fc1908567f3b | 1168 | f_close( &File1 ); |
kenjiArai | 3:fc1908567f3b | 1169 | break; |
kenjiArai | 3:fc1908567f3b | 1170 | } |
kenjiArai | 3:fc1908567f3b | 1171 | pc.printf("Copying file..."); |
kenjiArai | 3:fc1908567f3b | 1172 | p1 = 0; |
kenjiArai | 3:fc1908567f3b | 1173 | for ( ;; ) { |
kenjiArai | 3:fc1908567f3b | 1174 | f_res = f_read( &File1, Buff, blen, &s1 ); |
kenjiArai | 3:fc1908567f3b | 1175 | if ( f_res || s1 == 0 ) { |
kenjiArai | 3:fc1908567f3b | 1176 | break; /* error or eof */ |
kenjiArai | 3:fc1908567f3b | 1177 | } |
kenjiArai | 3:fc1908567f3b | 1178 | f_res = f_write( &File2, Buff, s1, &s2 ); |
kenjiArai | 3:fc1908567f3b | 1179 | p1 += s2; |
kenjiArai | 3:fc1908567f3b | 1180 | if ( f_res || s2 < s1 ) { |
kenjiArai | 3:fc1908567f3b | 1181 | break; /* error or disk full */ |
kenjiArai | 3:fc1908567f3b | 1182 | } |
kenjiArai | 3:fc1908567f3b | 1183 | } |
kenjiArai | 3:fc1908567f3b | 1184 | f_close( &File1 ); |
kenjiArai | 3:fc1908567f3b | 1185 | f_close( &File2 ); |
kenjiArai | 3:fc1908567f3b | 1186 | crlf(); |
kenjiArai | 3:fc1908567f3b | 1187 | break; |
kenjiArai | 3:fc1908567f3b | 1188 | #endif |
kenjiArai | 3:fc1908567f3b | 1189 | #if _FS_RPATH |
kenjiArai | 3:fc1908567f3b | 1190 | case 'g' : /* fg <path> - Change current directory */ |
kenjiArai | 3:fc1908567f3b | 1191 | while (*ptr == ' ') ptr++; |
kenjiArai | 3:fc1908567f3b | 1192 | put_rc(f_chdir(ptr)); |
kenjiArai | 3:fc1908567f3b | 1193 | break; |
kenjiArai | 3:fc1908567f3b | 1194 | #endif |
kenjiArai | 3:fc1908567f3b | 1195 | } |
kenjiArai | 3:fc1908567f3b | 1196 | } |
kenjiArai | 3:fc1908567f3b | 1197 | |
kenjiArai | 3:fc1908567f3b | 1198 | void put_dump ( |
kenjiArai | 3:fc1908567f3b | 1199 | void* buff, /* Pointer to the array to be dumped */ |
kenjiArai | 3:fc1908567f3b | 1200 | unsigned long addr, /* Heading address value */ |
kenjiArai | 3:fc1908567f3b | 1201 | int len, /* Number of items to be dumped */ |
kenjiArai | 3:fc1908567f3b | 1202 | int width /* Size of the items (DW_CHAR, DW_SHORT, DW_LONG) */ |
kenjiArai | 3:fc1908567f3b | 1203 | ) |
kenjiArai | 3:fc1908567f3b | 1204 | { |
kenjiArai | 3:fc1908567f3b | 1205 | int i; |
kenjiArai | 3:fc1908567f3b | 1206 | unsigned char *bp; |
kenjiArai | 3:fc1908567f3b | 1207 | unsigned short *sp; |
kenjiArai | 3:fc1908567f3b | 1208 | unsigned long *lp; |
kenjiArai | 3:fc1908567f3b | 1209 | |
kenjiArai | 3:fc1908567f3b | 1210 | pc.printf( "%08lx ", addr ); /* address */ |
kenjiArai | 3:fc1908567f3b | 1211 | switch ( width ) { |
kenjiArai | 3:fc1908567f3b | 1212 | case DW_CHAR: |
kenjiArai | 3:fc1908567f3b | 1213 | bp = (unsigned char *)buff; |
kenjiArai | 3:fc1908567f3b | 1214 | for ( i = 0; i < len; i++ ) { /* Hexdecimal dump */ |
kenjiArai | 3:fc1908567f3b | 1215 | pc.printf( " %02x", bp[i] ); |
kenjiArai | 3:fc1908567f3b | 1216 | } |
kenjiArai | 3:fc1908567f3b | 1217 | pc.putc(' '); |
kenjiArai | 3:fc1908567f3b | 1218 | for ( i = 0; i < len; i++ ) { /* ASCII dump */ |
kenjiArai | 3:fc1908567f3b | 1219 | pc.putc( (bp[i] >= ' ' && bp[i] <= '~') ? bp[i] : '.' ); |
kenjiArai | 3:fc1908567f3b | 1220 | } |
kenjiArai | 3:fc1908567f3b | 1221 | break; |
kenjiArai | 3:fc1908567f3b | 1222 | case DW_SHORT: |
kenjiArai | 3:fc1908567f3b | 1223 | sp = (unsigned short *)buff; |
kenjiArai | 3:fc1908567f3b | 1224 | do { /* Hexdecimal dump */ |
kenjiArai | 3:fc1908567f3b | 1225 | pc.printf( " %04x", *sp++ ); |
kenjiArai | 3:fc1908567f3b | 1226 | } while ( --len ); |
kenjiArai | 3:fc1908567f3b | 1227 | break; |
kenjiArai | 3:fc1908567f3b | 1228 | case DW_LONG: |
kenjiArai | 3:fc1908567f3b | 1229 | lp = (unsigned long *)buff; |
kenjiArai | 3:fc1908567f3b | 1230 | do { /* Hexdecimal dump */ |
kenjiArai | 3:fc1908567f3b | 1231 | pc.printf( " %08lx", *lp++ ); |
kenjiArai | 3:fc1908567f3b | 1232 | } while ( --len ); |
kenjiArai | 3:fc1908567f3b | 1233 | break; |
kenjiArai | 3:fc1908567f3b | 1234 | } |
kenjiArai | 3:fc1908567f3b | 1235 | pc.puts( "\r\n" ); |
kenjiArai | 3:fc1908567f3b | 1236 | } |
kenjiArai | 3:fc1908567f3b | 1237 | |
kenjiArai | 3:fc1908567f3b | 1238 | // RTC related subroutines |
kenjiArai | 3:fc1908567f3b | 1239 | void chk_and_set_time(char *ptr) |
kenjiArai | 3:fc1908567f3b | 1240 | { |
kenjiArai | 3:fc1908567f3b | 1241 | char buf[64]; |
kenjiArai | 3:fc1908567f3b | 1242 | |
kenjiArai | 3:fc1908567f3b | 1243 | long p1; |
kenjiArai | 3:fc1908567f3b | 1244 | struct tm t; |
kenjiArai | 3:fc1908567f3b | 1245 | time_t seconds; |
kenjiArai | 3:fc1908567f3b | 1246 | |
kenjiArai | 3:fc1908567f3b | 1247 | if (xatoi(&ptr, &p1)) { |
kenjiArai | 3:fc1908567f3b | 1248 | t.tm_year = (uint8_t)p1 + 100; |
kenjiArai | 3:fc1908567f3b | 1249 | pc.printf("Year:%ld ",p1); |
kenjiArai | 3:fc1908567f3b | 1250 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:fc1908567f3b | 1251 | t.tm_mon = (uint8_t)p1 - 1; |
kenjiArai | 3:fc1908567f3b | 1252 | pc.printf("Month:%ld ",p1); |
kenjiArai | 3:fc1908567f3b | 1253 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:fc1908567f3b | 1254 | t.tm_mday = (uint8_t)p1; |
kenjiArai | 3:fc1908567f3b | 1255 | pc.printf("Day:%ld ",p1); |
kenjiArai | 3:fc1908567f3b | 1256 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:fc1908567f3b | 1257 | t.tm_hour = (uint8_t)p1; |
kenjiArai | 3:fc1908567f3b | 1258 | pc.printf("Hour:%ld ",p1); |
kenjiArai | 3:fc1908567f3b | 1259 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:fc1908567f3b | 1260 | t.tm_min = (uint8_t)p1; |
kenjiArai | 3:fc1908567f3b | 1261 | pc.printf("Min:%ld ",p1); |
kenjiArai | 3:fc1908567f3b | 1262 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:fc1908567f3b | 1263 | t.tm_sec = (uint8_t)p1; |
kenjiArai | 3:fc1908567f3b | 1264 | pc.printf("Sec: %ld \r\n",p1); |
kenjiArai | 3:fc1908567f3b | 1265 | seconds = mktime(&t); |
kenjiArai | 3:fc1908567f3b | 1266 | set_time(seconds); |
kenjiArai | 3:fc1908567f3b | 1267 | } else { |
kenjiArai | 3:fc1908567f3b | 1268 | seconds = time(NULL); |
kenjiArai | 3:fc1908567f3b | 1269 | } |
kenjiArai | 3:fc1908567f3b | 1270 | strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); |
kenjiArai | 3:fc1908567f3b | 1271 | pc.printf("[Time] %s", buf); |
kenjiArai | 3:fc1908567f3b | 1272 | } |
kenjiArai | 3:fc1908567f3b | 1273 | |
kenjiArai | 3:fc1908567f3b | 1274 | // Get key input data |
kenjiArai | 3:fc1908567f3b | 1275 | void get_line (char *buff, int len) |
kenjiArai | 3:fc1908567f3b | 1276 | { |
kenjiArai | 3:fc1908567f3b | 1277 | char c; |
kenjiArai | 3:fc1908567f3b | 1278 | int idx = 0; |
kenjiArai | 3:fc1908567f3b | 1279 | |
kenjiArai | 3:fc1908567f3b | 1280 | for (;;) { |
kenjiArai | 3:fc1908567f3b | 1281 | c = pc.getc(); |
kenjiArai | 3:fc1908567f3b | 1282 | // Added by Kenji Arai / JH1PJL May 9th, 2010 |
kenjiArai | 3:fc1908567f3b | 1283 | if (c == '\r') { |
kenjiArai | 3:fc1908567f3b | 1284 | buff[idx++] = c; |
kenjiArai | 3:fc1908567f3b | 1285 | break; |
kenjiArai | 3:fc1908567f3b | 1286 | } |
kenjiArai | 3:fc1908567f3b | 1287 | if ((c == '\b') && idx) { |
kenjiArai | 3:fc1908567f3b | 1288 | idx--; |
kenjiArai | 3:fc1908567f3b | 1289 | pc.putc(c); |
kenjiArai | 3:fc1908567f3b | 1290 | pc.putc(' '); |
kenjiArai | 3:fc1908567f3b | 1291 | pc.putc(c); |
kenjiArai | 3:fc1908567f3b | 1292 | } |
kenjiArai | 3:fc1908567f3b | 1293 | if (((uint8_t)c >= ' ') && (idx < len - 1)) { |
kenjiArai | 3:fc1908567f3b | 1294 | buff[idx++] = c; |
kenjiArai | 3:fc1908567f3b | 1295 | pc.putc(c); |
kenjiArai | 3:fc1908567f3b | 1296 | } |
kenjiArai | 3:fc1908567f3b | 1297 | } |
kenjiArai | 3:fc1908567f3b | 1298 | buff[idx] = 0; |
kenjiArai | 3:fc1908567f3b | 1299 | pc.puts("\r\n"); |
kenjiArai | 3:fc1908567f3b | 1300 | } |
kenjiArai | 3:fc1908567f3b | 1301 | |
kenjiArai | 3:fc1908567f3b | 1302 | /* Outpur LF & CR */ |
kenjiArai | 3:fc1908567f3b | 1303 | void crlf( void ) |
kenjiArai | 3:fc1908567f3b | 1304 | { |
kenjiArai | 3:fc1908567f3b | 1305 | pc.printf( "\r\n" ); |
kenjiArai | 3:fc1908567f3b | 1306 | } |
kenjiArai | 3:fc1908567f3b | 1307 | |
kenjiArai | 3:fc1908567f3b | 1308 | /* Check key input */ |
kenjiArai | 3:fc1908567f3b | 1309 | unsigned int check_hit_key (void) |
kenjiArai | 3:fc1908567f3b | 1310 | { |
kenjiArai | 3:fc1908567f3b | 1311 | return ( pc.readable() ); |
kenjiArai | 3:fc1908567f3b | 1312 | } |
kenjiArai | 3:fc1908567f3b | 1313 | |
kenjiArai | 3:fc1908567f3b | 1314 | //------------------------------------------------------------------------------ |
kenjiArai | 3:fc1908567f3b | 1315 | // Get a value of the string |
kenjiArai | 3:fc1908567f3b | 1316 | //------------------------------------------------------------------------------ |
kenjiArai | 3:fc1908567f3b | 1317 | /* "123 -5 0x3ff 0b1111 0377 w " |
kenjiArai | 3:fc1908567f3b | 1318 | ^ 1st call returns 123 and next ptr |
kenjiArai | 3:fc1908567f3b | 1319 | ^ 2nd call returns -5 and next ptr |
kenjiArai | 3:fc1908567f3b | 1320 | ^ 3rd call returns 1023 and next ptr |
kenjiArai | 3:fc1908567f3b | 1321 | ^ 4th call returns 15 and next ptr |
kenjiArai | 3:fc1908567f3b | 1322 | ^ 5th call returns 255 and next ptr |
kenjiArai | 3:fc1908567f3b | 1323 | ^ 6th call fails and returns 0 |
kenjiArai | 3:fc1908567f3b | 1324 | */ |
kenjiArai | 3:fc1908567f3b | 1325 | int xatoi ( /* 0:Failed, 1:Successful */ |
kenjiArai | 3:fc1908567f3b | 1326 | char **str, /* Pointer to pointer to the string */ |
kenjiArai | 3:fc1908567f3b | 1327 | long *res /* Pointer to the valiable to store the value */ |
kenjiArai | 3:fc1908567f3b | 1328 | ) |
kenjiArai | 3:fc1908567f3b | 1329 | { |
kenjiArai | 3:fc1908567f3b | 1330 | unsigned long val; |
kenjiArai | 3:fc1908567f3b | 1331 | unsigned char c, r, s = 0; |
kenjiArai | 3:fc1908567f3b | 1332 | |
kenjiArai | 3:fc1908567f3b | 1333 | *res = 0; |
kenjiArai | 3:fc1908567f3b | 1334 | while ( (c = **str) == ' ' ) { |
kenjiArai | 3:fc1908567f3b | 1335 | (*str)++; /* Skip leading spaces */ |
kenjiArai | 3:fc1908567f3b | 1336 | } |
kenjiArai | 3:fc1908567f3b | 1337 | if ( c == '-' ) { /* negative? */ |
kenjiArai | 3:fc1908567f3b | 1338 | s = 1; |
kenjiArai | 3:fc1908567f3b | 1339 | c = *(++(*str)); |
kenjiArai | 3:fc1908567f3b | 1340 | } |
kenjiArai | 3:fc1908567f3b | 1341 | if ( c == '0' ) { |
kenjiArai | 3:fc1908567f3b | 1342 | c = *(++(*str)); |
kenjiArai | 3:fc1908567f3b | 1343 | switch (c) { |
kenjiArai | 3:fc1908567f3b | 1344 | case 'x': /* hexdecimal */ |
kenjiArai | 3:fc1908567f3b | 1345 | r = 16; |
kenjiArai | 3:fc1908567f3b | 1346 | c = *(++(*str)); |
kenjiArai | 3:fc1908567f3b | 1347 | break; |
kenjiArai | 3:fc1908567f3b | 1348 | case 'b': /* binary */ |
kenjiArai | 3:fc1908567f3b | 1349 | r = 2; |
kenjiArai | 3:fc1908567f3b | 1350 | c = *(++(*str)); |
kenjiArai | 3:fc1908567f3b | 1351 | break; |
kenjiArai | 3:fc1908567f3b | 1352 | default: |
kenjiArai | 3:fc1908567f3b | 1353 | if ( c <= ' ' ) return 1; /* single zero */ |
kenjiArai | 3:fc1908567f3b | 1354 | if ( c < '0' || c > '9' ) return 0; /* invalid char */ |
kenjiArai | 3:fc1908567f3b | 1355 | r = 8; /* octal */ |
kenjiArai | 3:fc1908567f3b | 1356 | } |
kenjiArai | 3:fc1908567f3b | 1357 | } else { |
kenjiArai | 3:fc1908567f3b | 1358 | if ( c < '0' || c > '9' ) return 0; /* EOL or invalid char */ |
kenjiArai | 3:fc1908567f3b | 1359 | r = 10; /* decimal */ |
kenjiArai | 3:fc1908567f3b | 1360 | } |
kenjiArai | 3:fc1908567f3b | 1361 | val = 0; |
kenjiArai | 3:fc1908567f3b | 1362 | while ( c > ' ' ) { |
kenjiArai | 3:fc1908567f3b | 1363 | if ( c >= 'a' ) { |
kenjiArai | 3:fc1908567f3b | 1364 | c -= 0x20; |
kenjiArai | 3:fc1908567f3b | 1365 | } |
kenjiArai | 3:fc1908567f3b | 1366 | c -= '0'; |
kenjiArai | 3:fc1908567f3b | 1367 | if ( c >= 17 ) { |
kenjiArai | 3:fc1908567f3b | 1368 | c -= 7; |
kenjiArai | 3:fc1908567f3b | 1369 | if ( c <= 9 ) { |
kenjiArai | 3:fc1908567f3b | 1370 | return 0; /* invalid char */ |
kenjiArai | 3:fc1908567f3b | 1371 | } |
kenjiArai | 3:fc1908567f3b | 1372 | } |
kenjiArai | 3:fc1908567f3b | 1373 | if ( c >= r ) { |
kenjiArai | 3:fc1908567f3b | 1374 | return 0; /* invalid char for current radix */ |
kenjiArai | 3:fc1908567f3b | 1375 | } |
kenjiArai | 3:fc1908567f3b | 1376 | val = val * r + c; |
kenjiArai | 3:fc1908567f3b | 1377 | c = *(++(*str)); |
kenjiArai | 3:fc1908567f3b | 1378 | } |
kenjiArai | 3:fc1908567f3b | 1379 | if (s) val = 0 - val; /* apply sign if needed */ |
kenjiArai | 3:fc1908567f3b | 1380 | *res = val; |
kenjiArai | 3:fc1908567f3b | 1381 | return 1; |
kenjiArai | 3:fc1908567f3b | 1382 | } |