Control.cpp ( File view )

  • By rarshion 2014-11-04
  • View(s):131
  • Download(s):3
  • Point(s): 2
			#include<iostream>
#include<cstring>
#include<list>
#include<string>
#include<stdio.h>
#include"ShareMemory.hpp"
#include"ShmIPS.hpp"
#include"Sem.hpp"
#include"IPC.hpp"
#include"IIPS.hpp"
#include"Common.hpp"
#include"struct.hpp"
#include "capture.h"
#include"Logger.hpp"
#include"Thread.hpp"
#include"Video.hpp"
#include"Functions.hpp"
#include"DeviceControl.hpp"

#include "capture.h"
#include "capvideo.h"

#include <time.h>


using namespace  std;

bool g_run_thread = false;
Video g_video;


void sendWater(struct shmCommand& com, string& ch)
{

    LOG_TRACE<<"control sendWater"<<endl;
    cout<<"control sendWater"<<endl;
    ch[0] = '7';
    ch[1] = '3';
    com.length = 2;

}


void sendTemp(struct shmCommand& com, std::string& str)
{

	LOG_TRACE<<"control sendTemp"<<endl;
	cout<<"control sendTemp"<<endl;

    str[0] = '2';
    str[1] = '8';

    com.length = 2;

}


void sendPicture(struct shmCommand& com, std::string& str, const char* pictureAttr)
{

   //std::cout<<"control the picture attribute lengtgh"<<(int)str.size()<<std::endl;


   struct  PhotoAttr photoa;

   //before use the pictureAttr, please sub 10..because the server
   //has added 10 on each attribute

    std::cout<<"control read the picture attribute"<<std::endl;


    photoa.resolution =(int)pictureAttr[0]-10;
    photoa.whitebalace = (int)pictureAttr[1]-10;
    photoa.bright = (int)pictureAttr[2]-10;
    photoa.contrast=(int)pictureAttr[3]-10;
    photoa.saturation=(int)pictureAttr[4]-10;
    photoa.quality=((int)pictureAttr[5]-10)*10;
    photoa.ligfrequency=((int)pictureAttr[6])-10;
    


    std::cout<<"resolutuion is "<<photoa.resolution<<std::endl;
    std::cout<<"whiteBalance is "<<photoa.whitebalace<<std::endl;
    std::cout<<"light is "<<photoa.bright <<std::endl;
    std::cout<<"constrast is "<<photoa.contrast<<std::endl;
    std::cout<<"saturation is "<<photoa.saturation<<std::endl;
    std::cout<<"quality is "<<photoa.quality<<std::endl;
    std::cout<<"ligfrency is"<<photoa.ligfrequency<<std::endl;

    switch(photoa.ligfrequency)
    {

        case 1:
	   std::cout<<"select 1 frency"<<std::endl;
	   
	   break;
        case 2:
	   std::cout<<"select 2 frency"<<std::endl;
           break;
	case 3:
	   std::cout<<"select 3 frency"<<std::endl;
	   break;
        default:
           break;
    
}


    capture_init(photoa,0);

    captureStart();

    str = capture();

    capture_uinit();
  
    com.length = str.size();

    std::cout<<"the image file is "<<str<<std::endl;

    Functions::Sleep(5000); //sleep 5 seconds

}

void* evePicture(void* arg)
{

   std::cout<<"control read the timepicture attribute"<<std::endl;

   TimerPhoto* timephotattr = static_cast<TimerPhoto*>(arg);

    struct PhotoAttr phtoattr;

    phtoattr = timephotattr->photoattr;
  
    std::cout<<"timehour is "<<timephotattr->eve_hour<<std::endl;     
    std::cout<<"timemin is "<<timephotattr->eve_min<<std::endl;

    std::cout<<"resolutuion is "<<phtoattr.resolution<<std::endl;
    std::cout<<"whiteBalance is "<<phtoattr.whitebalace<<std::endl;
    std::cout<<"light is "<<phtoattr.bright <<std::endl;
    std::cout<<"constrast is "<<phtoattr.contrast<<std::endl;
    std::cout<<"saturation is "<<phtoattr.saturation<<std::endl;
    std::cout<<"quality is "<<phtoattr.quality<<std::endl;
    std::cout<<"lightfrqency is" << phtoattr.ligfrequency<<std::endl;


    while(g_run_thread)
    {

      capture_init(phtoattr,0);
      captureStart();
      std::string str = capture();
      g_video.pushPictureName(str);
      capture_uinit();

    //  Functions::Sleep(5000); 
      Functions::Sleep(1000*60*timephotattr->eve_min);
    
}
   

}




