Changeset 18194


Ignore:
Timestamp:
06/10/15 12:13:52 (9 years ago)
Author:
dneise
Message:
Workaround for FSC firmware bug. Auto Reconnect in case of checksum error.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/fscctrl.cc

    r18189 r18194  
    3131
    3232    bool fIsVerbose;
     33    bool fIsAutoReconnect;
    3334
    3435    size_t fNumConsecutiveErrors;   // Number of consecutive messages with errors
    3536    size_t fNumConsecutiveMessages; // Number of consecutive message which are ok
    3637
     38    boost::asio::deadline_timer fReconnectTimeout;
    3739
    3840protected:
     
    126128    }
    127129
    128     void ProcessMessage()
     130    bool ProcessMessage()
    129131    {
    130132        if (fIsVerbose)
     
    132134
    133135        if (!CheckChecksum())
    134             return;
     136            return false;
    135137
    136138        // That looks a bit odd because it copies the values twice for no reason.
     
    247249            humidities.push_back((volt[*ph]-offrh[idx])*0.0313);
    248250
     251        //1019=4.8
     252        //1005=1.3
     253        //970=-7.6
     254        //1300=76
    249255        for (int *pt=mapt; *pt>=0; pt++)
    250256            //temperatures.push_back(resist[*pt]>800&&resist[*pt]<2000 ? GetTempPT1000(resist[*pt]) : 0);
    251257            temperatures.push_back(resist[*pt]>970&&resist[*pt]<1300 ? GetTempPT1000(resist[*pt]) : 0);
     258            //temperatures.push_back(resist[*pt]>1019&&resist[*pt]<1300 ? GetTempPT1000(resist[*pt]) : 0);
    252259
    253260        // 0 = 3-(3+0)%4
     
    435442                //if (resist[i]>800 && resist[i]<2000)
    436443                if (resist[i]>970 && resist[i]<1300)
     444                //if (resist[i]>1019 && resist[i]<1300)
    437445                    Out() << setw(2) << i << " - " << setw(4) << (int)resist[i] << ": " << setprecision(1) << fixed << GetTempPT1000(resist[i]) << endl;
    438446                else
     
    447455        fNumConsecutiveErrors = 0;
    448456        fNumConsecutiveMessages++;
     457
     458        return true;
    449459    }
    450460
     
    480490        }
    481491
    482         ProcessMessage();
     492        if (!ProcessMessage())
     493        {
     494            fIsAutoReconnect = true;
     495            fReconnectTimeout.expires_from_now(boost::posix_time::seconds(10));
     496            fReconnectTimeout.async_wait(boost::bind(&ConnectionFSC::HandleReconnectTimeout,
     497                                                     this, dummy::error));
     498            PostClose(true);
     499            return;
     500        }
     501
    483502        StartRead();
    484503    }
     
    488507        fNumConsecutiveErrors   = 0;
    489508        fNumConsecutiveMessages = 0;
     509        fIsAutoReconnect = false;
    490510
    491511        StartRead();
     512    }
     513
     514    void HandleReconnectTimeout(const bs::error_code &)
     515    {
     516        fIsAutoReconnect = false;
    492517    }
    493518
     
    529554public:
    530555    ConnectionFSC(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),
    531         fIsVerbose(false)
     556        fIsVerbose(false), fIsAutoReconnect(false), fReconnectTimeout(ioservice)
    532557    {
    533558        SetLogStream(&imp);
     
    547572    {
    548573        fPositionsBias = vec;
     574    }
     575
     576    bool IsOpen() const
     577    {
     578        return IsConnected() || fIsAutoReconnect;
    549579    }
    550580};
     
    758788    int Execute()
    759789    {
    760         return fFSC.IsConnected() ? State::kConnected : State::kDisconnected;
     790        return fFSC.IsOpen() ? State::kConnected : State::kDisconnected;
    761791    }
    762792
Note: See TracChangeset for help on using the changeset viewer.