Ticket #1945: diseqc-cleanup.patch

File diseqc-cleanup.patch, 10.7 KB (added by yeasah@…, 18 years ago)

Cleans up some bad indents, the large integer constant and static function warnings, and factors out a couple bit of common code. (the last part coincidentally fixes a problem with the rotor time estimate)

  • libs/libmythtv/diseqc.cpp

     
    7272#define LOC     QString("DiSEqCDevTree: ")
    7373#define LOC_ERR QString("DiSEqCDevTree, Error: ")
    7474
    75 static QString TableToString(uint type, const TypeTable *table)
     75QString DiSEqCDevDevice::TableToString(uint type, const TypeTable *table)
    7676{
    7777    for (; !table->name.isEmpty(); table++)
    7878    {
     
    8282    return QString::null;
    8383}
    8484
    85 static uint TableFromString(const QString &type, const TypeTable *table)
     85uint DiSEqCDevDevice::TableFromString(const QString &type, const TypeTable *table)
    8686{
    8787    uint first_val = table->value;
    8888    for (; !table->name.isEmpty(); table++)
     
    428428 *  \return True if execution completed successfully.
    429429 */
    430430bool DiSEqCDevTree::Execute(const DiSEqCDevSettings &settings,
    431                          const DVBTuning &tuning)
     431                            const DVBTuning &tuning)
    432432{
    433433    if (!m_root)
    434434    {
     
    572572 *  \param data Pointer to optional data.
    573573 */
    574574bool DiSEqCDevTree::SendCommand(uint adr, uint cmd, uint repeats,
    575                              uint data_len, unsigned char *data)
     575                                uint data_len, unsigned char *data)
    576576{
    577577    // check payload validity
    578578    if (data_len > 3 || (data_len > 0 && !data))
     
    691691}
    692692
    693693bool DiSEqCDevTree::ApplyVoltage(const DiSEqCDevSettings &settings,
    694                               const DVBTuning      &tuning)
     694                                 const DVBTuning         &tuning)
    695695{
    696696    uint voltage = SEC_VOLTAGE_18;
    697697
     
    707707 *  \brief Represents a node in a DVB-S device network.
    708708 */
    709709
    710 const TypeTable DiSEqCDevDevice::dvbdev_lookup[4] =
     710const DiSEqCDevDevice::TypeTable DiSEqCDevDevice::dvbdev_lookup[4] =
    711711{
    712712    { "switch",      kTypeSwitch },
    713713    { "rotor",       kTypeRotor  },
     
    795795}
    796796
    797797DiSEqCDevDevice *DiSEqCDevDevice::CreateByType(DiSEqCDevTree &tree,
    798                                          dvbdev_t type,
    799                                          uint dev_id)
     798                                               dvbdev_t type,
     799                                               uint dev_id)
    800800{
    801801    if (!dev_id)
    802802        dev_id = tree.NextFakeID();
     
    902902 *  \brief Switch class, including tone, legacy and DiSEqC switches.
    903903 */
    904904
    905 const TypeTable DiSEqCDevSwitch::SwitchTypeTable[7] =
     905const DiSEqCDevDevice::TypeTable DiSEqCDevSwitch::SwitchTypeTable[7] =
    906906{
    907907    { "legacy_sw21",  kTypeLegacySW21        },
    908908    { "legacy_sw42",  kTypeLegacySW42        },
     
    914914};
    915915
    916916DiSEqCDevSwitch::DiSEqCDevSwitch(DiSEqCDevTree &tree,
    917                            uint devid)
     917                                 uint devid)
    918918    : DiSEqCDevDevice(tree, devid),
    919919      m_type(kTypeTone), m_num_ports(2)
    920920{
     
    937937}
    938938
    939939bool DiSEqCDevSwitch::Execute(const DiSEqCDevSettings &settings,
    940                            const DVBTuning      &tuning)
     940                              const DVBTuning         &tuning)
    941941{
    942942    bool success = true;
    943943
     
    10571057}
    10581058
    10591059uint DiSEqCDevSwitch::GetVoltage(const DiSEqCDevSettings &settings,
    1060                                         const DVBTuning      &tuning) const
     1060                                 const DVBTuning         &tuning) const
    10611061{
    10621062    uint voltage = SEC_VOLTAGE_18;
    10631063    DiSEqCDevDevice *child = GetSelectedChild(settings);
     
    13101310}
    13111311
    13121312bool DiSEqCDevSwitch::ExecuteTone(const DiSEqCDevSettings &/*settings*/,
    1313                                const DVBTuning &/*tuning*/,
    1314                                uint pos)
     1313                                  const DVBTuning &/*tuning*/,
     1314                                  uint pos)
    13151315{
    13161316    VERBOSE(VB_CHANNEL, LOC + "Changing to Tone switch port " +
    13171317            QString("%1/2").arg(pos + 1));
     
    13241324}
    13251325
    13261326bool DiSEqCDevSwitch::ExecuteDiseqc(const DiSEqCDevSettings &settings,
    1327                                  const DVBTuning &tuning,
    1328                                  uint pos)
     1327                                    const DVBTuning &tuning,
     1328                                    uint pos)
    13291329{
    13301330    // retrieve LNB info
    13311331    bool high_band  = false;
     
    13881388
    13891389//////////////////////////////////////// DiSEqCDevRotor
    13901390
     1391static double GetCurTimeFloating(void)
     1392{
     1393    struct timeval curtime;
     1394    gettimeofday(&curtime, NULL);
     1395    return (double)curtime.tv_sec + (((double)curtime.tv_usec) / 1000000);
     1396}
     1397
    13911398/** \class DiSEqCDevRotor
    13921399 *  \brief Rotor class.
    13931400 */
    13941401
    1395 const TypeTable DiSEqCDevRotor::RotorTypeTable[] =
     1402const DiSEqCDevDevice::TypeTable DiSEqCDevRotor::RotorTypeTable[] =
    13961403{
    13971404    { "diseqc_1_2", kTypeDiSEqC_1_2 },
    13981405    { "diseqc_1_3", kTypeDiSEqC_1_3 },
     
    14001407};
    14011408
    14021409DiSEqCDevRotor::DiSEqCDevRotor(DiSEqCDevTree &tree,
    1403                          uint devid)
     1410                               uint devid)
    14041411    : DiSEqCDevDevice(tree, devid),
    14051412      m_type(kTypeDiSEqC_1_3),
    14061413      m_speed_hi(2.5),          m_speed_lo(1.9),
    1407       m_child(NULL),
    1408       m_last_position(0.0),     m_last_azimuth(0.0),
     1414      m_child(NULL),           
     1415      m_last_position(0.0),     m_desired_azimuth(0.0),
    14091416      m_reset(true),            m_move_time(0.0),
    1410       m_last_pos_known(false)
     1417      m_last_pos_known(false),  m_last_azimuth(0.0)
    14111418{
    14121419    Reset();
    14131420}
     
    14191426}
    14201427
    14211428bool DiSEqCDevRotor::Execute(const DiSEqCDevSettings &settings,
    1422                           const DVBTuning &tuning)
     1429                             const DVBTuning &tuning)
    14231430{
    14241431    bool success = true;
    14251432
     
    14981505}
    14991506
    15001507uint DiSEqCDevRotor::GetVoltage(const DiSEqCDevSettings &settings,
    1501                                        const DVBTuning      &tuning) const
     1508                                const DVBTuning         &tuning) const
    15021509{
    15031510    double position = settings.GetValue(GetDeviceID());
    1504     bool   moving   = ((GetProgress() < 1.0) || m_reset ||
    1505                        (position != m_last_position));
     1511    double completed = GetProgress();
     1512    bool   moving   = (completed < 1.0) || (position != m_last_position);
    15061513
    15071514    // override voltage if the last position is known and the rotor is moving
    15081515    if (m_last_pos_known && moving)
     
    16691676    double duration = change / speed;
    16701677
    16711678    // determine completion percentage
    1672     struct timeval curtime;
    1673     gettimeofday(&curtime, NULL);
    1674 
    1675     double cursecond       = (curtime.tv_sec +
    1676                               ((double) curtime.tv_usec / 1000000));
    1677     double time_since_move = cursecond - m_move_time;
    1678     double completed       = time_since_move / duration;
    1679 
    1680     // move completed, finish up
    1681     if (completed > 1.0)
     1679    double time_since_move = GetCurTimeFloating() - m_move_time;
     1680    double completed = time_since_move / duration;
     1681    if(completed > 1.0)
    16821682    {
     1683        RotationComplete();
    16831684        completed = 1.0;
    1684         m_move_time = 0.0;
    1685         m_last_pos_known = true;
    16861685    }
    16871686
    16881687    return completed;
     
    17201719}
    17211720
    17221721bool DiSEqCDevRotor::ExecuteRotor(const DiSEqCDevSettings&, const DVBTuning&,
    1723                                double angle)
     1722                                  double angle)
    17241723{
    17251724    // determine stored position from position map
    17261725    dbl_to_uint_t::const_iterator it = m_posmap.find(angle);
     
    17391738}
    17401739
    17411740bool DiSEqCDevRotor::ExecuteUSALS(const DiSEqCDevSettings&, const DVBTuning&,
    1742                                double angle)
     1741                                  double angle)
    17431742{
    17441743    double azimuth = CalculateAzimuth(angle);
    17451744    StartRotorPositionTracking(azimuth);
     
    17931792    m_desired_azimuth = azimuth;
    17941793
    17951794    // set last to approximate current position (or worst case if unknown)
    1796     m_last_azimuth = azimuth > 0.0 ? -75.0 : 75.0;
    1797     if (m_last_pos_known)
     1795    if (m_last_pos_known || m_move_time > 0.0)
    17981796        m_last_azimuth = GetApproxAzimuth();
     1797    else
     1798        m_last_azimuth = azimuth > 0.0 ? -75.0 : 75.0;
    17991799
    1800     struct timeval curtime;
    1801     gettimeofday(&curtime, NULL);
     1800    m_move_time = GetCurTimeFloating();
     1801}
    18021802
    1803     m_move_time = curtime.tv_sec + (((double)curtime.tv_usec) / 1000000);
     1803void DiSEqCDevRotor::RotationComplete(void) const
     1804{
     1805    m_move_time = 0.0;
     1806    m_last_pos_known = true;
     1807    m_last_azimuth = m_desired_azimuth;
    18041808}
    18051809
    18061810////////////////////////////////////////
     
    18351840}
    18361841
    18371842uint DiSEqCDevLNB::GetVoltage(const DiSEqCDevSettings&,
    1838                                      const DVBTuning &tuning) const
     1843                              const DVBTuning &tuning) const
    18391844{
    18401845    uint voltage = SEC_VOLTAGE_18;
    18411846
  • libs/libmythtv/diseqc.h

     
    3434typedef QMap<uint, DiSEqCDevTree*> cardid_to_diseqc_tree_t;
    3535typedef vector<DiSEqCDevDevice*>   dvbdev_vec_t;
    3636
    37 typedef struct { QString name; uint value; } TypeTable;
    38 static QString TableToString(uint type, const TypeTable *table);
    39 static uint    TableFromString(const QString &type, const TypeTable *table);
    40 
    4137class DiSEqCDevSettings
    4238{
    4339  public:
     
    149145    // Gets
    150146    dvbdev_t      GetDeviceType(void)  const { return m_dev_type;    }
    151147    uint          GetDeviceID(void)    const { return m_devid;       }
    152     bool          IsRealDeviceID(void) const { return m_devid<4000000000; }
     148    bool          IsRealDeviceID(void) const { return m_devid<4000000000u; }
    153149    DiSEqCDevDevice *GetParent(void)   const { return m_parent;      }
    154150    uint          GetOrdinal(void)     const { return m_ordinal;     }
    155151    QString       GetDescription(void) const { return m_desc;        }
     
    188184    uint             m_ordinal;
    189185    uint             m_repeat;
    190186
     187    typedef struct { QString name; uint value; } TypeTable;
     188    static QString TableToString(uint type, const TypeTable *table);
     189    static uint    TableFromString(const QString &type, const TypeTable *table);
     190
    191191  private:
    192192    static const TypeTable dvbdev_lookup[4];
    193193};
     
    272272    void   SetHiSpeed(double speed)        { m_speed_hi = speed; }
    273273    void   SetPosMap(const uint_to_dbl_t &posmap);
    274274    virtual bool SetChild(uint ordinal, DiSEqCDevDevice* device);
     275    void   RotationComplete(void) const;
    275276
    276277    // Gets
    277278    dvbdev_rotor_t GetType(void)         const { return m_type;      }
     
    315316
    316317    // state
    317318    double         m_last_position;
    318     double         m_last_azimuth;
    319319    double         m_desired_azimuth;
    320320    bool           m_reset;
    321321
    322322    // rotor position tracking state
    323323    mutable double m_move_time;
    324324    mutable bool   m_last_pos_known;
     325    mutable double m_last_azimuth;
    325326
    326327    // statics
    327328    static const TypeTable RotorTypeTable[3];