Web Camera for mbed-os. This sample works on GR-LYCHEE besides GR-PEACH. 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

For mbed classic sample

For mbed classic sample, please refer to the following.
mbed classic用サンプルについては以下を参照ください。

https://developer.mbed.org/teams/Renesas/code/GR-PEACH_WebCamera_mbed-classic/

License

When you use this program, we judge you have agreed to the following contents.
本プログラムを使用する際は、以下の内容に合意した事になります。

https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

Video Links on how to setup and run WebCamera Application:

Your video will be live at:

What is this ?

Web Camera sample program using GR-PEACH(with GR-PEACH AUDIO CAMERA Shield) or GR-LYCHEE. When you access GR-PEACH or GR-LYCHEE from a web browser, the following contents is indicated.

  • Camera input picture
  • Control screen of devices connected to the I2C bus
  • LED control screen

When importing this programming, please put a check in "Update all libraries to the latest version".
I consulted this about HTTPServer and RPC./users/yueee_yt/code/HttpServerSample/

Please refer to following link about GR-PEACH AUDIO CAMERA Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

Composition

For GR-PEACH:

  1. GR-PEACH
  2. One of the following
    NTSC analog camera, MT9V111 and GR-PEACH AUDIO CAMERA Shield、OV5642 and GR-PEACH AUDIO CAMERA Shield、GR-PEACH Wireless CAMERA Shield : OV7725
  3. One of the following network
    Ethernet、BP3595 (wifi)、GR-PEACH Wireless CAMERA Shield : ESP32 (wifi)

For GR-LYCHEE:

  1. GR-LYCHEE


The IP address is acquired from DHCP Server by this sample program. When you'd like to use a static IP address, please change the below.

main.cpp (IP address config)

/** Network setting **/
#define USE_DHCP               (1)                 /* Select  0(static configuration) or 1(use DHCP) */
#if (USE_DHCP == 0)
  #define IP_ADDRESS           ("192.168.0.2")     /* IP address      */
  #define SUBNET_MASK          ("255.255.255.0")   /* Subnet mask     */
  #define DEFAULT_GATEWAY      ("192.168.0.3")     /* Default gateway */
#endif


To specify MAC address, add fllowing function to main.cpp.

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}


Also, please change the below along your using network type.

main.cpp (Network type setting)

#define NETWORK_TYPE           (0)                 /* Select  0(Ethernet), 1(BP3595), 2(ESP32 STA) ,3(ESP32 AP) */
#if (NETWORK_TYPE >= 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif


How to use

  1. Please turn on the power to GR-PEACH or GR-LYCHEE and start terminal software.
  2. Please connect an ethernet cable and press the reset button on board.
  3. An IP address is output on terminal.
    The after explanation assumes an IP address "192.168.0.2".
    Please refer to the following link about how to use the terminal.
    The default value of baud rate in mbed is 9600, and this application uses baud rate 9600.
    https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
    https://developer.mbed.org/handbook/SerialPC
  4. When "http://192.168.0.2/web_top.htm" is opened by a web browser, top screen is indicated.
    The configuration of the top screen is a menu screen on the left side, a description screen of the sample program on the right side.
    If you click on each menu on the left side of the screen, the screen along the menu is indicated on the right screen.
  5. When you click the "Web camera" in the menu screen, the pictures of a camera is indicated.
    It can be changed at a slider bar in "Wait time" at the timing of a renewal of a camera picture. (Defaults are 500ms.)
  6. When you click the "Setting by I2C" of the menu screen, the control screen of the device connected to the I2C bus is indicated.
    By sending a command of a format listed below("Format of the device set by I2C") in Direct input or File reference, data transmission and reception is possible with respect to devices connected to I2C_SDA and I2C_SCL terminals of I2C.
    (In this configuration, you can execute the camera settings such as white balance and automatic exposure with respect to Camera(MT9V111).)
    The communication log of transmission and reception by "Format of the device set by I2C" is displayed in the log window.
    When you press the "Clear" button, the log is cleared. When you press the "Save" button, the log is saved.
  7. When you click the "LED On/Off" of the menu screen, the LED control screen is indicated.
    Each switch switches LED1 ~ LED3 of GR-PEACH(LED1 ~ LED4 of GR-LYCHEE) to ON or OFF.
    Each switch indicates the current state of LED on board. When the LED is On, the color of switch will change the LED color.
  8. When you click the "Top Page" of the menu screen, the top screen is indicated.


The Terminal indication when being a reset start.

********* PROGRAM START ***********
Network Setting up...
MAC Address is 00:02:f7:f0:00:00
IP Address is 192.168.0.2
NetMask is 255.255.255.0
Gateway Address is 192.168.0.3
Network Setup OK




Example of ”Page Top” screen
/media/uploads/1050186/web_top2.jpg


Example of ”Web Camera” screen
/media/uploads/1050186/camera3.jpg


Example of ”Setting by I2C” screen
/media/uploads/1050186/setting_i2c3.jpg

Format of the device set by I2C

Method:I2C addr,data length,data1,data2,data3,...

The details of each parameter is shown below.
For specific settings, check on the specifications of the connected device, you must create a command along the format.

MethodPlease specify one of the following:
"Wr" ・・・ Write functions in I2C
"Rd" ・・・ Read functions in I2C
"WrNoP" ・・・ Write functions in I2C(No STOP condition)
"RdNoP" ・・・ Read functions in I2C(No STOP condition)
I2C addrSet the I2C address of device in hexadecimal.
Ex: If the address is 0x90, set the "90"
data lengthIf Method is "Wr" or "WrNoP", set write size(the size of the data portion) in hexadecimal.
Ex: If the write size is 2 byte(data1, data2), set the "02".
If Method is "Rd" or "RdNoP", set read size in hexadecimal.
Ex: If the read size is 10 byte, set the "0A".
dataIf Method is "Wr" or "WrNoP", set write data in 1 byte unit in hexadecimal.
Ex: If the write data is 0x01 0x02, set "01" in the data1 and "02" in the data2.
If Method is "Rd" or "RdNoP", this parameter is omitted.

An example of the format is shown below.

Wr:90,03,25,45,14

To the device of the I2C address 0x90, the data write of 3Byte(0x25 0x45 0x14)

Rd:90,02

To the device of the I2C address 0x90, the data read of 2Byte


Some of the camera settings commands for MT9V111 is shown below.
In the case of direct input, after writing the commands in a text box, press the "Send" button.
In the case of file reference, after selecting file in the "Choose a text file" button, press the "Send" button.
In MT9V111, the setting value is valid until you shut off the power supply disconnect the USB cable.



Example of ”LED On/Off” screen
/media/uploads/1050186/led2.jpg

