Homepage Demos Overview Downloads Tutorials Reference
Credits

RawCamBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_RawCamBehavior_h_
00003 #define INCLUDED_RawCamBehavior_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 images from camera over wireless
00013 /*! The format used for serialization is basically defined by the
00014  *  subclass of FilterBankGenerator being used.  I suggest looking at
00015  *  that classes's documentation to determine the format used.
00016  *
00017  *  However, RawCamBehavior will add a few fields at the beginning of
00018  *  each packet to assist in processing the image stream.
00019  *
00020  *  I emphasize: <i>beginning</i> of each Vision packet, <i>before</i> the FilterBankGenerator header. 
00021  *  - <@c string:"TekkotsuImage">
00022  *  - <<tt>Config::vision_config::encoding_t</tt>: rawcam_encoding> <i>(expect single or multiple channels, 0 means color (3 channels), 1 means intensity (1 channel))</i>
00023  *  - <<tt>Config::vision_config::compression_t</tt>: rawcam_compression> <i>(0==none, 1==jpeg, 2==rle)</i>
00024  *  - <@c unsigned @c int: width> <i>(this is the width of the largest channel - note different channels can be sent at different resolutions!  Provides cheap "compression" of chromaticity channels)</i>
00025  *  - <@c unsigned @c int: height> <i>(similarly, height of largest channel)</i>
00026  *  - <@c unsigned @c int: timestamp> <i>(time image was taken, milliseconds since boot)</i>
00027  *  - <@c unsigned @c int: framenumber> <i>(incremented for each frame, so we can tell if/when we drop one)</i>
00028  *
00029  *  This is exactly the same protocol that is followed by the SegCamBehavior as well - the same code can parse either stream.
00030  */ 
00031 class RawCamBehavior : public BehaviorBase {
00032 public:
00033   //! constructor
00034   RawCamBehavior();
00035 
00036   static const unsigned int TCP_WIRELESS_BUFFER_SIZE=200000; //!< 200000 bytes for use up to 416x320 + 2*208x160 (double res Y, full res UV on ERS-7)
00037   static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size
00038 
00039   virtual void DoStart();
00040 
00041   virtual void DoStop();
00042 
00043   virtual void processEvent(const EventBase& e);
00044 
00045   static std::string getClassDescription() {
00046     char tmp[20];
00047     sprintf(tmp,"%d",config->vision.rle_port);
00048     return std::string("Forwards images from camera over port ")+tmp;
00049   }
00050   virtual std::string getDescription() const { return getClassDescription(); }
00051   
00052 protected:
00053   //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error)
00054   /*! see the class documentation for RawCamBehavior for the protocol documentation */
00055   bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer);
00056   bool writeColor(const FilterBankEvent& fbke); //!< writes a color image
00057   bool writeSingleChannel(const FilterBankEvent& fbke); //!< writes a single channel
00058   void closePacket(); //!< closes and sends a packet, does nothing if no packet open
00059 
00060   Socket * visRaw; //!< socket for sending the image stream
00061   char * packet; //!< point to the current buffer being prepared to be sent
00062   char * cur; //!< current location within that buffer
00063   unsigned int avail; //!< the number of bytes remaining in the buffer
00064   unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated
00065 
00066 private:
00067   RawCamBehavior(const RawCamBehavior&); //!< don't call
00068   RawCamBehavior& operator=(const RawCamBehavior&); //!< don't call
00069 };
00070 
00071 /*! @file
00072  * @brief Describes RawCamBehavior, which forwards images from camera over wireless
00073  * @author ejt (Creator)
00074  *
00075  * $Author: ejt $
00076  * $Name: tekkotsu-2_2_2 $
00077  * $Revision: 1.10 $
00078  * $State: Exp $
00079  * $Date: 2004/11/11 01:45:36 $
00080  */
00081 
00082 #endif

Tekkotsu v2.2.2
Generated Tue Jan 4 15:43:15 2005 by Doxygen 1.4.0