void timePicture(struct shmCommand& com, std::string& str, const char* attr)
{

   printf("---start timePicture \n");

    static bool isFirstTime = true;
    com.length = 0;

    //start or continue a video.
    if( attr[0] == 0 )
    {

        if( isFirstTime )
        {

          //  cout<<"FirstTime "<<endl;
            isFirstTime = false;
            g_run_thread = true;

           struct TimerPhoto timepictureattr;
           struct PhotoAttr photoattr;


            timepictureattr.eve_hour=(int)attr[1]-10;
            timepictureattr.eve_min=(int)attr[2]-10;

            photoattr.resolution =(int)attr[3]-10;
            photoattr.whitebalace = (int)attr[4]-10;
            photoattr.bright = (int)attr[5]-10;
            photoattr.contrast=(int)attr[6]-10;
            photoattr.saturation=(int)attr[7]-10;
            photoattr.quality=((int)attr[8]-10)*10;    

            timepictureattr.photoattr = photoattr;
            timepictureattr.isContinue =1;

            Thread thread(NULL, evePicture);
            thread.start(&timepictureattr);
			sleep(1);

        
}
        else
        {

             cout<<"second time "<<endl;

        
}
    
}else //if( attr[0] == 1 )//stop to video
    {
    
         cout<<"stop"<<endl;
         str = "";
         com.length= str.size();

         g_run_thread = false;
         isFirstTime = true; //reset it, make it can identify
         Functions::Sleep(10000);
         g_video.clearFileName();
         return ;
    
}

   // std::cout<<"the main thread begins to get fileName"<<std::endl;
    LOG_TRACE<<"the main thread begins to get fileName"<<std::endl;

    //get the picture name
    while( true )
    {

        //if don't have filename, this function return ""
        str = g_video.popPictureName();
       LOG_TRACE<<"the file name is "<<str<<std::endl;
     //  std::cout<<"the file name is "<<str<<std::endl;
        // now it don't exist picture but the thread taking photo;
        if( str.empty() && g_run_thread )
        {

            Functions::Sleep(1000); //sleep 5 seconds
        
}
        else
            break;
    
}

    com.length = str.size();



}



void* videoPicture(void* arg)
{

    printf("start videopicture in control.cpp\n");


    VideoAttr* videoAttr = static_cast<VideoAttr*>(arg);

     struct PhotoAttr phtoattr;

    phtoattr = videoAttr->photoattr;


/*
    std::cout<<"resolutuion is "<<(int)videoAttr.resolution<<std::endl;
    std::cout<<"whiteBalance is "<<(int)videoAttr.whitebalace<<std::endl;
    std::cout<<"light is "<<(int)videoAttr.bright <<std::endl;
    std::cout<<"constrast is "<<(int)videoAttr.contrast<<std::endl;
    std::cout<<"saturation is"<<(int)videoAttr.saturation<<std::endl;
*/

    
    time_t start_time,now;
    time(&start_time);

   // capvideo_init(videoAttr);
     capvideo_init();

    while( g_run_thread )  
    {

      // Functions::Sleep(300);
      capvideo();
    
}

   capvideo_uinit();

   time(&now);
   printf("tiem_ev is %d\n",now-start_time);

   Functions::Sleep(5000);


/*
   bool isCaptureThreadRun = true;
  Thread thread(NULL, startCaptureVideo);
  thread.start(&isCaptureThreadRun);
  sleep(1);
*/

/*
  while( g_run_thread )  {



        //capture a image and write it in loop

        std::string str = getVideoPictureFileName();

        std::cout<<"the vedio image file is "<<str<<std::endl;

        g_video.pushPictureName(str);

    
}

   isCaptureThreadRun = false;

   thread.join(); //wait for the startCaptureVideo thread to stop

   capvideo_uinit();

   time(&now);
   printf("tiem_ev is %d\n",now-start_time);

   Functions::Sleep(5000);*/

}



/*videoAttr[0] identify the video status.
 *if it == 0, it means start or continue a video.
 *
 *if it == 1, stop to video, but still need to upload the rest
 *              pictures which the control has photographed.
 *
 *if it == 2  it means cancel this video.
 */
