Web Camera for mbed-os. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Dependencies:   HttpServer_snapshot_mbed-os LWIPBP3595Interface_STA_for_mbed-os RomRamBlockDevice mbed-rpc

Fork of GR-Boards_WebCamera by Renesas

このサンプルは 「GR-LYCHEE」ではじめる電子工作 で紹介しています。
出版時と内容が異ならないよう、各ライブラリはアップデートせずに使用してください。

このサンプルの最新バージョンは下記から入手できます。最新バージョンは本の内容と一部処理が異なります。
https://github.com/d-kato/GR-Boards_WebCamera

Files at this revision

API Documentation at this revision

Comitter:
dkato
Date:
Tue May 16 04:44:07 2017 +0000
Parent:
20:7b5753609952
Child:
22:9e54410bd934
Commit message:
Supports mbed os 5.4.

Changed in this revision

FATFileSystem.lib Show diff for this revision Revisions of this file
GraphicsFramework.lib Show annotated file Show diff for this revision Revisions of this file
LWIPBP3595Interface_mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
RomRamBlockDevice.lib Show annotated file Show diff for this revision Revisions of this file
RomRamFileSystem.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
--- a/FATFileSystem.lib	Thu Feb 23 08:20:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/teams/mbed-official/code/FATFileSystem/#e2ab678eb692
--- a/GraphicsFramework.lib	Thu Feb 23 08:20:51 2017 +0000
+++ b/GraphicsFramework.lib	Tue May 16 04:44:07 2017 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Renesas/code/GraphicsFramework/#9bf28e65755e
+http://developer.mbed.org/teams/Renesas/code/GraphicsFramework/#1ee2176ef13f
--- a/LWIPBP3595Interface_mbed-os.lib	Thu Feb 23 08:20:51 2017 +0000
+++ b/LWIPBP3595Interface_mbed-os.lib	Tue May 16 04:44:07 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/dkato/code/LWIPBP3595Interface_STA_for_mbed-os/#7f296a8b4b11
+https://developer.mbed.org/users/dkato/code/LWIPBP3595Interface_STA_for_mbed-os/#6bd475023468
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RomRamBlockDevice.lib	Tue May 16 04:44:07 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/dkato/code/RomRamBlockDevice/#3e16bac28356
--- a/RomRamFileSystem.h	Thu Feb 23 08:20:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,147 +0,0 @@
-/*******************************************************************************
-* DISCLAIMER
-* This software is supplied by Renesas Electronics Corporation and is only
-* intended for use with Renesas products. No other uses are authorized. This
-* software is owned by Renesas Electronics Corporation and is protected under
-* all applicable laws, including copyright laws.
-* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
-* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
-* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
-* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
-* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
-* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
-* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
-* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
-* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-* Renesas reserves the right, without notice, to make changes to this software
-* and to discontinue the availability of this software. By using this software,
-* you agree to the additional terms and conditions found by accessing the
-* following link:
-* http://www.renesas.com/disclaimer*
-* Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
-*******************************************************************************/
-#ifndef MBED_ROMRAMFILESYSTEM_H
-#define MBED_ROMRAMFILESYSTEM_H
-
-#include "FATFileSystem.h"
-
-#define NUM_OF_SECTORS     (1000)
-#define SECTOR_SIZE        (512)
-
-#if defined(TARGET_RZ_A1H)
-#define ROM_START_ADDRESS  (0x18000000uL)  // for GR-PEACH
-#define ROM_END_ADDRESS    (0x1FFFFFFFuL)  // for GR-PEACH
-#else
-#define ROM_START_ADDRESS  (0xFFFFFFFFuL)
-#define ROM_END_ADDRESS    (0xFFFFFFFFuL)
-#endif
-
-using namespace mbed;
-
-class RomRamFileSystem : public FATFileSystem {
-public:
-    // NUM_OF_SECTORS sectors, each 512 bytes
-    char *sectors[NUM_OF_SECTORS];
-
-    RomRamFileSystem(const char* name) : FATFileSystem(name) {
-        memset(sectors, 0, sizeof(sectors));
-    }
-
-    virtual ~RomRamFileSystem() {
-        for (int i = 0; i < NUM_OF_SECTORS; i++) {
-            if ((sectors[i] != NULL) && (isRomAddress(sectors[i]) == false)) {
-                free(sectors[i]);
-            }
-        }
-    }
-
-    // read a sector in to the buffer, return 0 if ok
-    virtual int disk_read(uint8_t *buffer, uint32_t sector, uint32_t count) {
-        for (uint64_t sec_no = sector; sec_no < (sector + count); sec_no++) {
-            if (sectors[sec_no] == NULL) {
-                // nothing allocated means sector is empty
-                memset(buffer, 0, SECTOR_SIZE);
-            } else {
-                memcpy(buffer, sectors[sec_no], SECTOR_SIZE);
-            }
-            buffer += SECTOR_SIZE;
-        }
-        return 0;
-    }
-
-    // write a sector from the buffer, return 0 if ok
-    virtual int disk_write(const uint8_t *buffer, uint32_t sector, uint32_t count) {
-        for (uint64_t sec_no = sector; sec_no < (sector + count); sec_no++) {
-            bool all_zero = true;
-            for (int i = 0; i < SECTOR_SIZE; i++) {
-                if (buffer[i] != NULL) {
-                    all_zero = false;
-                    break;
-                }
-            }
-            if (all_zero != false) {
-                if (sectors[sec_no] != NULL) {
-                    if (isRomAddress(sectors[sec_no]) == false) {
-                        free(sectors[sec_no]);
-                    }
-                    sectors[sec_no] = NULL;
-                }
-                return 0;
-            }
-            // allocate a sector if needed, and write
-            if (isRomAddress((char *)buffer) == false) {
-                if ((sectors[sec_no] == NULL) || (isRomAddress(sectors[sec_no]) != false)) {
-                    char *sec = (char*)malloc(SECTOR_SIZE);
-                    if (sec == NULL) {
-                        return 1; // out of memory
-                    }
-                    sectors[sec_no] = sec;
-                }
-                memcpy(sectors[sec_no], buffer, SECTOR_SIZE);
-            } else {
-                if (isRomAddress(sectors[sec_no]) == false) {
-                    free(sectors[sec_no]);
-                }
-                sectors[sec_no] = (char *)buffer;
-            }
-            buffer += SECTOR_SIZE;
-        }
-        return 0;
-    }
-
-    // return the number of sectors
-    virtual uint32_t disk_sectors() {
-        return NUM_OF_SECTORS;
-    }
-
-    void dump(FILE *fp) {
-        for (int i = 0; i < NUM_OF_SECTORS; i++) {
-            fwrite(&sectors[i], sizeof(int), 1, fp);
-            if (sectors[i] != NULL) {
-                fwrite(sectors[i], sizeof(char), SECTOR_SIZE, fp);
-            }
-        }
-    }
-
-    void load(FILE *fp) {
-        int sec_info = 0;
-        for (int i = 0; i < NUM_OF_SECTORS; i++) {
-            fread(&sec_info, sizeof(int), 1, fp);
-            if (sec_info != 0) {
-                char *sec = (char *)malloc(SECTOR_SIZE);
-                fread(sec, sizeof(char), SECTOR_SIZE, fp);
-                sectors[i] = sec;
-            }
-        }
-    }
-
-private:
-    bool isRomAddress(char * address) {
-        if (((uint32_t)address >= ROM_START_ADDRESS)
-         && ((uint32_t)address <= (ROM_END_ADDRESS - SECTOR_SIZE + 1))) {
-            return true;
-        }
-        return false;
-    }
-};
-#endif
--- a/main.cpp	Thu Feb 23 08:20:51 2017 +0000
+++ b/main.cpp	Tue May 16 04:44:07 2017 +0000
@@ -4,7 +4,8 @@
 #include "JPEG_Converter.h"
 #include "HTTPServer.h"
 #include "mbed_rpc.h"