Processing

  1. At the time of a reset start.
    1. Data for Web pages written on file_"table.h" is registered with FileSystem. ".htm" files and ".js" files are indicated on "file_table.h "as binary data.
    2. The merit of the picture is begun from a camera using GR-PEACH_video library.
    3. To allow LED operation and Terminal output from the Web browser, registration with the mbed-rpc library is done.
    4. EthernetInterface is started and an IP address is acquired from DHCP Server. (It's possible to set a static IP address.)
      The after explanation assumes an IP address "192.168.0.2".
    5. SnapshotHandler (for pictures), FSHandler (for Web page indication) and RPCHandler (for operation) are registered with HTTPServer.

  2. At the time of "Web Camera" click.
    1. "http://192.168.0.2/camera.htm" is opened.
    2. The function in the JavaScript "http://192.168.0.2/camera.js" is called, and a picture acquisition request to SnapshotHandler occurs periodically.
    3. When GR-PEACH or GR-LYCHEE accept a picture acquisition order to SnapshotHandler, GR-PEACH or GR-LYCHEE change the camera picture acquired from GR-PEACH_video library to JPEG in JPEG Converter in a GraphicsFramework library and replies to a web browser.
      The picture size GR-PEACH or GR-LYCHEE send is QVGA (320 x 240). Even biggest VGA (640 x 480) is expanded on the web browser.

  3. At the time of "Setting by I2C" click.
    1. "http://192.168.0.2/i2c_set.htm" is opened.
    2. When you push the "Send" button, the function in the JavaScript "http://192.168.0.2/camera.js" is called, and a control acquisition request to SnapshotHandler occurs periodically.
    3. When GR-PEACH or GR-LYCHEE accept a control acquisition order to SnapshotHandler, GR-PEACH or GR-LYCHEE analyze the command part and execute the I2C communication using the I2C driver.

      The communication log of transmission and reception by "Format of the device set by I2C" is displayed in the log window.
      In the writing format, GR-PEACH or GR-LYCHEE execute data writing by the I2C communication and displays the results of writing on the log window. In success, it is "OK run". In failure, it is "NG run".
      In the reading format, GR-PEACH or GR-LYCHEE execute data reading by the I2C communication and displays the results of writing on the log window. In success, it is "OK XX,YY,... run". In failure, it is "NG run".
      (XX and YY are the read data in accordance with the specified size.)

      Example of "Write successful example" screen
      /media/uploads/1050186/i2c_log_write.jpg

      Example of "Read successful example(read data=2Byte)" screen
      /media/uploads/1050186/i2c_log_read.jpg

      Also when you connect the "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14", etc., GR-PEACH or GR-LYCHEE execute the I2C communication. When you set the writing format to the command part of subsequent of "/run,", GR-PEACH or GR-LYCHEE execute data writing by the I2C communication and displays the results of writing on the web browser. In success, it is "OK run". In failure, it is "NG run".
      When you set the reading format to the command part of subsequent of "/run,", GR-PEACH or GR-LYCHEE execute data reading by the I2C communication and displays the results of writing on the web browser. In success, it is "OK XX,YY,... run". In failure, it is "NG run".
      (XX and YY are the read data in accordance with the specified size.)

      Example of "Write successful example" screen
      /media/uploads/1050186/i2c_write2.jpg

      Example of "Read successful example(read data=2Byte)" screen
      /media/uploads/1050186/i2c_read2.jpg


  4. At the time of "LED On/Off" click.
    1. "http://192.168.0.2/led.htm" is opened.
    2. When you push each switch, the function in the JavaScript "http://192.168.0.2/mbedrpc.js" is called, and a control acquisition request of "http://192.168.0.2/rpc/led1/write 1" etc. occurs to RPCHandler.
    3. When GR-PEACH or GR-LYCHEE accept a control acquisition order to RPCHandler, GR-PEACH or GR-LYCHEE operate an LED using mbed-rpc library.
    4. Then, an information acquisition request of "http://192.168.0.2/rpc/led1/write 1" etc. occurs to RPCHandler.
    5. When GR-PEACH or GR-LYCHEE accept an information acquisition order to RPCHandler, GR-PEACH or GR-LYCHEE get the current status of LED using mbed-rpc library, replies to a web browser.


File in the "file_table.h"

It's modified by making reference to something introduced here about the RPC function ("led.htm" and "mbedrpc.js").
/users/yueee_yt/code/HttpServerSample/


When you enable the following thread startup process and thread process, you can set the device in the I2C at Terminal via as well as via a Web browser.
Command to be sent is the same as at the time through a Web browser.

main.cpp

int main(void) {
    printf("********* PROGRAM START ***********\r\n");

    /* Please enable this line when performing the setting from the Terminal side. */
//    Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE);


i2c_setting.cpp

#if(0) /* Please enable this line when performing the setting from the Terminal side. */
Serial terminal(USBTX, USBRX);
static char recv_term_buffer[I2C_SETTING_STR_BUF_SIZE];

void SetI2CfromTerm(void const *argument) {
    ... Skip ...
}
#endif





Using WiFi BP3595

When using "GR-PEACH Normal", it's possible to do a WiFi connection with BP3595 manufactured by ROHM instead of an ethernet connection. GR-PEACH has a dedicated connector for BP3595. Without the need for complex wiring work, it is capable of high-speed wireless communication of the USB2.0 connection.
/media/uploads/dkato/normal-wifi_01_s.png
https://developer.mbed.org/components/BP3595-for-GR-PEACH/

GR-PEACH、GR-PEACH AUDIO CAMERA Shield、Camera、PC、WiFi access point、BP3595。
/media/uploads/dkato/web_camera_composition_wifi.png

It's necessary to input 5V to VBUS1 to use BP3595. It is possible to supply 5V to VBUS1 by following one of them.

  1. Close GR-PEACH's JP21
    https://developer.mbed.org/teams/Renesas/wiki/Jumper-settings-of-GR-PEACH
  2. Close GR-PEACH AUDIO CAMERA Shield's JP1
    https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

Modify "User Selection" setting of main.cpp as below when using BP3595.

main.cpp (Network type setting)

#define NETWORK_TYPE           (0)                 /* Select  0(Ethernet), 1(BP3595), 2(ESP32 STA) ,3(ESP32 AP) */
#if (NETWORK_TYPE >= 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif


NETWORK_TYPEIf using WiFi BP3595, "NETWORK_TYPE" should be "1".
SCAN_NETWORK0: It's connected to a network using WLAN_SSID, WLAN_PSK and WLAN_SECURITY.
1: A network is chosen from a scan result. A scan result is shown to Terminal.
WLAN_SSIDSet the SSID to connect to the access point. It isn't used in case of "SCAN_NETWORK = 1".
WLAN_PSKSet the password to connect to the access point. It isn't used in case of "SCAN_NETWORK = 1".
WLAN_SECURITYSet the security type to connect to the access point. It isn't used in case of "SCAN_NETWORK = 1".



Appendix

Setting of fixed IP address

Only for Windows(R) user:
You need to set up IP address of your PC to match GR-PEACH WebCamera sample when you use fixed IP address.
The default settings are as below.

GR-PEACH192.168.0.2
Subnet mask255.255.255.0
Default Gate Way192.168.0.3


Setting steps of IP address is shown as below.
We will set "192.168.0.3" for the IP address of PC in following steps.

  1. Open the control panel and click "Network and Sharing Center".
    /media/uploads/MasaoHamanaka/change_ip_eng_1.png

  2. Click "Change adapter settings".
    /media/uploads/MasaoHamanaka/change_ip_eng_2.png

  3. Right-click "Local Area Connection" to open a property.
    /media/uploads/MasaoHamanaka/change_ip_eng_3.png

  4. Select "Internet Protocol Version 4(TCP/IPv4)" and click "Properties".
    /media/uploads/MasaoHamanaka/change_ip_eng_4.png

  5. Check "Use the following IP address:" and "Use the following DNS server addresses:".
  6. Enter "192.168.0.3" to "IP address:", and enter "255.255.255.0" to "Subnet mask:".
    "Default gateway:", "Preferred DNS server:", and "Alternate DNS server:" are empty.
    And click "OK".
    /media/uploads/MasaoHamanaka/change_ip_eng_5.png


MATLAB & WebCamera

Do more with WebCamera.. ...

compare images

/media/uploads/pateshian/grp-matlab.pdf

GR-PEACH and MATLAB operations – Image differences – two jpeg (.jpg) image files. MATLAB using R2014A forward

Example – WebCamera –possible applications: Motion detection, Earthquake monitoring (or Camera vibration) Intruder detection, alarm function

Steganography*, (finding hidden messages in original source vs. modified version)

  • Can be independent of WebCamera – SURF section can be skipped for better performance

-MATLAB change detection, using general or WebCamera pictures - here is Scale Invariant difference of two similar pictures

This would be best case results –

File : difference.m (for MatLab) is complex code and Sqrt, Arctangent in SURF algorithms to do jpg to rgb absolute differences – this would not be fast on GR-PEACH. SURF is used as its 3-5x faster than SIFT.


概要

GR-PEACHとGR-PEACH AUDIO CAMERA Shield、又は、GR-LYCHEEを使ったWeb Cameraサンプルプログラムです。
WebブラウザからGR-PEACHにアクセスすると以下が表示されます。

  • Camera入力画像
  • I2Cバスに繋がっているデバイスの制御画面
  • LED操作画面

Importの際は"Update all libraries to the latest version"にチェックを入れてください。
HTTPServer、および、RPCについて、こちらを参考にさせていただきました。/users/yueee_yt/code/HttpServerSample/

GR-PEACH AUDIO CAMERA Shieldについては下記を参照ください。
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

構成

GR-PEACHの場合:

  1. GR-PEACH
  2. 以下のいずれか
    NTSCアナログカメラ、MT9V111 and GR-PEACH AUDIO CAMERA Shield、OV5642 and GR-PEACH AUDIO CAMERA Shield、GR-PEACH Wireless CAMERA Shield : OV7725
  3. 以下のいずれかのネットワーク
    Ethernet、BP3595 (wifi)、GR-PEACH Wireless CAMERA Shield : ESP32 (wifi)

GR-LYCHEEの場合:

  1. GR-LYCHEE


サンプルプログラムではDHCP ServerからIPアドレスを取得します。固定IPアドレスを使用する場合は以下を変更してください。

main.cpp (IP address config)

/** Network setting **/
#define USE_DHCP               (1)                 /* Select  0(static configuration) or 1(use DHCP) */
#if (USE_DHCP == 0)
  #define IP_ADDRESS           ("192.168.0.2")     /* IP address      */
  #define SUBNET_MASK          ("255.255.255.0")   /* Subnet mask     */
  #define DEFAULT_GATEWAY      ("192.168.0.3")     /* Default gateway */
#endif


main.cppの最後にの下記のように関数を追加し、用意したMACアドレスを設定してください。

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}


また、使用するネットワークに合わせて以下を変更してください。

main.cpp (Network type setting)

#define NETWORK_TYPE           (0)                 /* Select  0(Ethernet), 1(BP3595), 2(ESP32 STA) ,3(ESP32 AP) */
#if (NETWORK_TYPE >= 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif


使い方

  1. GR-PEACH or GR-LYCHEEに電源を入れ、Terminalソフトを立ち上げます。
  2. イーサーネットケーブルを接続し、ボード上のリセットボタンを押します。
  3. Terminal上にIPアドレスが出力されます。
    以降は取得(設定)したIPアドレスが"192.168.0.2"として説明します。
    Terminalの使い方は以下のリンクを参照下さい。
    mbedでのボーレートのデフォルト値は9600で、このサンプルではボーレート9600を使います。
    https://developer.mbed.org/teams/Renesas/wiki/GR-PEACH-Getting-Started#install-the-usb-serial-communication
    https://developer.mbed.org/handbook/SerialPC
  4. PCのWebブラウザで”http://192.168.0.2/web_top.htm”を開くと、トップ画面が表示されます。
    トップ画面は、左側にメニュー画面、右側にサンプルプログラムの説明画面という構成になっており、
    左画面の各メニューをクリックすると、メニューに沿った画面が右画面に表示されます。
  5. メニュー画面の”Web Camera”をクリックすると、Camera画像が表示されます。
    "Wait time"のスライダーバーでCamera画像の更新タイミングが変更できます。(初期値は500msです)
  6. メニュー画面の"Setting by I2C"をクリックすると、I2Cバスに繋がっているデバイスの制御画面が表示されます。
    直接入力(Direct input)欄又はファイル参照(File reference)欄にて、下記("I2Cによるデバイス設定のフォーマット")に記載されているフォーマットのコマンドを送信する事で、I2CのI2C_SDA,I2C_SCL端子に繋がっているデバイスに対して、データの送受信が可能です。
    (今回の構成ではCamera(MT9V111)に対して、ホワイトバランスや自動露出といったカメラ設定が行えます。)
    "I2Cによるデバイス設定のフォーマット"による送受信の通信ログは、ログウィンドウに表示されます。
    "Clear"ボタンを押すとログのクリア、"Save"ボタンを押すとログの保存ができます。
  7. メニュー画面の"LED On/Off"をクリックすると、LED操作画面が表示されます。
    各スイッチはGR-PEACHのLED1~LED3、GR-LYCHEEのLED1~LED4をON/OFF切り替えます。
    スイッチはそれぞれボード上LEDの現状を表しており、ONにすると対応するLEDの色になります。
  8. メニュー画面の"Top Page"をクリックすると、 トップ画面が表示されます。


リセットスタート時のTerminal表示

********* PROGRAM START ***********
Network Setting up...
MAC Address is 00:02:f7:f0:00:00
IP Address is 192.168.0.2
NetMask is 255.255.255.0
Gateway Address is 192.168.0.3
Network Setup OK



”Page Top”画面の例
/media/uploads/1050186/web_top2.jpg


”Web Camera”画面の例
/media/uploads/1050186/camera3.jpg


”Setting by I2C”画面の例
/media/uploads/1050186/setting_i2c3.jpg

I2Cによるデバイス設定のフォーマット

Method:I2C addr,data length,data1,data2,data3,...

各パラメータの詳細を以下に示します。
具体的な設定値については、接続先のデバイスの仕様をご確認のうえ、フォーマットに沿ってコマンドを作成して下さい。

Method以下のいづれかを指定して下さい
"Wr" ・・・ I2Cでの書き込み
"Rd" ・・・ I2Cでの読み出し
"WrNoP" ・・・ I2Cでの書き込み(STOPコンディション省略)
"RdNoP" ・・・ I2Cでの読み出し(STOPコンディション省略)
I2C addr接続先デバイスのI2Cアドレスを16進数で設定して下さい。
(例) アドレスが0x90の場合、"90"を設定
data lengthMethodが"Wr"又は"WrNoP"の場合、書き込むサイズ(data部分のサイズ)を16進数で設定して下さい。
(例) 書き込むサイズが2Byte(data1,data2)の場合、"02"を設定
Methodが"Rd"又は"RdNoP"の場合は読み取るサイズを16進数で設定して下さい。
(例) 読み取りサイズが10Byteの場合、"0A"を設定
dataMethodが"Wr"又は"WrNoP"の場合、書き込むデータを16進数で1Byte単位で設定して下さい。
(例) 書き込みデータが0x01,0x02の場合、data1に"01"、data2に"02"を設定
"Rd"又は"RdNoP"の場合は省略して下さい。

フォーマットの例を以下に示します。

Wr:90,03,25,45,14

I2Cアドレス0x90のデバイスに対して0x25 0x45 0x14の計3Byteのデータ書き込み

Rd:90,02

I2Cアドレス0x90のデバイスに対して2Byteのデータ読み出し


また、MT9V111用のカメラ設定コマンドをいくつか用意しました。
直接入力(Direct input)の場合は、テキストボックスにコマンドを書いた後、"Send"ボタンを押して下さい。
ファイル参照(File reference)の場合は、"Choose a text file"ボタンをクリックしてファイルを選択した後、"Send"ボタンを押して下さい。
MT9V111の場合、USBケーブルを抜き電源供給を遮断するまで設定値が有効になります。



”LED On/Off”画面の例
/media/uploads/1050186/led2.jpg

処理の流れ

  1. リセットスタート時
    1. "file_table.h"に書かれたWeb page用データをFileSystemに登録します。 "file_table.h"には".htm"ファイルと".js"ファイルがバイナリデータとして記載されています。
    2. GR-PEACH_videoライブラリを用いてCameraからの画像取得を開始します。
    3. WebブラウザからI2Cでの設定、LED操作、及び、Terminal出力ができるように、mbed-rpcライブラリへの登録を行います。
    4. EthernetInterfaceを起動し、DHCP ServerからIPアドレスを取得します。(固定アドレスを設定することもできます)
      以降は取得(設定)したIPアドレスが"192.168.0.2"として説明します。
    5. HTTPServerにSnapshotHandler(画像用)、FSHandler(Webページ表示用)、RPCHandler(操作用)を登録します。

  2. "Web Camera"クリック時
    1. "http://192.168.0.2/camera.htm"が開きます。
    2. JavaScript "http://192.168.0.2/camera.js"内の関数が実行され、定期的にSnapshotHandlerへの画像取得要求が発生します。
    3. GR-PEACH or GR-LYCHEEはSnapshotHandlerへの画像取得要求を受けると、GR-PEACH_videoライブラリから取得したCamera画像をGraphicsFrameworkライブラリのJPEG ConverterにてJPEGに変換し、Webブラウザに応答します。
      GR-PEACH or GR-LYCHEEが送信する画像サイズはQVGA(320 x 240)です。Webブラウザ上で最大VGA(640 x 480)まで拡大されます。

  3. "Setting by I2C"クリック時
    1. "http://192.168.0.2/i2c_set.htm"が開きます。
    2. "Send"ボタンを押すと、JavaScript "http://192.168.0.2/mbedrpc.js"内の関数が実行され、RPCHandlerへ "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14" などの操作要求が発生します。
    3. GR-PEACH or GR-LYCHEEはRPCHandlerへの操作要求を受けると、"/run,"以降のコマンド部分の解析を行い、I2Cドライバを用いてI2C通信を行います。

      "I2Cによるデバイス設定のフォーマット"による送受信の通信ログは、ログウィンドウに表示されます。
      書き込みフォーマットの場合、I2C通信でデータ書き込みを行ない、ログウィンドウに書き込み結果を表示します。成功の場合は"OK run"、失敗の場合は"NG run"となります。
      読み出しフォーマットの場合、I2C通信でデータ読み出し行ない、ログウィンドウに読み出し結果と読み出したデータを表示します。成功の場合は"OK XX,YY,... run"、失敗の場合は"NG run"となります。
      (XXやYYは指定サイズに応じた読み出したデータです。)

      "書き込み成功例"画面の例
      /media/uploads/1050186/i2c_log_write.jpg

      "読み出し成功例(読み出しデータ=2Byte)"画面の例
      /media/uploads/1050186/i2c_log_read.jpg

      また、 "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14" などで直接接続した場合でも、上記同様のI2C通信を行います。 "/run,"以降のコマンド部分を書き込みフォーマットにすると、I2C通信でデータ書き込みを行ない、ブラウザ上に書き込み結果を表示します。成功の場合は"OK run"、失敗の場合は"NG run"となります。
      "/run,"以降のコマンド部分を読み出しフォーマットにすると、I2C通信でデータ読み出しを行ない、ブラウザ上に読み出し結果と読み出したデータを表示します。成功の場合は"OK XX,YY,... run"、失敗の場合は"NG run"となります。
      (XXやYYは指定サイズに応じた読み出したデータです。)

      "書き込み成功例"画面の例
      /media/uploads/1050186/i2c_write2.jpg

      "読み出し成功例(読み出しデータ=2Byte)"画面の例
      /media/uploads/1050186/i2c_read2.jpg

  4. "LED On/Off"クリック時
    1. "http://192.168.0.2/led.htm"が開きます。
    2. 各スイッチを操作すると、JavaScript "http://192.168.0.2/mbedrpc.js"内の関数が実行され、RPCHandlerへ "http://192.168.0.2/rpc/led1/write 1" などの操作要求が発生します。
    3. GR-PEACH or GR-LYCHEEはRPCHandlerへの操作要求を受けると、mbed-rpcライブラリを通してLEDのOn/Off操作を行います。
    4. その後、RPCHandlerへ "http://192.168.0.2/rpc/led1/read" などの情報取得要求が発生します。
    5. GR-PEACH or GR-LYCHEEはRPCHandlerへの情報取得要求を受けると、mbed-rpcライブラリを通してLEDの現在の状態を取得し、Webブラウザに応答します。


"file_table.h"内のファイル

RPC機能("led.htm"、"mbedrpc.js")については、こちらで紹介されているものを参考に一部変更しています。
/users/yueee_yt/code/HttpServerSample/


なお、サンプルプログラムにて、以下のスレッド起動処理とスレッド処理を有効すると、 Webブラウザ経由と同様にTerminal経由でもI2Cでのデバイス設定ができます。
送信するコマンドはWebブラウザ経由時と同じです。

main.cpp

int main(void) {
    printf("********* PROGRAM START ***********\r\n");

    /* Please enable this line when performing the setting from the Terminal side. */
//    Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE);


i2c_setting.cpp

#if(0) /* Please enable this line when performing the setting from the Terminal side. */
Serial terminal(USBTX, USBRX);
static char recv_term_buffer[I2C_SETTING_STR_BUF_SIZE];

void SetI2CfromTerm(void const *argument) {
    ... 省略 ...
}
#endif





WiFi BP3595を使う

「GR-PEACH Normal」をご使用の場合、イーサーネット接続の代わりにROHM製BP3595を使用したWiFi接続を行うことができます。GR-PEACHにはBP3595専用のコネクタが搭載されています。複雑な配線作業をする必要なく、USB2.0接続の高速無線通信が可能です。
/media/uploads/dkato/normal-wifi_01_s.png
https://developer.mbed.org/components/BP3595-for-GR-PEACH/

GR-PEACH、GR-PEACH AUDIO CAMERA Shield、Camera、PC、WiFiアクセスポイント、BP3595。
/media/uploads/dkato/web_camera_composition_wifi.png

BP3595を使用する為にはVBUS1に5Vを入力する必要があります。以下のいずれかの対応でVBUS1に5Vを供給する事が可能です。

  1. GR-PEACHのJP21をショートする。
    https://developer.mbed.org/teams/Renesas/wiki/Jumper-settings-of-GR-PEACH
  2. GR-PEACH AUDIO CAMERA ShieldのJP1をショートする。
    https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

BP3595を使用する場合はmain.cppのUser Selection の設定を変更してください。

main.cpp (Network type setting)

#define NETWORK_TYPE           (0)                 /* Select  0(Ethernet), 1(BP3595), 2(ESP32 STA) ,3(ESP32 AP) */
#if (NETWORK_TYPE >= 1)
  #define SCAN_NETWORK         (1)                 /* Select  0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
  #define WLAN_SSID            ("SSIDofYourAP")    /* SSID */
  #define WLAN_PSK             ("PSKofYourAP")     /* PSK(Pre-Shared Key) */
  #define WLAN_SECURITY        NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
#endif


NETWORK_TYPEWiFi BP3595を使用する場合は、1を選択します。
SCAN_NETWORK0: WLAN_SSID、WLAN_PSK、WLAN_SECURITYを使ってネットワークに接続します。
1: スキャン結果からネットワークを選択します。スキャン結果はTerminalに表示されます。
WLAN_SSID接続先アクセスポイントのSSIDを設定します。SCAN_NETWORK=1の場合は使用しません。
WLAN_PSK接続先アクセスポイントのパスワードを設定します。SCAN_NETWORK=1の場合は使用しません。
WLAN_SECURITY接続先アクセスポイントのセキュリティタイプを設定します。SCAN_NETWORK=1の場合は使用しません。



付録

固定IPアドレスの設定

以降はWindows PCでの固定IPアドレス設定方法を記載します。
GR-PEACH WebCameraサンプルで、固定IPアドレスを使用する場合、
PC側のIPアドレスをプログラムに合うよう変更する必要があります。
デフォルトでは、以下の設定になっています。

GR-PEACH192.168.0.2
Subnet mask255.255.255.0
Default Gate Way192.168.0.3


以下にIPアドレス設定方法を記載します。
PCに設定するIPアドレスは、192.168.0.3を設定します。

  1. コントロールパネルを開き、「ネットワークと共有センター」をクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_1.png

  2. 「アダプターの設定の変更」をクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_2.png

  3. 「ローカルエリア接続」を右クリックし、プロパティを開きます。
    /media/uploads/MasaoHamanaka/change_ip_jpn_3.png

  4. 「インターネット プロトコル バージョン 4(TCP/IPv4)」を選択し、「プロパティ」をクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_4.png

  5. 「次のIPアドレスを使う」および「次のDNSサーバーのアドレスを使う」をチェックします。
  6. IPアドレスに192.168.0.3、サブネットマスクに255.255.255.0を入力します。
     デフォルトゲートウェイ、優先DNSサーバーおよび代替DNSサーバーを空欄にし、OKをクリックします。
    /media/uploads/MasaoHamanaka/change_ip_jpn_5.png
Committer:
1050186
Date:
Tue Dec 25 09:57:54 2018 +0000
Revision:
23:e7fd26563f8f
Parent:
21:c7de71ccb5ca
Support Mbed OS 5.10, replace Renesas libraries to mbed-gr-libs and optimize main.cpp and related files for supporting GR-LYCHEE too.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:c5448e500c90 1 #include "mbed.h"
1050186 23:e7fd26563f8f 2 #include "EasyAttach_CameraAndLCD.h"
1050186 23:e7fd26563f8f 3 #include "dcache-control.h"
dkato 0:c5448e500c90 4 #include "JPEG_Converter.h"
dkato 0:c5448e500c90 5 #include "HTTPServer.h"
dkato 0:c5448e500c90 6 #include "mbed_rpc.h"
dkato 21:c7de71ccb5ca 7 #include "FATFileSystem.h"
dkato 21:c7de71ccb5ca 8 #include "RomRamBlockDevice.h"
1050186 23:e7fd26563f8f 9 #include "SDBlockDevice_GRBoard.h"
1050186 23:e7fd26563f8f 10 #if defined(TARGET_RZ_A1H)
1050186 23:e7fd26563f8f 11 #include "file_table_peach.h" //Binary data of web pages
1050186 23:e7fd26563f8f 12 #elif defined(TARGET_GR_LYCHEE)
1050186 23:e7fd26563f8f 13 #include "file_table_lychee.h" //Binary data of web pages
1050186 23:e7fd26563f8f 14 #endif
1050186 5:34d84609dd60 15 #include "i2c_setting.h"
dkato 0:c5448e500c90 16
dkato 0:c5448e500c90 17 /**** User Selection *********/
dkato 11:ad8ff26679bb 18 /** Network setting **/
dkato 11:ad8ff26679bb 19 #define USE_DHCP (1) /* Select 0(static configuration) or 1(use DHCP) */
dkato 11:ad8ff26679bb 20 #if (USE_DHCP == 0)
dkato 11:ad8ff26679bb 21 #define IP_ADDRESS ("192.168.0.2") /* IP address */
dkato 11:ad8ff26679bb 22 #define SUBNET_MASK ("255.255.255.0") /* Subnet mask */
dkato 11:ad8ff26679bb 23 #define DEFAULT_GATEWAY ("192.168.0.3") /* Default gateway */
dkato 11:ad8ff26679bb 24 #endif
1050186 23:e7fd26563f8f 25 #define NETWORK_TYPE (0) /* Select 0(Ethernet), 1(BP3595), 2(ESP32 STA) ,3(ESP32 AP) */
1050186 23:e7fd26563f8f 26 #if (NETWORK_TYPE >= 1)
dkato 17:2648bcf3f2cc 27 #define SCAN_NETWORK (1) /* Select 0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */
dkato 15:eac4c3711aab 28 #define WLAN_SSID ("SSIDofYourAP") /* SSID */
dkato 15:eac4c3711aab 29 #define WLAN_PSK ("PSKofYourAP") /* PSK(Pre-Shared Key) */
dkato 17:2648bcf3f2cc 30 #define WLAN_SECURITY NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */
dkato 15:eac4c3711aab 31 #endif
1050186 23:e7fd26563f8f 32 /** JPEG out setting **/
1050186 23:e7fd26563f8f 33 #define JPEG_ENCODE_QUALITY (75) /* JPEG encode quality (min:1, max:75 (Considering the size of JpegBuffer, about 75 is the upper limit.)) */
1050186 23:e7fd26563f8f 34 #define VFIELD_INT_SKIP_CNT (0) /* A guide for GR-LYCHEE. 0:60fps, 1:30fps, 2:20fps, 3:15fps, 4:12fps, 5:10fps */
dkato 0:c5448e500c90 35 /*****************************/
dkato 0:c5448e500c90 36
dkato 15:eac4c3711aab 37 #if (NETWORK_TYPE == 0)
dkato 15:eac4c3711aab 38 #include "EthernetInterface.h"
dkato 15:eac4c3711aab 39 EthernetInterface network;
dkato 15:eac4c3711aab 40 #elif (NETWORK_TYPE == 1)
1050186 23:e7fd26563f8f 41 #error "Not supported"
1050186 23:e7fd26563f8f 42 #elif (NETWORK_TYPE == 2)
1050186 23:e7fd26563f8f 43 #include "ESP32Interface.h"
1050186 23:e7fd26563f8f 44 #if defined(TARGET_RZ_A1H)
1050186 23:e7fd26563f8f 45 ESP32Interface network(P3_10, P3_9, P2_14, P2_15);
1050186 23:e7fd26563f8f 46 #elif defined(TARGET_GR_LYCHEE)
1050186 23:e7fd26563f8f 47 ESP32Interface network(P5_3, P3_14, P7_1, P0_1);
1050186 23:e7fd26563f8f 48 #endif
1050186 23:e7fd26563f8f 49 #elif (NETWORK_TYPE == 3)
1050186 23:e7fd26563f8f 50 #include "ESP32InterfaceAP.h"
1050186 23:e7fd26563f8f 51 #if defined(TARGET_RZ_A1H)
1050186 23:e7fd26563f8f 52 ESP32InterfaceAP network(P3_10, P3_9, P2_14, P2_15);
1050186 23:e7fd26563f8f 53 #elif defined(TARGET_GR_LYCHEE)
1050186 23:e7fd26563f8f 54 ESP32InterfaceAP network(P5_3, P3_14, P7_1, P0_1);
1050186 23:e7fd26563f8f 55 #endif
dkato 15:eac4c3711aab 56 #else
dkato 15:eac4c3711aab 57 #error NETWORK_TYPE error
dkato 15:eac4c3711aab 58 #endif /* NETWORK_TYPE */
1050186 23:e7fd26563f8f 59
1050186 23:e7fd26563f8f 60 /* Video input and LCD layer 0 output */
1050186 23:e7fd26563f8f 61 #define VIDEO_FORMAT (DisplayBase::VIDEO_FORMAT_YCBCR422)
1050186 23:e7fd26563f8f 62 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_YCBCR422)
1050186 23:e7fd26563f8f 63 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_32_16BIT)
1050186 23:e7fd26563f8f 64 #define DATA_SIZE_PER_PIC (2u)
1050186 23:e7fd26563f8f 65
1050186 23:e7fd26563f8f 66 /*! Frame buffer stride: Frame buffer stride should be set to a multiple of 32 or 128
1050186 23:e7fd26563f8f 67 in accordance with the frame buffer burst transfer mode. */
1050186 23:e7fd26563f8f 68 #define VIDEO_PIXEL_HW (320u) /* QVGA */
1050186 23:e7fd26563f8f 69 #define VIDEO_PIXEL_VW (240u) /* QVGA */
1050186 23:e7fd26563f8f 70
1050186 23:e7fd26563f8f 71 #define FRAME_BUFFER_STRIDE (((VIDEO_PIXEL_HW * DATA_SIZE_PER_PIC) + 31u) & ~31u)
1050186 23:e7fd26563f8f 72 #define FRAME_BUFFER_HEIGHT (VIDEO_PIXEL_VW)
1050186 23:e7fd26563f8f 73
1050186 23:e7fd26563f8f 74 DisplayBase Display;
dkato 0:c5448e500c90 75
dkato 14:212f66386982 76 #if defined(__ICCARM__)
1050186 23:e7fd26563f8f 77 #pragma data_alignment=32
1050186 23:e7fd26563f8f 78 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]@ ".mirrorram";
dkato 14:212f66386982 79 #else
1050186 23:e7fd26563f8f 80 static uint8_t user_frame_buffer0[FRAME_BUFFER_STRIDE * FRAME_BUFFER_HEIGHT]__attribute((section("NC_BSS"),aligned(32)));
dkato 14:212f66386982 81 #endif
1050186 23:e7fd26563f8f 82
1050186 23:e7fd26563f8f 83 FATFileSystem fs("storage");
1050186 23:e7fd26563f8f 84 RomRamBlockDevice romram_bd(512000, 512);
1050186 23:e7fd26563f8f 85 SDBlockDevice_GRBoard sd;
1050186 23:e7fd26563f8f 86 Serial pc(USBTX, USBRX);
1050186 23:e7fd26563f8f 87 Thread sdConnectTask;
1050186 23:e7fd26563f8f 88
dkato 14:212f66386982 89 #if defined(__ICCARM__)
1050186 23:e7fd26563f8f 90 #pragma data_alignment=32
1050186 23:e7fd26563f8f 91 static uint8_t JpegBuffer[2][1024 * 64];
dkato 14:212f66386982 92 #else
1050186 23:e7fd26563f8f 93 static uint8_t JpegBuffer[2][1024 * 64]__attribute((aligned(32)));
dkato 14:212f66386982 94 #endif
dkato 1:ebff3aeb40a0 95 static size_t jcu_encode_size[2];
dkato 0:c5448e500c90 96 static int image_change = 0;
dkato 1:ebff3aeb40a0 97 JPEG_Converter Jcu;
dkato 1:ebff3aeb40a0 98 static int jcu_buf_index_write = 0;
dkato 1:ebff3aeb40a0 99 static int jcu_buf_index_write_done = 0;
dkato 1:ebff3aeb40a0 100 static int jcu_buf_index_read = 0;
dkato 1:ebff3aeb40a0 101 static int jcu_encoding = 0;
1050186 23:e7fd26563f8f 102 static int Vfield_Int_Cnt = 0;
dkato 7:c45ecff1b44d 103 static char i2c_setting_str_buf[I2C_SETTING_STR_BUF_SIZE];
dkato 1:ebff3aeb40a0 104
dkato 1:ebff3aeb40a0 105 static void JcuEncodeCallBackFunc(JPEG_Converter::jpeg_conv_error_t err_code) {
1050186 23:e7fd26563f8f 106 if (err_code == JPEG_Converter::JPEG_CONV_OK) {
1050186 23:e7fd26563f8f 107 jcu_buf_index_write_done = jcu_buf_index_write;
1050186 23:e7fd26563f8f 108 image_change = 1;
dkato 0:c5448e500c90 109 }
1050186 23:e7fd26563f8f 110 jcu_encoding = 0;
dkato 0:c5448e500c90 111 }
dkato 0:c5448e500c90 112
dkato 0:c5448e500c90 113 static int snapshot_req(const char ** pp_data) {
dkato 1:ebff3aeb40a0 114 int encode_size;
dkato 0:c5448e500c90 115
dkato 1:ebff3aeb40a0 116 while ((jcu_encoding == 1) || (image_change == 0)) {
1050186 23:e7fd26563f8f 117 ThisThread::sleep_for(1);
dkato 0:c5448e500c90 118 }
dkato 1:ebff3aeb40a0 119 jcu_buf_index_read = jcu_buf_index_write_done;
dkato 0:c5448e500c90 120 image_change = 0;
dkato 0:c5448e500c90 121
dkato 1:ebff3aeb40a0 122 *pp_data = (const char *)JpegBuffer[jcu_buf_index_read];
dkato 1:ebff3aeb40a0 123 encode_size = (int)jcu_encode_size[jcu_buf_index_read];
dkato 0:c5448e500c90 124
dkato 1:ebff3aeb40a0 125 return encode_size;
dkato 0:c5448e500c90 126 }
dkato 0:c5448e500c90 127
1050186 23:e7fd26563f8f 128 static void IntCallbackFunc_Vfield(DisplayBase::int_type_t int_type) {
1050186 23:e7fd26563f8f 129 if (Vfield_Int_Cnt < VFIELD_INT_SKIP_CNT) {
1050186 23:e7fd26563f8f 130 Vfield_Int_Cnt++;
1050186 23:e7fd26563f8f 131 return;
1050186 23:e7fd26563f8f 132 }
1050186 23:e7fd26563f8f 133 Vfield_Int_Cnt = 0;
1050186 23:e7fd26563f8f 134
1050186 23:e7fd26563f8f 135 //Interrupt callback function
1050186 23:e7fd26563f8f 136 if (jcu_encoding == 0) {
1050186 23:e7fd26563f8f 137 JPEG_Converter::bitmap_buff_info_t bitmap_buff_info;
1050186 23:e7fd26563f8f 138 JPEG_Converter::encode_options_t encode_options;
1050186 23:e7fd26563f8f 139
1050186 23:e7fd26563f8f 140 bitmap_buff_info.width = VIDEO_PIXEL_HW;
1050186 23:e7fd26563f8f 141 bitmap_buff_info.height = VIDEO_PIXEL_VW;
1050186 23:e7fd26563f8f 142 bitmap_buff_info.format = JPEG_Converter::WR_RD_YCbCr422;
1050186 23:e7fd26563f8f 143 bitmap_buff_info.buffer_address = (void *)user_frame_buffer0;
1050186 23:e7fd26563f8f 144
1050186 23:e7fd26563f8f 145 encode_options.encode_buff_size = sizeof(JpegBuffer[0]);
1050186 23:e7fd26563f8f 146 encode_options.p_EncodeCallBackFunc = &JcuEncodeCallBackFunc;
1050186 23:e7fd26563f8f 147 encode_options.input_swapsetting = JPEG_Converter::WR_RD_WRSWA_32_16_8BIT;
1050186 23:e7fd26563f8f 148
1050186 23:e7fd26563f8f 149 jcu_encoding = 1;
1050186 23:e7fd26563f8f 150 if (jcu_buf_index_read == jcu_buf_index_write) {
1050186 23:e7fd26563f8f 151 jcu_buf_index_write ^= 1; // toggle
1050186 23:e7fd26563f8f 152 }
1050186 23:e7fd26563f8f 153 jcu_encode_size[jcu_buf_index_write] = 0;
1050186 23:e7fd26563f8f 154 dcache_invalid(JpegBuffer[jcu_buf_index_write], sizeof(JpegBuffer[0]));
1050186 23:e7fd26563f8f 155 if (Jcu.encode(&bitmap_buff_info, JpegBuffer[jcu_buf_index_write],
1050186 23:e7fd26563f8f 156 &jcu_encode_size[jcu_buf_index_write], &encode_options) != JPEG_Converter::JPEG_CONV_OK) {
1050186 23:e7fd26563f8f 157 jcu_encode_size[jcu_buf_index_write] = 0;
1050186 23:e7fd26563f8f 158 jcu_encoding = 0;
1050186 23:e7fd26563f8f 159 }
1050186 23:e7fd26563f8f 160 }
1050186 23:e7fd26563f8f 161 }
1050186 23:e7fd26563f8f 162
1050186 23:e7fd26563f8f 163 static void Start_Video_Camera(void) {
1050186 23:e7fd26563f8f 164 // Video capture setting (progressive form fixed)
1050186 23:e7fd26563f8f 165 Display.Video_Write_Setting(
1050186 23:e7fd26563f8f 166 DisplayBase::VIDEO_INPUT_CHANNEL_0,
1050186 23:e7fd26563f8f 167 DisplayBase::COL_SYS_NTSC_358,
1050186 23:e7fd26563f8f 168 (void *)user_frame_buffer0,
1050186 23:e7fd26563f8f 169 FRAME_BUFFER_STRIDE,
1050186 23:e7fd26563f8f 170 VIDEO_FORMAT,
1050186 23:e7fd26563f8f 171 WR_RD_WRSWA,
1050186 23:e7fd26563f8f 172 VIDEO_PIXEL_VW,
1050186 23:e7fd26563f8f 173 VIDEO_PIXEL_HW
1050186 23:e7fd26563f8f 174 );
1050186 23:e7fd26563f8f 175 EasyAttach_CameraStart(Display, DisplayBase::VIDEO_INPUT_CHANNEL_0);
1050186 23:e7fd26563f8f 176 }
1050186 23:e7fd26563f8f 177
dkato 0:c5448e500c90 178 static void TerminalWrite(Arguments* arg, Reply* r) {
dkato 16:b5469a6226c7 179 if ((arg != NULL) && (r != NULL)) {
dkato 16:b5469a6226c7 180 for (int i = 0; i < arg->argc; i++) {
dkato 16:b5469a6226c7 181 if (arg->argv[i] != NULL) {
dkato 16:b5469a6226c7 182 printf("%s", arg->argv[i]);
dkato 16:b5469a6226c7 183 }
dkato 16:b5469a6226c7 184 }
dkato 16:b5469a6226c7 185 printf("\n");
dkato 16:b5469a6226c7 186 r->putData<const char*>("ok");
dkato 16:b5469a6226c7 187 }
dkato 0:c5448e500c90 188 }
dkato 0:c5448e500c90 189
dkato 0:c5448e500c90 190 static void mount_romramfs(void) {
dkato 0:c5448e500c90 191 FILE * fp;
dkato 0:c5448e500c90 192
dkato 21:c7de71ccb5ca 193 romram_bd.SetRomAddr(0x18000000, 0x1FFFFFFF);
dkato 21:c7de71ccb5ca 194 fs.format(&romram_bd, 512);
dkato 21:c7de71ccb5ca 195 fs.mount(&romram_bd);
dkato 0:c5448e500c90 196
dkato 12:6c002b871c4d 197 //index.htm
dkato 21:c7de71ccb5ca 198 fp = fopen("/storage/index.htm", "w");
dkato 12:6c002b871c4d 199 fwrite(index_htm_tbl, sizeof(char), sizeof(index_htm_tbl), fp);
dkato 12:6c002b871c4d 200 fclose(fp);
dkato 12:6c002b871c4d 201
dkato 0:c5448e500c90 202 //camera.js
dkato 21:c7de71ccb5ca 203 fp = fopen("/storage/camera.js", "w");
dkato 0:c5448e500c90 204 fwrite(camaera_js_tbl, sizeof(char), sizeof(camaera_js_tbl), fp);
dkato 0:c5448e500c90 205 fclose(fp);
dkato 0:c5448e500c90 206
dkato 0:c5448e500c90 207 //camera.htm
dkato 21:c7de71ccb5ca 208 fp = fopen("/storage/camera.htm", "w");
dkato 0:c5448e500c90 209 fwrite(camera_htm_tbl, sizeof(char), sizeof(camera_htm_tbl), fp);
dkato 0:c5448e500c90 210 fclose(fp);
dkato 0:c5448e500c90 211
dkato 0:c5448e500c90 212 //mbedrpc.js
dkato 21:c7de71ccb5ca 213 fp = fopen("/storage/mbedrpc.js", "w");
dkato 0:c5448e500c90 214 fwrite(mbedrpc_js_tbl, sizeof(char), sizeof(mbedrpc_js_tbl), fp);
dkato 0:c5448e500c90 215 fclose(fp);
dkato 0:c5448e500c90 216
dkato 0:c5448e500c90 217 //led.htm
dkato 21:c7de71ccb5ca 218 fp = fopen("/storage/led.htm", "w");
dkato 0:c5448e500c90 219 fwrite(led_htm_tbl, sizeof(char), sizeof(led_htm_tbl), fp);
dkato 0:c5448e500c90 220 fclose(fp);
1050186 5:34d84609dd60 221
1050186 5:34d84609dd60 222 //i2c_set.htm
dkato 21:c7de71ccb5ca 223 fp = fopen("/storage/i2c_set.htm", "w");
1050186 5:34d84609dd60 224 fwrite(i2c_set_htm_tbl, sizeof(char), sizeof(i2c_set_htm_tbl), fp);
1050186 5:34d84609dd60 225 fclose(fp);
1050186 5:34d84609dd60 226
1050186 5:34d84609dd60 227 //web_top.htm
dkato 21:c7de71ccb5ca 228 fp = fopen("/storage/web_top.htm", "w");
1050186 5:34d84609dd60 229 fwrite(web_top_htm_tbl, sizeof(char), sizeof(web_top_htm_tbl), fp);
1050186 5:34d84609dd60 230 fclose(fp);
1050186 5:34d84609dd60 231
1050186 5:34d84609dd60 232 //menu.htm
dkato 21:c7de71ccb5ca 233 fp = fopen("/storage/menu.htm", "w");
1050186 5:34d84609dd60 234 fwrite(menu_htm_tbl, sizeof(char), sizeof(menu_htm_tbl), fp);
1050186 5:34d84609dd60 235 fclose(fp);
1050186 5:34d84609dd60 236
1050186 5:34d84609dd60 237 //window.htm
dkato 21:c7de71ccb5ca 238 fp = fopen("/storage/window.htm", "w");
1050186 5:34d84609dd60 239 fwrite(window_htm_tbl, sizeof(char), sizeof(window_htm_tbl), fp);
1050186 5:34d84609dd60 240 fclose(fp);
1050186 5:34d84609dd60 241 }
1050186 5:34d84609dd60 242
1050186 5:34d84609dd60 243 static void SetI2CfromWeb(Arguments* arg, Reply* r) {
1050186 10:3a176dc33f74 244 int result = 0;
1050186 10:3a176dc33f74 245
1050186 10:3a176dc33f74 246 if (arg != NULL) {
1050186 10:3a176dc33f74 247 if (arg->argc >= 2) {
1050186 10:3a176dc33f74 248 if ((arg->argv[0] != NULL) && (arg->argv[1] != NULL)) {
1050186 10:3a176dc33f74 249 sprintf(i2c_setting_str_buf, "%s,%s", arg->argv[0], arg->argv[1]);
1050186 10:3a176dc33f74 250 result = 1;
1050186 10:3a176dc33f74 251 }
1050186 10:3a176dc33f74 252 } else if (arg->argc == 1) {
1050186 10:3a176dc33f74 253 if (arg->argv[0] != NULL) {
1050186 10:3a176dc33f74 254 sprintf(i2c_setting_str_buf, "%s", arg->argv[0]);
1050186 10:3a176dc33f74 255 result = 1;
1050186 10:3a176dc33f74 256 }
1050186 10:3a176dc33f74 257 } else {
1050186 10:3a176dc33f74 258 /* Do nothing */
1050186 10:3a176dc33f74 259 }
dkato 7:c45ecff1b44d 260 /* command analysis and execute */
1050186 10:3a176dc33f74 261 if (result != 0) {
1050186 10:3a176dc33f74 262 if (i2c_setting_exe(i2c_setting_str_buf) != false) {
1050186 10:3a176dc33f74 263 r->putData<const char*>(i2c_setting_str_buf);
1050186 10:3a176dc33f74 264 }
1050186 5:34d84609dd60 265 }
1050186 5:34d84609dd60 266 }
dkato 0:c5448e500c90 267 }
dkato 0:c5448e500c90 268
1050186 23:e7fd26563f8f 269 #if (SCAN_NETWORK == 1) && (NETWORK_TYPE != 3)
dkato 21:c7de71ccb5ca 270 static const char *sec2str(nsapi_security_t sec) {
dkato 21:c7de71ccb5ca 271 switch (sec) {
dkato 21:c7de71ccb5ca 272 case NSAPI_SECURITY_NONE:
dkato 21:c7de71ccb5ca 273 return "None";
dkato 21:c7de71ccb5ca 274 case NSAPI_SECURITY_WEP:
dkato 21:c7de71ccb5ca 275 return "WEP";
dkato 21:c7de71ccb5ca 276 case NSAPI_SECURITY_WPA:
dkato 21:c7de71ccb5ca 277 return "WPA";
dkato 21:c7de71ccb5ca 278 case NSAPI_SECURITY_WPA2:
dkato 21:c7de71ccb5ca 279 return "WPA2";
dkato 21:c7de71ccb5ca 280 case NSAPI_SECURITY_WPA_WPA2:
dkato 21:c7de71ccb5ca 281 return "WPA/WPA2";
dkato 21:c7de71ccb5ca 282 case NSAPI_SECURITY_UNKNOWN:
dkato 21:c7de71ccb5ca 283 default:
dkato 21:c7de71ccb5ca 284 return "Unknown";
dkato 21:c7de71ccb5ca 285 }
dkato 21:c7de71ccb5ca 286 }
dkato 21:c7de71ccb5ca 287
dkato 21:c7de71ccb5ca 288 static bool scan_network(WiFiInterface *wifi) {
dkato 21:c7de71ccb5ca 289 WiFiAccessPoint *ap;
dkato 21:c7de71ccb5ca 290 bool ret = false;
dkato 17:2648bcf3f2cc 291 int i;
1050186 23:e7fd26563f8f 292 int count = 10; /* Limit number of network arbitrary to 10 */
dkato 21:c7de71ccb5ca 293
dkato 21:c7de71ccb5ca 294 printf("Scan:\r\n");
dkato 21:c7de71ccb5ca 295 ap = new WiFiAccessPoint[count];
1050186 23:e7fd26563f8f 296 if (ap == NULL) {
1050186 23:e7fd26563f8f 297 printf("memory error\r\n");
1050186 23:e7fd26563f8f 298 return 0;
1050186 23:e7fd26563f8f 299 }
dkato 21:c7de71ccb5ca 300 count = wifi->scan(ap, count);
dkato 21:c7de71ccb5ca 301 for (i = 0; i < count; i++) {
1050186 23:e7fd26563f8f 302 printf("No.%d Network: %s secured: %s BSSID: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx RSSI: %hhd Ch: %hhd\r\n",
1050186 23:e7fd26563f8f 303 i, ap[i].get_ssid(), sec2str(ap[i].get_security()),
1050186 23:e7fd26563f8f 304 ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2], ap[i].get_bssid()[3],
1050186 23:e7fd26563f8f 305 ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
dkato 21:c7de71ccb5ca 306 }
dkato 21:c7de71ccb5ca 307 printf("%d networks available.\r\n", count);
dkato 17:2648bcf3f2cc 308
dkato 21:c7de71ccb5ca 309 if (count > 0) {
dkato 21:c7de71ccb5ca 310 char c;
dkato 21:c7de71ccb5ca 311 char pass[64];
dkato 21:c7de71ccb5ca 312 int select_no;
dkato 21:c7de71ccb5ca 313 bool loop_break = false;;
dkato 21:c7de71ccb5ca 314
dkato 21:c7de71ccb5ca 315 printf("\nPlease enter the number of the network you want to connect.\r\n");
dkato 21:c7de71ccb5ca 316 printf("Enter key:[0]-[%d], (If inputting the other key, it's scanned again.)\r\n", count - 1);
dkato 21:c7de71ccb5ca 317 c = (uint8_t)pc.getc();
dkato 21:c7de71ccb5ca 318 select_no = c - 0x30;
dkato 21:c7de71ccb5ca 319 if ((select_no >= 0) && (select_no < count)) {
dkato 21:c7de71ccb5ca 320 printf("[%s] is selected.\r\n", ap[select_no].get_ssid());
dkato 21:c7de71ccb5ca 321 printf("Please enter the PSK.\r\n");
dkato 21:c7de71ccb5ca 322 i = 0;
dkato 21:c7de71ccb5ca 323 while (loop_break == false) {
dkato 21:c7de71ccb5ca 324 c = (uint8_t)pc.getc();
dkato 21:c7de71ccb5ca 325 switch (c) {
dkato 21:c7de71ccb5ca 326 case 0x0D:
dkato 21:c7de71ccb5ca 327 pass[i] = '\0';
dkato 21:c7de71ccb5ca 328 pc.puts("\r\n");
dkato 21:c7de71ccb5ca 329 loop_break = true;
dkato 21:c7de71ccb5ca 330 break;
dkato 21:c7de71ccb5ca 331 case 0x08:
dkato 21:c7de71ccb5ca 332 if (i > 0) {
dkato 21:c7de71ccb5ca 333 pc.puts("\b \b");
dkato 21:c7de71ccb5ca 334 i--;
dkato 21:c7de71ccb5ca 335 }
dkato 21:c7de71ccb5ca 336 break;
dkato 21:c7de71ccb5ca 337 case 0x0A:
dkato 21:c7de71ccb5ca 338 break;
dkato 21:c7de71ccb5ca 339 default:
dkato 21:c7de71ccb5ca 340 if ((i + 1) < sizeof(pass)) {
dkato 21:c7de71ccb5ca 341 pass[i] = c;
dkato 21:c7de71ccb5ca 342 i++;
dkato 21:c7de71ccb5ca 343 pc.putc(c);
dkato 21:c7de71ccb5ca 344 }
dkato 21:c7de71ccb5ca 345 break;
dkato 21:c7de71ccb5ca 346 }
dkato 17:2648bcf3f2cc 347 }
dkato 21:c7de71ccb5ca 348 wifi->set_credentials(ap[select_no].get_ssid(), pass, ap[select_no].get_security());
dkato 21:c7de71ccb5ca 349 ret = true;
dkato 17:2648bcf3f2cc 350 }
dkato 17:2648bcf3f2cc 351 }
dkato 21:c7de71ccb5ca 352
dkato 21:c7de71ccb5ca 353 delete[] ap;
dkato 21:c7de71ccb5ca 354
dkato 21:c7de71ccb5ca 355 return ret;
dkato 17:2648bcf3f2cc 356 }
dkato 17:2648bcf3f2cc 357 #endif
dkato 17:2648bcf3f2cc 358
1050186 23:e7fd26563f8f 359 static void sd_connect_task(void) {
1050186 23:e7fd26563f8f 360 int storage_type = 0;
1050186 23:e7fd26563f8f 361
1050186 23:e7fd26563f8f 362 while (1) {
1050186 23:e7fd26563f8f 363 if (storage_type == 0) {
1050186 23:e7fd26563f8f 364 if (sd.connect()) {
1050186 23:e7fd26563f8f 365 fs.unmount();
1050186 23:e7fd26563f8f 366 fs.mount(&sd);
1050186 23:e7fd26563f8f 367 storage_type = 1;
1050186 23:e7fd26563f8f 368 printf("SDBlockDevice\r\n");
1050186 23:e7fd26563f8f 369 }
1050186 23:e7fd26563f8f 370 } else {
1050186 23:e7fd26563f8f 371 if (sd.connected() == false) {
1050186 23:e7fd26563f8f 372 fs.unmount();
1050186 23:e7fd26563f8f 373 fs.mount(&romram_bd);
1050186 23:e7fd26563f8f 374 storage_type = 0;
1050186 23:e7fd26563f8f 375 printf("RomRamBlockDevice\r\n");
1050186 23:e7fd26563f8f 376 }
1050186 23:e7fd26563f8f 377 }
1050186 23:e7fd26563f8f 378 ThisThread::sleep_for(250);
1050186 23:e7fd26563f8f 379 }
1050186 23:e7fd26563f8f 380 }
1050186 23:e7fd26563f8f 381
dkato 0:c5448e500c90 382 int main(void) {
dkato 0:c5448e500c90 383 printf("********* PROGRAM START ***********\r\n");
dkato 0:c5448e500c90 384
1050186 23:e7fd26563f8f 385 mount_romramfs(); //RomRamFileSystem Mount
1050186 23:e7fd26563f8f 386
1050186 23:e7fd26563f8f 387 sdConnectTask.start(&sd_connect_task);
1050186 5:34d84609dd60 388
1050186 23:e7fd26563f8f 389 EasyAttach_Init(Display);
1050186 23:e7fd26563f8f 390 Jcu.SetQuality(JPEG_ENCODE_QUALITY);
1050186 23:e7fd26563f8f 391 // Interrupt callback function setting (Field end signal for recording function in scaler 0)
1050186 23:e7fd26563f8f 392 Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_VFIELD, 0, IntCallbackFunc_Vfield);
1050186 23:e7fd26563f8f 393 Start_Video_Camera();
dkato 0:c5448e500c90 394
dkato 0:c5448e500c90 395 RPC::add_rpc_class<RpcDigitalOut>();
dkato 0:c5448e500c90 396 RPCFunction rpcFunc(TerminalWrite, "TerminalWrite");
1050186 5:34d84609dd60 397 RPCFunction rpcSetI2C(SetI2CfromWeb, "SetI2CfromWeb");
dkato 0:c5448e500c90 398
1050186 23:e7fd26563f8f 399 #if defined(TARGET_RZ_A1H) && (NETWORK_TYPE == 1)
dkato 15:eac4c3711aab 400 //Audio Camera Shield USB1 enable for WlanBP3595
1050186 23:e7fd26563f8f 401 DigitalOut usb1en(P3_8);
dkato 15:eac4c3711aab 402 usb1en = 1; //Outputs high level
1050186 23:e7fd26563f8f 403 ThisThread::sleep_for(5);
dkato 15:eac4c3711aab 404 usb1en = 0; //Outputs low level
1050186 23:e7fd26563f8f 405 ThisThread::sleep_for(5);
dkato 15:eac4c3711aab 406 #endif
dkato 15:eac4c3711aab 407
dkato 11:ad8ff26679bb 408 printf("Network Setting up...\r\n");
dkato 17:2648bcf3f2cc 409 #if (USE_DHCP == 0)
dkato 17:2648bcf3f2cc 410 network.set_dhcp(false);
dkato 17:2648bcf3f2cc 411 if (network.set_network(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
dkato 17:2648bcf3f2cc 412 printf("Network Set Network Error \r\n");
dkato 0:c5448e500c90 413 }
dkato 17:2648bcf3f2cc 414 #endif
1050186 23:e7fd26563f8f 415
1050186 23:e7fd26563f8f 416 #if (NETWORK_TYPE >= 1)
1050186 23:e7fd26563f8f 417 #if (SCAN_NETWORK == 1) && (NETWORK_TYPE != 3)
dkato 21:c7de71ccb5ca 418 while (!scan_network(&network));
dkato 15:eac4c3711aab 419 #else
dkato 17:2648bcf3f2cc 420 network.set_credentials(WLAN_SSID, WLAN_PSK, WLAN_SECURITY);
dkato 17:2648bcf3f2cc 421 #endif
dkato 15:eac4c3711aab 422 #endif
1050186 23:e7fd26563f8f 423
1050186 23:e7fd26563f8f 424 printf("\r\nConnecting...\r\n");
dkato 17:2648bcf3f2cc 425 if (network.connect() != 0) {
dkato 11:ad8ff26679bb 426 printf("Network Connect Error \r\n");
dkato 0:c5448e500c90 427 return -1;
dkato 0:c5448e500c90 428 }
dkato 18:0461a79ced71 429 printf("MAC Address is %s\r\n", network.get_mac_address());
dkato 17:2648bcf3f2cc 430 printf("IP Address is %s\r\n", network.get_ip_address());
dkato 17:2648bcf3f2cc 431 printf("NetMask is %s\r\n", network.get_netmask());
dkato 17:2648bcf3f2cc 432 printf("Gateway Address is %s\r\n", network.get_gateway());
dkato 11:ad8ff26679bb 433 printf("Network Setup OK\r\n");
dkato 0:c5448e500c90 434
dkato 0:c5448e500c90 435 SnapshotHandler::attach_req(&snapshot_req);
dkato 0:c5448e500c90 436 HTTPServerAddHandler<SnapshotHandler>("/camera"); //Camera
dkato 21:c7de71ccb5ca 437 FSHandler::mount("/storage", "/");
dkato 0:c5448e500c90 438 HTTPServerAddHandler<FSHandler>("/");
dkato 0:c5448e500c90 439 HTTPServerAddHandler<RPCHandler>("/rpc");
dkato 17:2648bcf3f2cc 440 HTTPServerStart(&network, 80);
dkato 0:c5448e500c90 441 }