Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

RegionCamBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_RegionCamBehavior_h_
00003 #define INCLUDED_RegionCamBehavior_h_
00004 
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "Shared/Config.h"
00007 
00008 class Socket;
00009 class FilterBankGenerator;
00010 class FilterBankEvent;
00011 
00012 //! Forwards segmented images from camera over wireless
00013 
00014 class RegionCamBehavior : public BehaviorBase {
00015 public:
00016   //! constructor
00017   RegionCamBehavior();
00018 
00019   static const unsigned int TCP_WIRELESS_BUFFER_SIZE=85000; //!< 85000 bytes for use up to 416x320 pixels / 8 min expected runs * 5 bytes per run + some padding
00020   static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size
00021 
00022   virtual void DoStart();
00023 
00024   virtual void DoStop();
00025 
00026   virtual void processEvent(const EventBase& e);
00027 
00028   static std::string getClassDescription() {
00029     char tmp[20];
00030     sprintf(tmp,"%d",*config->vision.segcam.port);
00031     return std::string("Forwards regions calculated out of images from camera over port ")+tmp;
00032   }
00033   virtual std::string getDescription() const { return getClassDescription(); }
00034   
00035 protected:
00036   void closeServer(); //!<tear down the server socket (#visRegion)
00037   void setupServer(); //!<setup the server socket (#visRegion)
00038   
00039   //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error)
00040   /*! see the class documentation for RegionCamBehavior for the protocol documentation */
00041   bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer); 
00042   bool writeRegions(const FilterBankEvent& fbke); //!< writes the region information
00043   void closePacket(); //!< closes and sends a packet, does nothing if no packet open
00044 
00045   Socket * visRegion; //!< socket to send image stream over
00046   char * packet; //!< buffer being filled out to be sent
00047   char * cur; //!< current location in #packet
00048   unsigned int avail; //!< number of bytes remaining in #packet
00049   unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated
00050 
00051 private:
00052   RegionCamBehavior(const RegionCamBehavior&); //!< don't call
00053   RegionCamBehavior& operator=(const RegionCamBehavior&); //!< don't call
00054 };
00055 
00056 /*! @file
00057  * @brief Implements RegionCamBehavior, which forwards the regions from RegionGenerator over wireless
00058  * @author harm & niels (Creators)
00059  *
00060  * $Author: ejt $
00061  * $Name: tekkotsu-4_0 $
00062  * $Revision: 1.5 $
00063  * $State: Exp $
00064  * $Date: 2007/01/30 22:56:19 $
00065  */
00066 
00067 #endif

Tekkotsu v4.0
Generated Thu Nov 22 00:54:55 2007 by Doxygen 1.5.4