00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef VETSIM_SERIAL_CFG_H
00021 #define VETSIM_SERIAL_CFG_H
00022
00023 #ifdef _WIN32
00024 #define _CRT_SECURE_NO_DEPRECATE // it appears that something in wxwidgets is linking against string.h
00025 #define _CRT_SECURE_NO_WARNINGS // and making use of old-school strcpy() and other insecure routines
00026 #endif
00027
00028
00029
00030
00031 #include <string>
00032 #include <boost/asio.hpp>
00033
00034
00035 #include <wx/artprov.h>
00036 #include <wx/xrc/xmlres.h>
00037 #include <wx/intl.h>
00038 #include <wx/string.h>
00039 #include <wx/stattext.h>
00040 #include <wx/gdicmn.h>
00041 #include <wx/font.h>
00042 #include <wx/colour.h>
00043 #include <wx/settings.h>
00044 #include <wx/textctrl.h>
00045 #include <wx/choice.h>
00046 #include <wx/sizer.h>
00047 #include <wx/statline.h>
00048 #include <wx/button.h>
00049 #include <wx/dialog.h>
00050
00051
00052 #include <wx/msgdlg.h>
00053
00054
00055 #ifndef NULLPTR
00056 #define NULLPTR 0
00057 #endif
00058
00059 namespace cornelluniversity {
00060 namespace vetcpr {
00061
00066 class SerialCfg {
00067 public:
00068 static SerialCfg * instance( void );
00073 inline static void terminate(void) { if( instance_ ) delete instance_; instance_ = NULLPTR; }
00074 inline const std::string & device( void ) const { return( this->device_ ); }
00075 inline const boost::asio::serial_port_base::baud_rate & baudrate( void ) const { return( this->baudrate_ ); }
00076 inline const boost::asio::serial_port_base::parity & parity( void ) const { return( this->parity_ ); }
00077 inline const boost::asio::serial_port_base::flow_control & flowcntrl( void ) const { return( this->flowcntrl_ ); }
00078 inline const boost::asio::serial_port_base::stop_bits & stopbits( void ) const { return( this->stopbits_ ); }
00079 inline const boost::asio::serial_port_base::character_size & databits( void ) const { return( this->charsz_ ); }
00080 inline void device( const std::string & d ) { this->device_ = d; }
00081 inline void baudrate( const boost::asio::serial_port_base::baud_rate & br ) { this->baudrate_ = br; }
00082 inline void parity( const boost::asio::serial_port_base::parity & p ) { this->parity_ = p; }
00083 inline void flowcntrl( const boost::asio::serial_port_base::flow_control & fc ) { this->flowcntrl_ = fc; }
00084 inline void stopbits( const boost::asio::serial_port_base::stop_bits & sb ) { this->stopbits_ = sb; }
00085 inline void databits( const boost::asio::serial_port_base::character_size & cs ) { this->charsz_ = cs; }
00086
00087 protected:
00089 SerialCfg( void );
00090 SerialCfg( const std::string & device, const unsigned int baudrate,
00091 const boost::asio::serial_port_base::parity & parity=boost::asio::serial_port_base::parity( boost::asio::serial_port_base::parity::none ),
00092 const boost::asio::serial_port_base::flow_control & flowcntrl=boost::asio::serial_port_base::flow_control( boost::asio::serial_port_base::flow_control::none ),
00093 const boost::asio::serial_port_base::stop_bits & stopbits=boost::asio::serial_port_base::stop_bits( boost::asio::serial_port_base::stop_bits::one ),
00094 const boost::asio::serial_port_base::character_size & charsz=boost::asio::serial_port_base::character_size( boost::asio::serial_port_base::character_size(8) )
00095 );
00096 virtual ~SerialCfg( void ){;}
00097 SerialCfg( const SerialCfg & refcpy ){;}
00100 private:
00101 static SerialCfg * instance_;
00102 std::string device_;
00103 boost::asio::serial_port_base::baud_rate baudrate_;
00104 boost::asio::serial_port_base::parity parity_;
00105 boost::asio::serial_port_base::flow_control flowcntrl_;
00106 boost::asio::serial_port_base::stop_bits stopbits_;
00107 boost::asio::serial_port_base::character_size charsz_;
00108 };
00109
00114 class DlgSerialCfg : public wxDialog {
00115
00116 public:
00117 DlgSerialCfg( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Configure Serial"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 270,315 ), long style = wxDEFAULT_DIALOG_STYLE );
00118 ~DlgSerialCfg();
00119
00120 protected:
00121 enum {
00122 ID_TEXT_SERIAL_PORT = 1000,
00123 ID_CHOICE_PARITY,
00124 ID_CHOICE_DATA_WIDTH,
00125 ID_CHOICE_STOP_BITS,
00126 };
00127
00128
00129 virtual void doSaveConfiguration( wxCommandEvent& event );
00130
00131 wxStaticText* m_label_notice;
00132 wxStaticText* m_label_port;
00133 wxTextCtrl* m_text_serial_port;
00134 wxStaticText* m_label_baud_rate;
00135 wxChoice* m_choice_baud_rate;
00136 wxStaticText* m_label_parity;
00137 wxChoice* m_choice_parity;
00138 wxStaticText* m_label_data_bits;
00139 wxChoice* m_choice_data_width;
00140 wxStaticText* m_label_stop_bits;
00141 wxChoice* m_choice_stop_bits;
00142 wxStaticLine* m_staticline;
00143 wxStdDialogButtonSizer* m_button_sizer_dlg_serial;
00144 wxButton* m_button_sizer_dlg_serialSave;
00145 wxButton* m_button_sizer_dlg_serialCancel;
00146
00147 };
00148
00149 }
00150 }
00151
00152 #endif // VETSIM_SERIAL_CFG_H