void sendVideo(struct shmCommand& com, std::string& str, const char* attr)
{

  // printf("start sendvideo\n");

    static bool isFirstTime = true;
    com.length = 0;


     VideoAttr videoAttr;
     PhotoAttr photattr;
          

          //photoattr in vedio
      photattr.resolution =(int)attr[1]-10;
      photattr.whitebalace = (int)attr[2]-10;
      photattr.bright = (int)attr[3]-10;
      photattr.contrast=(int)attr[4]-10;
      photattr.saturation=(int)attr[5]-10;  

      videoAttr.photoattr  = photattr;


/*
    std::cout<<"att[0] is "<<(int)attr[0]<<std::endl;
    std::cout<<"resolutuion is "<<(int)attr[1]<<std::endl;
    std::cout<<"whiteBalance is "<<(int)attr[2]<<std::endl;
    std::cout<<"light is "<<(int)attr[3] <<std::endl;
    std::cout<<"constrast is "<<(int)attr[4]<<std::endl;
    std::cout<<"saturation is"<<(int)attr[5]<<std::endl;
*/

    //start or continue a video.
    if( attr[0] == 0 )
    {

        if( isFirstTime )
        {

          //  cout<<"FirstTime "<<endl;
            isFirstTime = false;
            g_run_thread = true;

            videoAttr.isContinue =1;

            Thread thread(NULL, videoPicture);
            thread.start(&videoAttr);
			sleep(1);
        
}
        else
        {

             cout<<"second time "<<endl;

        
}
    
}else //if( attr[0] == 1 )//stop to video
    {
    
         cout<<"stop"<<endl;
         str = "";
         com.length= str.size();

         g_run_thread = false;
         isFirstTime = true; //reset it, make it can identify
         Functions::Sleep(10000);
         g_video.clearFileName();
         return ;
    
}

    std::cout<<"the main thread begins to get fileName"<<std::endl;
    LOG_TRACE<<"the main thread begins to get fileName"<<std::endl;

    //get the picture name
    while( true )
    {

        //if don't have filename, this function return ""
        str = g_video.popPictureName();
       LOG_TRACE<<"the file name is "<<str<<std::endl;
       std::cout<<"the file name is "<<str<<std::endl;
        // now it don't exist picture but the thread taking photo;
        if( str.empty() && g_run_thread )
        {

            Functions::Sleep(1000); //sleep 5 seconds
        
}
        else
            break;
    
}

    com.length = str.size();


}


