Homepage Demos Overview Downloads Tutorials Reference
Credits

SegCamBehavior.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SegCamBehavior_h_
00003 #define INCLUDED_SegCamBehavior_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 /*! 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, SegCamBehavior 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>: Config::vision_config::ENCODE_SINGLE_CHANNEL> <i>(always just sends a single channel)</i>
00023  *  - <<tt>Config::vision_config::compression_t</tt>: Config::vision_config::COMPRESS_RLE> <i>(This is misleading - may actually be uncompressed, but this signals it's a segmented color image)</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
00030  *  RawCamBehavior as well - the same code can parse either stream.
00031  *
00032  *  However, odd bit - since the RLEGenerator doesn't save the color
00033  *  information itself, SegCamBehavior will do it instead.  So, if
00034  *  SegCamBehavior is using RLE compression, it will tack a footer at
00035  *  the end of the packet: (from SegmentedColorGenerator::encodeColors())
00036  *  - <@c unsigned @c int: num_cols> <i>(number of different colors available)</i>
00037  *  - for each of num_col:
00038  *    - <@c char: red> <i>red color to use for display of this index</i>
00039  *    - <@c char: green> <i>green color to use for display of this index</i>
00040  *    - <@c char: blue> <i>blue color to use for display of this index</i>
00041  */ 
00042 class SegCamBehavior : public BehaviorBase {
00043 public:
00044   //! constructor
00045   SegCamBehavior();
00046 
00047   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
00048   static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size
00049 
00050   virtual void DoStart();
00051 
00052   virtual void DoStop();
00053 
00054   virtual void processEvent(const EventBase& e);
00055 
00056   virtual std::string getName() const { return "SegCamServer"; }
00057 
00058   static std::string getClassDescription() {
00059     char tmp[20];
00060     sprintf(tmp,"%d",config->vision.rle_port);
00061     return std::string("Forwards segmented images from camera over port ")+tmp;
00062   }
00063   
00064 protected:
00065   //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error)
00066   /*! see the class documentation for SegCamBehavior for the protocol documentation */
00067   bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer); 
00068   bool writeRLE(const FilterBankEvent& fbke); //!< writes a color image
00069   bool writeSeg(const FilterBankEvent& fbke); //!< writes a color image
00070   void closePacket(); //!< closes and sends a packet, does nothing if no packet open
00071 
00072   Socket * visRLE; //!< socket to send image stream over
00073   char * packet; //!< buffer being filled out to be sent
00074   char * cur; //!< current location in #packet
00075   unsigned int avail; //!< number of bytes remaining in #packet
00076   unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated
00077 
00078 private:
00079   SegCamBehavior(const SegCamBehavior&); //!< don't call
00080   SegCamBehavior& operator=(const SegCamBehavior&); //!< don't call
00081 };
00082 
00083 /*! @file
00084  * @brief Describes SegCamBehavior, which forwards segmented images from camera over wireless
00085  * @author ejt (Creator)
00086  *
00087  * $Author: ejt $
00088  * $Name: tekkotsu-2_2 $
00089  * $Revision: 1.6 $
00090  * $State: Exp $
00091  * $Date: 2004/09/28 22:12:30 $
00092  */
00093 
00094 #endif

Tekkotsu v2.2
Generated Tue Oct 19 14:19:15 2004 by Doxygen 1.3.9.1