-#include "RomRamFileSystem.h"
+#include "FATFileSystem.h"
+#include "RomRamBlockDevice.h"
 #include "file_table.h"        //Binary data of web pages
 #include "i2c_setting.h"
 
@@ -68,7 +69,8 @@
 #else
   #error NETWORK_TYPE error
 #endif /* NETWORK_TYPE */
-RomRamFileSystem romramfs("romram");
+FATFileSystem fs("storage");
+RomRamBlockDevice romram_bd(512000, 512);
 Serial pc(USBTX, USBRX);
 
 #if defined(__ICCARM__)
@@ -315,50 +317,52 @@
 static void mount_romramfs(void) {
     FILE * fp;
 
-    romramfs.format();
+    romram_bd.SetRomAddr(0x18000000, 0x1FFFFFFF);
+    fs.format(&romram_bd, 512);
+    fs.mount(&romram_bd);
 
     //index.htm
-    fp = fopen("/romram/index.htm", "w");
+    fp = fopen("/storage/index.htm", "w");
     fwrite(index_htm_tbl, sizeof(char), sizeof(index_htm_tbl), fp);
     fclose(fp);
 
     //camera.js
-    fp = fopen("/romram/camera.js", "w");
+    fp = fopen("/storage/camera.js", "w");
     fwrite(camaera_js_tbl, sizeof(char), sizeof(camaera_js_tbl), fp);
     fclose(fp);
 
     //camera.htm
-    fp = fopen("/romram/camera.htm", "w");
+    fp = fopen("/storage/camera.htm", "w");
     fwrite(camera_htm_tbl, sizeof(char), sizeof(camera_htm_tbl), fp);
     fclose(fp);
 
     //mbedrpc.js
-    fp = fopen("/romram/mbedrpc.js", "w");
+    fp = fopen("/storage/mbedrpc.js", "w");
     fwrite(mbedrpc_js_tbl, sizeof(char), sizeof(mbedrpc_js_tbl), fp);
     fclose(fp);
 
     //led.htm
-    fp = fopen("/romram/led.htm", "w");
+    fp = fopen("/storage/led.htm", "w");
     fwrite(led_htm_tbl, sizeof(char), sizeof(led_htm_tbl), fp);
     fclose(fp);
 
     //i2c_set.htm
-    fp = fopen("/romram/i2c_set.htm", "w");
+    fp = fopen("/storage/i2c_set.htm", "w");
     fwrite(i2c_set_htm_tbl, sizeof(char), sizeof(i2c_set_htm_tbl), fp);
     fclose(fp);
 
     //web_top.htm
-    fp = fopen("/romram/web_top.htm", "w");
+    fp = fopen("/storage/web_top.htm", "w");
     fwrite(web_top_htm_tbl, sizeof(char), sizeof(web_top_htm_tbl), fp);
     fclose(fp);
 
     //menu.htm
-    fp = fopen("/romram/menu.htm", "w");
+    fp = fopen("/storage/menu.htm", "w");
     fwrite(menu_htm_tbl, sizeof(char), sizeof(menu_htm_tbl), fp);
     fclose(fp);
 
     //window.htm
-    fp = fopen("/romram/window.htm", "w");
+    fp = fopen("/storage/window.htm", "w");
     fwrite(window_htm_tbl, sizeof(char), sizeof(window_htm_tbl), fp);
     fclose(fp);
 }