int main()
{

  
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 2

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
arm_capture.o7.44 kB23-09-14 11:04
arm_capture_init.o6.25 kB23-09-14 11:04
arm_capture_uinit.o2.11 kB23-09-14 11:04
arm_capvideo.o18.83 kB23-09-14 11:04
arm_capvideo_init.o6.44 kB23-09-14 11:04
arm_capvideo_uinit.o2.16 kB23-09-14 11:04
arm_Client.o102.76 kB03-11-14 23:23
arm_ClientPort99.95 kB03-11-14 23:23
arm_Common.o2.89 kB23-09-14 11:04
arm_Connector.o37.29 kB23-09-14 11:04
arm_control146.15 kB04-11-14 12:37
arm_Father9.37 kB23-09-14 08:26
arm_Functions.o2.02 kB23-09-14 11:04
arm_Lock.o1.60 kB23-09-14 11:04
arm_Logger.o7.59 kB23-09-14 11:04
arm_Mutex.o6.47 kB23-09-14 11:04
arm_Sem.o4.98 kB23-09-14 11:04
arm_ShareBuff.o21.13 kB23-09-14 11:04
arm_ShareMemory.o7.59 kB23-09-14 11:04
arm_ShmIPS.o12.88 kB23-09-14 11:04
arm_Socket.o1.16 kB23-09-14 11:04
arm_SocketOps.o5.43 kB23-09-14 11:04
arm_SocketStream.o6.77 kB23-09-14 11:04
arm_SsbSipH264Encode.o4.00 kB23-09-14 11:04
arm_TcpClient.o50.54 kB23-09-14 11:04
arm_Thread.o5.96 kB23-09-14 11:04
arm_Transform.o11.05 kB23-09-14 11:04
arm_Video.o22.58 kB23-09-14 11:04
capture.cpp4.76 kB12-12-13 15:12
capture.cpp~4.76 kB23-11-13 09:17
capture.h1,009.00 B23-11-13 09:17
capture.o5.05 kB23-09-14 11:03
capture_init.cpp9.78 kB12-12-13 14:49
capture_init.cpp~9.78 kB12-12-13 14:49
capture_init.o6.09 kB23-09-14 11:03
capture_uinit.cpp1.32 kB23-11-13 09:17
capture_uinit.o1.78 kB23-09-14 11:03
capvideo.cpp8.17 kB07-01-14 19:34
capvideo.cpp~8.15 kB23-11-13 09:17
capvideo.h527.00 B23-11-13 09:17
capvideo.o12.45 kB23-09-14 11:03
capvideo_init.cpp8.04 kB23-11-13 09:17
capvideo_init.o6.01 kB23-09-14 11:03
capvideo_uinit.cpp1.69 kB23-11-13 09:17
capvideo_uinit.o1.82 kB23-09-14 11:03
Client.cpp6.93 kB03-11-14 23:19
Client.cpp~6.91 kB30-03-14 18:48
Client.hpp1.03 kB23-11-13 09:17
Client.o66.13 kB03-11-14 23:23
Client11_19.pro1.27 kB23-11-13 09:17
ClientPort87.28 kB03-11-14 23:23
Common.cpp358.00 B23-11-13 09:17
Common.hpp308.00 B23-11-13 09:17
Common.o2.57 kB23-09-14 11:03
Connector.cpp2.37 kB23-09-14 10:28
Connector.cpp~2.37 kB16-03-14 20:18
Connector.hpp715.00 B16-03-14 21:59
Connector.hpp~715.00 B23-11-13 09:17
Connector.o24.09 kB23-09-14 11:03
control128.54 kB04-11-14 12:37
Control.cpp11.11 kB04-11-14 12:29
Control.cpp~10.58 kB07-04-14 21:25
<DeviceControl.cpp>0.00 B23-09-14 11:09
DeviceControl.hpp171.00 B23-09-14 11:09
Father12.37 kB23-09-14 08:25
Father.cpp1.89 kB21-02-14 15:48
Father.cpp~1.89 kB23-11-13 09:17
Functions.cpp852.00 B23-11-13 09:17
Functions.hpp317.00 B23-11-13 09:17
Functions.o1.48 kB23-09-14 11:03
IIPS.hpp328.00 B23-11-13 09:17
IMutex.hpp194.00 B23-11-13 09:17
IPC.hpp824.00 B23-11-13 09:17
Lock.cpp168.00 B23-11-13 09:17
Lock.hpp453.00 B23-11-13 09:17
Lock.o1.21 kB23-09-14 11:03
Logger.cpp1.95 kB23-11-13 09:17
Logger.hpp1.40 kB23-11-13 09:17
Logger.o6.40 kB23-09-14 11:03
LogMsg.c1.22 kB23-11-13 09:17
LogMsg.h370.00 B23-11-13 09:17
main.cpp1.24 kB23-11-13 09:17
makefile4.00 kB09-04-14 22:33
makefile~4.00 kB23-11-13 09:17
MfcDriver.h1.71 kB23-11-13 09:17
MfcDrvParams.h4.41 kB23-11-13 09:17
Mutex.cpp543.00 B23-11-13 09:17
Mutex.hpp284.00 B23-11-13 09:17
Mutex.o5.23 kB23-09-14 11:03
Sem.cpp1.01 kB23-11-13 09:17
Sem.hpp504.00 B23-11-13 09:17
Sem.o4.15 kB23-09-14 11:03
ShareBuff.cpp621.00 B23-11-13 09:17
ShareBuff.hpp301.00 B23-11-13 09:17
ShareBuff.o12.41 kB23-09-14 11:03
ShareMemory.cpp1.31 kB23-11-13 09:17
ShareMemory.hpp706.00 B28-03-14 21:41
ShareMemory.hpp~705.00 B28-03-14 21:25
ShareMemory.o6.66 kB23-09-14 11:03
ShmIPS.cpp797.00 B23-11-13 09:17
ShmIPS.hpp771.00 B23-11-13 09:17
ShmIPS.o9.46 kB23-09-14 11:03
Socket.cpp252.00 B23-11-13 09:17
Socket.hpp304.00 B23-11-13 09:17
Socket.o1.02 kB23-09-14 11:03
SocketOps.cpp2.25 kB23-11-13 09:17
SocketOps.hpp566.00 B23-11-13 09:17
SocketOps.o4.96 kB23-09-14 11:03
SocketStream.cpp2.03 kB23-11-13 09:17
SocketStream.hpp685.00 B23-11-13 09:17
SocketStream.o5.71 kB23-09-14 11:03
SsbSipH264Encode.c9.73 kB23-11-13 09:17
SsbSipH264Encode.h1.85 kB23-11-13 09:17
SsbSipH264Encode.o2.63 kB23-09-14 11:03
struct.hpp1.44 kB23-09-14 10:46
TcpClient.cpp1.22 kB23-11-13 09:17
TcpClient.hpp588.00 B23-11-13 09:17
TcpClient.o31.48 kB23-09-14 11:03
Thread.cpp1.56 kB23-11-13 09:17
Thread.hpp1.07 kB23-11-13 09:17
Thread.o5.08 kB23-09-14 11:03
ThreadAttr.cpp1.71 kB23-11-13 09:17
ThreadAttr.hpp651.00 B23-11-13 09:17
Transform.cpp1.26 kB23-11-13 09:17
Transform.hpp547.00 B23-11-13 09:17
Transform.o7.17 kB23-09-14 11:03
Uncopyable.hpp238.00 B28-03-14 21:30
Uncopyable.hpp~239.00 B28-03-14 21:30
Video.cpp1.05 kB23-11-13 09:17
Video.hpp536.00 B23-11-13 09:17
Video.o13.39 kB23-09-14 11:03
<Client2013-12-15>0.00 B04-11-14 22:07
...
Sponsored links

Control.cpp (337.95 kB)

Need 2 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D