00001 #ifndef _REC_ROBOTINO_IMAGESENDER_SENDER_H_ 00002 #define _REC_ROBOTINO_IMAGESENDER_SENDER_H_ 00003 00004 #include "rec/robotino/imagesender/defines.h" 00005 00006 #include <QObject> 00007 #include <QUdpSocket> 00008 #include <QByteArray> 00009 #include <QTimer> 00010 00011 namespace rec 00012 { 00013 namespace robotino 00014 { 00015 namespace imagesender 00016 { 00017 class REC_ROBOTINO_IMAGESENDER_EXPORT Sender : public QUdpSocket 00018 { 00019 Q_OBJECT 00020 public: 00021 typedef enum { IdleState, SendingState } State; 00022 00023 Sender( QObject* parent ); 00024 00025 State state() const { return _state; } 00026 00030 void stop(); 00031 00032 #ifdef QT_NO_KEYWORDS 00033 public Q_SLOTS: 00034 #else 00035 public slots: 00036 #endif 00037 void setRawImageData( const QByteArray& data, 00038 unsigned int width, 00039 unsigned int height, 00040 unsigned int numChannels, 00041 unsigned int bitsPerChannel, 00042 unsigned int step ); 00043 00044 void setJpgImageData( const QByteArray& data ); 00045 00046 void setReceiver( quint32 address, quint16 port ); 00047 00048 #ifdef QT_NO_KEYWORDS 00049 Q_SIGNALS: 00050 #else 00051 signals: 00052 #endif 00053 void imageSendingCompleted(); 00054 00055 #ifdef QT_NO_KEYWORDS 00056 private Q_SLOTS: 00057 #else 00058 private slots: 00059 #endif 00060 void on_timer_timeout(); 00061 00062 private: 00063 static const int _startSequenceSize; 00064 static const qint8 _startSequence[10]; 00065 00066 static const int _stopSequenceSize; 00067 static const qint8 _stopSequence[10]; 00068 00069 void setImageData( bool isJpg, 00070 const QByteArray& data, 00071 unsigned int width, 00072 unsigned int height, 00073 unsigned int numChannels, 00074 unsigned int bitsPerChannel, 00075 unsigned int step ); 00076 00077 QHostAddress _receiver; 00078 quint16 _receiverPort; 00079 00080 QByteArray _imageData; 00081 qint32 _bytesWritten; 00082 00083 qint32 _partSize; 00084 00085 State _state; 00086 00087 QByteArray _header; 00088 00089 QTimer* _timer; 00090 }; 00091 } 00092 } 00093 } 00094 00095 #endif //_REC_ROBOTINO_IMAGESENDER_SENDER_H_