Camera_PCStreaming with WIZwiki-W7500

Dependencies:   CameraC328 WIZnetInterface_Ricky mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "EthernetInterface.h"
00003 #include "CameraC328.h"
00004 
00005 /* CAMERA */
00006 #define USE_JPEG_HIGH_RESOLUTION    2//1=80x64 <--- not working -_-;;, 2=160x128, 3=320x240, 4=640x480
00007 #define START                       "start"
00008 #define END                         "end"
00009 CameraC328 camera(PA_13, PA_14, CameraC328::Baud115200);
00010 
00011 /* TCP/IP */
00012 static char buf[1024];
00013 const char dest_ip[] = "192.168.0.11";
00014 int dest_port = 1212;
00015 
00016 uint8_t mac_addr[6] = {0x00, 0x08, 0xdc, 0x12, 0x34, 0x45};
00017 const char ip_addr[] = "192.168.0.200"; 
00018 const char mask_addr[] = "255.255.255.0"; 
00019 const char gateway_addr[] = "192.168.0.1"; 
00020 
00021 EthernetInterface eth;
00022 TCPSocketConnection Streaming;
00023 
00024 /* UART */
00025 Serial pc(USBTX, USBRX);
00026 
00027 /* Function*/ 
00028 void jpeg_callback(char *buf, size_t siz);
00029 void sync(void);
00030 void test_jpeg_snapshot_picture(void);
00031 void init(void);
00032 
00033 int main() {
00034 
00035     printf("Hello WIZwiki-W7500 Camera PCStreaming World!\r\n"); 
00036       
00037     eth.init(mac_addr, ip_addr, mask_addr, gateway_addr); //Use Static
00038     eth.connect();
00039     sync();
00040     init();
00041     while (Streaming.connect(dest_ip, dest_port) < 0) {
00042         printf("Unable to connect to (%s) on port (%d)\r\n", dest_ip, dest_port);
00043         wait(1);
00044     }
00045     
00046     while(true)
00047     {
00048         int n = Streaming.receive(buf, sizeof(buf));
00049         buf[n] = '\0';
00050             
00051         Streaming.send(START, sizeof(START)-1);
00052         test_jpeg_snapshot_picture();
00053         Streaming.send(END, sizeof(END)-1); 
00054         
00055         
00056         /*    
00057         if (!strncmp(buf, "123", 3)){
00058         }
00059         else if(!strncmp(buf, "220", 3)){
00060         }
00061         else if(!strncmp(buf, "789", 3)){
00062         }
00063         */
00064     }
00065 }
00066 
00067 void jpeg_callback(char *buf, size_t siz) {
00068     //for (int i = 0; i < (int)siz; i++) {
00069         //fprintf(fp_jpeg, "%c", buf[i]);
00070         Streaming.send(buf, siz);
00071     //}
00072 }
00073 void sync(void) {
00074     CameraC328::ErrorNumber err = CameraC328::NoError;
00075 
00076     err = camera.sync();
00077     if (CameraC328::NoError == err) {
00078         printf("[ OK ] : CameraC328::sync\r\n");
00079     } else {
00080         printf("[FAIL] : CameraC328::sync (Error=%02X)\r\n", (int)err);
00081     }
00082 }
00083 void test_jpeg_snapshot_picture() {
00084     CameraC328::ErrorNumber err = CameraC328::NoError;
00085 
00086     err = camera.getJpegSnapshotPicture(jpeg_callback);
00087     if (CameraC328::NoError == err) {
00088         printf("[ OK ] : CameraC328::getJpegSnapshotPicture\r\n");
00089     } else {
00090         printf("[FAIL] : CameraC328::getJpegSnapshotPicture (Error=%02X)\r\n", (int)err);
00091     }
00092 }
00093 void init()
00094 {
00095     CameraC328::ErrorNumber err = CameraC328::NoError;
00096 
00097 #if (USE_JPEG_HIGH_RESOLUTION==1)
00098     err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution80x64);
00099 #elif (USE_JPEG_HIGH_RESOLUTION==2)
00100     err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution160x128);
00101 #elif (USE_JPEG_HIGH_RESOLUTION==3)
00102     err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution320x240);
00103 #elif (USE_JPEG_HIGH_RESOLUTION==4)
00104     err = camera.init(CameraC328::Jpeg, CameraC328::RawResolution80x60, CameraC328::JpegResolution640x480);
00105 #endif
00106     if (CameraC328::NoError == err) {
00107         printf("[ OK ] : CameraC328::init\r\n");
00108     } else {
00109         printf("[FAIL] : CameraC328::init (Error=%02X)\r\n", (int)err);
00110     }
00111 }