| Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
SegCamBehavior.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_SegCamBehavior_h_ 00003 #define INCLUDED_SegCamBehavior_h_ 00004 00005 #include "CameraStreamBehavior.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. (Generally 00016 * either SegmentedColorGenerator or RLEGenerator) 00017 * 00018 * However, SegCamBehavior will add a few fields at the beginning of 00019 * each packet to assist in processing the image stream. 00020 * 00021 * I emphasize: <i>beginning</i> of each Vision packet, <i>before</i> the FilterBankGenerator header. 00022 * - <@c string:"TekkotsuImage"> 00023 * - <<tt>Config::vision_config::encoding_t</tt>: Config::vision_config::ENCODE_SINGLE_CHANNEL> <i>(always just sends a single channel)</i> 00024 * - <<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> 00025 * - <@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> 00026 * - <@c unsigned @c int: height> <i>(similarly, height of largest channel)</i> 00027 * - <@c unsigned @c int: timestamp> <i>(time image was taken, milliseconds since boot)</i> 00028 * - <@c unsigned @c int: framenumber> <i>(incremented for each frame, so we can tell if/when we drop one)</i> 00029 * 00030 * Alternatively, SegCamBehavior may send a "Close Connection" packet 00031 * when the server is shutting down. This is to help UDP connections, which 00032 * otherwise wouldn't realize that they need to start trying to reconnect. 00033 * - <@c string:"CloseConnection"> 00034 * 00035 * This is exactly the same protocol that is followed by the 00036 * RawCamBehavior as well - the same code can parse either stream. 00037 * 00038 * However, one odd bit - since the RLEGenerator doesn't save the color 00039 * information itself, SegCamBehavior will do it instead. So, if 00040 * SegCamBehavior is using RLE compression, it will tack a footer at 00041 * the end of the packet: (from SegmentedColorGenerator::encodeColors()) 00042 * - <@c unsigned @c int: num_cols> <i>(number of different colors available)</i> 00043 * - for each of num_col: 00044 * - <@c char: red> <i>red color to use for display of this index</i> 00045 * - <@c char: green> <i>green color to use for display of this index</i> 00046 * - <@c char: blue> <i>blue color to use for display of this index</i> 00047 * 00048 * You can tell whether to expect the color footer by the creator string 00049 * that follows the SegCamBehavior header. (The compression field listed 00050 * is considering segmented color itself a type of compression, whether 00051 * or not it's RLE encoded, so you can't use that to tell whether the 00052 * data is RLE encoded until you get to the data section.) 00053 * 00054 * This is a binary protocol -- the fields listed indicate binary values 00055 * in the AIBO's byte order (little endian). Strings are encoded using 00056 * the LoadSave::encode(char*,unsigned int, unsigned int) method. 00057 */ 00058 class SegCamBehavior : public CameraStreamBehavior { 00059 public: 00060 //! constructor 00061 SegCamBehavior(); 00062 00063 //! destructor 00064 ~SegCamBehavior() { theOne=NULL; } 00065 00066 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 00067 static const unsigned int UDP_WIRELESS_BUFFER_SIZE=64*1024; //!< 64KB is the max udp packet size 00068 00069 virtual void DoStart(); 00070 00071 virtual void DoStop(); 00072 00073 virtual void processEvent(const EventBase& e); 00074 00075 static std::string getClassDescription() { 00076 char tmp[20]; 00077 snprintf(tmp,20,"%d",config->vision.segcam_port); tmp[19]='\0'; 00078 return std::string("Forwards segmented images from camera over port ")+tmp; 00079 } 00080 virtual std::string getDescription() const { return getClassDescription(); } 00081 00082 protected: 00083 static SegCamBehavior* theOne; //!< global instance of SegCamBehavior acting as server 00084 //! function for network data to be sent to -- forwards to #theOne's receiveData() 00085 static int networkCallback(char* buf, int bytes) { return theOne->receiveData(buf,bytes); } 00086 00087 void closeServer(); //!<tear down the server socket (#visRLE) 00088 void setupServer(); //!<setup the server socket (#visRLE ) 00089 00090 //! opens a new packet, writes header info; returns true if open, false if otherwise open (check cur==NULL for error) 00091 /*! see the class documentation for SegCamBehavior for the protocol documentation */ 00092 bool openPacket(FilterBankGenerator& fbkgen, unsigned int time, unsigned int layer); 00093 bool writeRLE(const FilterBankEvent& fbke); //!< writes a color image 00094 bool writeSeg(const FilterBankEvent& fbke); //!< writes a color image 00095 void closePacket(); //!< closes and sends a packet, does nothing if no packet open 00096 00097 //! sends a packet signaling the server is closing the connection (good for UDP connections) 00098 bool sendCloseConnectionPacket(); 00099 00100 Socket * visRLE; //!< socket to send image stream over 00101 char * packet; //!< buffer being filled out to be sent 00102 char * cur; //!< current location in #packet 00103 unsigned int avail; //!< number of bytes remaining in #packet 00104 unsigned int max_buf; //!< the buffer size requested from Wireless when the socket was allocated 00105 unsigned int lastProcessedTime; //!< the time that the last event was processed 00106 00107 private: 00108 SegCamBehavior(const SegCamBehavior&); //!< don't call 00109 SegCamBehavior& operator=(const SegCamBehavior&); //!< don't call 00110 }; 00111 00112 /*! @file 00113 * @brief Describes SegCamBehavior, which forwards segmented images from camera over wireless 00114 * @author ejt (Creator) 00115 * 00116 * $Author: ejt $ 00117 * $Name: tekkotsu-3_0 $ 00118 * $Revision: 1.13 $ 00119 * $State: Exp $ 00120 * $Date: 2006/09/16 20:11:50 $ 00121 */ 00122 00123 #endif |
|
Tekkotsu v3.0 |
Generated Wed Oct 4 00:03:46 2006 by Doxygen 1.4.7 |