@@ -390,88 +394,88 @@
 }
 
 #if (SCAN_NETWORK == 1)
-static void scan_network(void) {
-    int num;
+static const char *sec2str(nsapi_security_t sec) {
+    switch (sec) {
+        case NSAPI_SECURITY_NONE:
+            return "None";
+        case NSAPI_SECURITY_WEP:
+            return "WEP";
+        case NSAPI_SECURITY_WPA:
+            return "WPA";
+        case NSAPI_SECURITY_WPA2:
+            return "WPA2";
+        case NSAPI_SECURITY_WPA_WPA2:
+            return "WPA/WPA2";
+        case NSAPI_SECURITY_UNKNOWN:
+        default:
+            return "Unknown";
+    }
+}
+
+static bool scan_network(WiFiInterface *wifi) {
+    WiFiAccessPoint *ap;
+    bool ret = false;
     int i;
-    int select_no;
-    bool loop_break;
-    char ch;
-    char pass[64];
-    const uint8_t *wk_p;
-    WiFiAccessPoint point[8];
+    int count = 8;    /* Limit number of network arbitrary to 8 */
+
+    printf("Scan:\r\n");
+    ap = new WiFiAccessPoint[count];
+    count = wifi->scan(ap, count);
+    for (i = 0; i < count; i++) {
+        printf("No.%d Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\r\n", i, ap[i].get_ssid(),
+               sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
+               ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
+    }
+    printf("%d networks available.\r\n", count);
 
-    while (1) {
-        printf("scan...\n");
-        num = network.scan(point, 8);
-        for (i = 0; i < num; i++) {
-            printf(" No.%d\n", i);
-            printf("   ssid    :%s\n", point[i].get_ssid());
-            wk_p = point[i].get_bssid();
-            printf("   bssid   :0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n",
-                    wk_p[0],wk_p[1],wk_p[2],wk_p[3],wk_p[4],wk_p[5]);
-            printf("   security:");
-            switch (point[i].get_security()) {
-                case NSAPI_SECURITY_NONE:
-                    printf("NONE\n");
-                    break;
-                case NSAPI_SECURITY_WPA:
-                    printf("WPA\n");
-                    break;
-                case NSAPI_SECURITY_WPA2:
-                    printf("WPA2\n");
-                    break;
-                case NSAPI_SECURITY_WPA_WPA2:
-                    printf("WPA_WPA2\n");
-                    break;
-                case NSAPI_SECURITY_UNKNOWN:
-                default:
-                    printf("UNKNOWN\n");
-                    break;
+    if (count > 0) {
+        char c;
+        char pass[64];
+        int select_no;
+        bool loop_break = false;;
+
+        printf("\nPlease enter the number of the network you want to connect.\r\n");
+        printf("Enter key:[0]-[%d], (If inputting the other key, it's scanned again.)\r\n", count - 1);
+        c = (uint8_t)pc.getc();
+        select_no = c - 0x30;
+        if ((select_no >= 0) && (select_no < count)) {
+            printf("[%s] is selected.\r\n", ap[select_no].get_ssid());
+            printf("Please enter the PSK.\r\n");
+            i = 0;
+            while (loop_break == false) {
+                c = (uint8_t)pc.getc();
+                switch (c) {
+                    case 0x0D:
+                        pass[i] = '\0';
+                        pc.puts("\r\n");
+                        loop_break = true;
+                        break;
+                    case 0x08:
+                        if (i > 0) {
+                            pc.puts("\b \b");
+                            i--;
+                        }
+                        break;
+                    case 0x0A:
+                        break;
+                    default:
+                        if ((i + 1) < sizeof(pass)) {
+                            pass[i] = c;
+                            i++;
+                            pc.putc(c);
+                        }
+                        break;
+                }
             }
-            printf("   rssi    :%d\n", point[i].get_rssi());
-            printf("   channel :%d\n", point[i].get_channel());
-        }
-        if (num > 0) {
-            printf("\nPlease enter the number of the network you want to connect.\n");
-            printf("Enter key:[0]-[%d], (If inputting the other key, it's scanned again.)\n", num - 1);
-            ch = (uint8_t)pc.getc();
-            select_no = ch - 0x30;
-            if ((select_no >= 0) && (select_no < num)) {
-                printf("[%s] is selected.\n", point[select_no].get_ssid());
-                printf("Please enter the PSK.\n");
-                loop_break = false;
-                i = 0;
-                while (loop_break == false) {
-                    ch = (uint8_t)pc.getc();
-                    switch (ch) {
-                        case 0x0D:
-                            pass[i] = '\0';
-                            pc.puts("\r\n");
-                            loop_break = true;
-                            break;
-                        case 0x08:
-                            if (i > 0) {
-                                pc.puts("\b \b");
-                                i--;
-                            }
-                            break;
-                        case 0x0A:
-                            break;
-                        default:
-                            if ((i + 1) < sizeof(pass)) {
-                                pass[i] = ch;
-                                i++;
-                                pc.putc(ch);
-                            }
-                            break;
-                    }
-                }
-                printf("connecting...\n");
-                network.set_credentials(point[select_no].get_ssid(), pass, point[select_no].get_security());
-                break;
-            }
+            printf("connecting...\r\n");
+            wifi->set_credentials(ap[select_no].get_ssid(), pass, ap[select_no].get_security());
+            ret = true;
         }
     }
+
+    delete[] ap;
+
+    return ret;
 }
 #endif
 
@@ -509,7 +513,7 @@
 #endif
 #if (NETWORK_TYPE == 1)
 #if (SCAN_NETWORK == 1)
-    scan_network();
+    while (!scan_network(&network));
 #else
     network.set_credentials(WLAN_SSID, WLAN_PSK, WLAN_SECURITY);
 #endif
@@ -526,7 +530,7 @@
 
     SnapshotHandler::attach_req(&snapshot_req);
     HTTPServerAddHandler<SnapshotHandler>("/camera"); //Camera
-    FSHandler::mount("/romram", "/");
+    FSHandler::mount("/storage", "/");
     HTTPServerAddHandler<FSHandler>("/");
     HTTPServerAddHandler<RPCHandler>("/rpc");
     HTTPServerStart(&network, 80);
--- a/mbed-os.lib	Thu Feb 23 08:20:51 2017 +0000
+++ b/mbed-os.lib	Tue May 16 04:44:07 2017 +0000
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#bcf7085d85b2811b5d68bdda192c754eadfb8f88
+https://github.com/ARMmbed/mbed-os/#8d21974ba35e04c4854e5090c0f8283171664175