GNU Radio 3.4.2 C++ API
control.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2008,2009,2010 Free Software Foundation, Inc.
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation, either version 3 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef INCLUDED_CONTROL_H
00020 #define INCLUDED_CONTROL_H
00021 
00022 #include <gruel/thread.h>
00023 #include <usrp2_eth_packet.h>
00024 
00025 namespace usrp2 {
00026 
00027   struct op_generic_cmd {
00028     u2_eth_packet_t h;
00029     op_generic_t    op;
00030     op_generic_t    eop;
00031   };
00032 
00033   /*!
00034    * OP_CONFIG_RX_V2 command packet
00035    */
00036   struct op_config_rx_v2_cmd
00037   {
00038     u2_eth_packet_t   h;
00039     op_config_rx_v2_t op;
00040     op_generic_t      eop;
00041   };
00042 
00043   struct op_start_rx_streaming_cmd
00044   {
00045     u2_eth_packet_t         h;
00046     op_start_rx_streaming_t op;
00047     op_generic_t            eop;
00048   };
00049 
00050   struct op_sync_and_start_rx_streaming_cmd
00051   {
00052     u2_eth_packet_t         h;
00053     op_generic_t            sync_op;
00054     op_start_rx_streaming_t rx_op;
00055     op_generic_t            eop;
00056   };
00057 
00058   struct op_stop_rx_cmd {
00059     u2_eth_packet_t h;
00060     op_generic_t    op;
00061     op_generic_t    eop;
00062   };
00063 
00064   struct op_config_tx_v2_cmd
00065   {
00066     u2_eth_packet_t   h;
00067     op_config_tx_v2_t op;
00068     op_generic_t      eop;
00069   };
00070 
00071   struct op_config_mimo_cmd
00072   {
00073     u2_eth_packet_t   h;
00074     op_config_mimo_t  op;
00075     op_generic_t      eop;
00076   };
00077 
00078   struct op_burn_mac_addr_cmd
00079   {
00080     u2_eth_packet_t    h;
00081     op_burn_mac_addr_t op;
00082     op_generic_t       eop;
00083   };
00084 
00085   struct op_dboard_info_cmd {
00086     u2_eth_packet_t h;
00087     op_generic_t    op;
00088     op_generic_t    eop;
00089   };
00090 
00091   struct op_peek_cmd {
00092     u2_eth_packet_t h;
00093     op_peek_t       op;
00094     op_generic_t    eop;
00095   };
00096 
00097   struct op_poke_cmd {
00098     u2_eth_packet_t h;
00099     op_poke_t       op;
00100     // words to write go here
00101     // eop must be dynamically written here
00102   };
00103 
00104   struct op_freq_cmd {
00105     u2_eth_packet_t h;
00106     op_freq_t       op;
00107     op_generic_t    eop;
00108   };
00109 
00110   struct op_gpio_cmd {
00111     u2_eth_packet_t h;
00112     op_gpio_t       op;
00113     op_generic_t    eop;
00114   };
00115 
00116   struct op_gpio_set_sels_cmd {
00117     u2_eth_packet_t h;
00118     op_gpio_set_sels_t op;
00119     op_generic_t    eop;
00120   };
00121 
00122   /*!
00123    * Control mechanism to allow API calls to block waiting for reply packets
00124    */
00125   class pending_reply
00126   {
00127   private:
00128     unsigned int    d_rid;
00129     void           *d_buffer;
00130     size_t          d_len;
00131 
00132     // d_mutex is used with d_cond and also protects d_complete
00133     gruel::mutex      d_mutex;
00134     gruel::condition_variable d_cond;
00135     bool            d_complete;
00136 
00137   public:
00138     /*!
00139      * Construct a pending reply from the reply ID, response packet
00140      * buffer, and buffer length.
00141      */
00142     pending_reply(unsigned int rid, void *buffer, size_t len);
00143 
00144     /*!
00145      * Destructor. Signals creating thread.
00146      */
00147     ~pending_reply();
00148 
00149     /*!
00150      * Block, waiting for reply packet.
00151      * Returns: 1 = ok, reply packet in buffer
00152      *          0 = timeout
00153      */
00154     int wait_for_completion(double secs);
00155 
00156     /*!
00157      * Allows creating thread to resume after copying reply into buffer
00158      */
00159     void notify_completion();
00160 
00161     /*!
00162      * Retrieve pending reply ID
00163      */
00164     unsigned int rid() const { return d_rid; }
00165 
00166     /*!
00167      * Retrieve destination buffer address
00168      */
00169     void *buffer() const { return d_buffer; }
00170 
00171     /*!
00172      * Retrieve destination buffer length
00173      */
00174     size_t len() const { return d_len; }
00175   };
00176 
00177 } // namespace usrp2
00178 
00179 #endif /* INCLUDED_CONTROL_H */