Revision b1f34b4f host/lib/usrp/usrp2/usrp2_iface.cpp

b/host/lib/usrp/usrp2/usrp2_iface.cpp
39 39
using namespace uhd::transport;
40 40

  
41 41
static const double CTRL_RECV_TIMEOUT = 1.0;
42
static const size_t CTRL_RECV_RETRIES = 3;
43

  
44
//custom timeout error for retry logic to catch/retry
45
struct timeout_error : uhd::runtime_error
46
{
47
    timeout_error(const std::string &what):
48
        uhd::runtime_error(what)
49
    {
50
        //NOP
51
    }
52
};
42 53

  
43 54
static const boost::uint32_t MIN_PROTO_COMPAT_SPI = 7;
44 55
static const boost::uint32_t MIN_PROTO_COMPAT_I2C = 7;
......
264 275
    ){
265 276
        boost::mutex::scoped_lock lock(_ctrl_mutex);
266 277

  
278
        for (size_t i = 0; i < CTRL_RECV_RETRIES; i++){
279
            try{
280
                return ctrl_send_and_recv_internal(out_data, lo, hi, CTRL_RECV_TIMEOUT/CTRL_RECV_RETRIES);
281
            }
282
            catch(const timeout_error &e){
283
                UHD_MSG(error)
284
                    << "Control packet attempt " << i
285
                    << ", sequence number " << _ctrl_seq_num
286
                    << ":\n" << e.what() << std::endl;
287
            }
288
        }
289
        throw uhd::runtime_error("link dead: timeout waiting for control packet ACK");
290
    }
291

  
292
    usrp2_ctrl_data_t ctrl_send_and_recv_internal(
293
        const usrp2_ctrl_data_t &out_data,
294
        boost::uint32_t lo, boost::uint32_t hi,
295
        const double timeout
296
    ){
267 297
        //fill in the seq number and send
268 298
        usrp2_ctrl_data_t out_copy = out_data;
269 299
        out_copy.proto_ver = htonl(_protocol_compat);
......
274 304
        boost::uint8_t usrp2_ctrl_data_in_mem[udp_simple::mtu]; //allocate max bytes for recv
275 305
        const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem);
276 306
        while(true){
277
            size_t len = _ctrl_transport->recv(boost::asio::buffer(usrp2_ctrl_data_in_mem), CTRL_RECV_TIMEOUT);
307
            size_t len = _ctrl_transport->recv(boost::asio::buffer(usrp2_ctrl_data_in_mem), timeout);
278 308
            boost::uint32_t compat = ntohl(ctrl_data_in->proto_ver);
279 309
            if(len >= sizeof(boost::uint32_t) and (hi < compat or lo > compat)){
280 310
                throw uhd::runtime_error(str(boost::format(
......
290 320
            if (len == 0) break; //timeout
291 321
            //didnt get seq or bad packet, continue looking...
292 322
        }
293
        throw uhd::runtime_error("no control response");
323
        throw timeout_error("no control response, possible packet loss");
294 324
    }
295 325

  
296 326
    rev_type get_rev(void){

Also available in: Unified diff