Ticket #2226: mythtv-diseqc-multiswitch.patch

File mythtv-diseqc-multiswitch.patch, 9.0 KB (added by yeasah@…, 6 years ago)

take into account polarity and band when considering whether to send committed diseqc messages

  • libs/libmythtv/diseqc.cpp

     
    450450    ApplyVoltage(settings, tuning); 
    451451 
    452452    // turn off tone burst first if commands need to be sent 
    453     if (m_root->IsCommandNeeded(settings)) 
     453    if (m_root->IsCommandNeeded(settings, tuning)) 
    454454    { 
    455455        SetTone(false); 
    456456        usleep(DISEQC_SHORT_WAIT); 
     
    969969    if (pos < 0) 
    970970        return false; 
    971971 
    972     // determine if switch command needs to be sent based on last pos 
    973     if ((m_last_pos == (uint)pos) && m_children[pos]) 
    974         return m_children[pos]->Execute(settings, tuning); 
    975  
    976972    // perform switching 
    977     switch (m_type) 
     973    if (ShouldSwitch(settings, tuning)) 
    978974    { 
    979         case kTypeTone: 
    980             success = ExecuteTone(settings, tuning, pos); 
    981             break; 
    982         case kTypeDiSEqCCommitted: 
    983         case kTypeDiSEqCUncommitted: 
    984             success = ExecuteDiseqc(settings, tuning, pos); 
    985             break; 
    986         case kTypeLegacySW21: 
    987         case kTypeLegacySW42: 
    988         case kTypeLegacySW64: 
    989             success = ExecuteLegacy(settings, tuning, pos); 
    990             break; 
    991         default: 
    992             success = false; 
    993             VERBOSE(VB_IMPORTANT, LOC_ERR + 
    994                     QString("Unknown switch type (%1)") 
    995                     .arg((uint)m_type)); 
    996             break; 
    997     } 
     975        switch (m_type) 
     976        { 
     977            case kTypeTone: 
     978                success = ExecuteTone(settings, tuning, pos); 
     979                break; 
     980            case kTypeDiSEqCCommitted: 
     981            case kTypeDiSEqCUncommitted: 
     982                success = ExecuteDiseqc(settings, tuning, pos); 
     983                break; 
     984            case kTypeLegacySW21: 
     985            case kTypeLegacySW42: 
     986            case kTypeLegacySW64: 
     987                success = ExecuteLegacy(settings, tuning, pos); 
     988                break; 
     989            default: 
     990                success = false; 
     991                VERBOSE(VB_IMPORTANT, LOC_ERR + 
     992                        QString("Unknown switch type (%1)") 
     993                        .arg((uint)m_type)); 
     994                break; 
     995        } 
    998996 
    999     // if a child device will be sending a diseqc command, wait 100ms 
    1000     if (m_children[pos]->IsCommandNeeded(settings)) 
    1001     { 
    1002         VERBOSE(VB_CHANNEL, LOC + "Waiting for switch"); 
    1003         usleep(DISEQC_LONG_WAIT); 
     997        // if a child device will be sending a diseqc command, wait 100ms 
     998        if (m_children[pos]->IsCommandNeeded(settings, tuning)) 
     999        { 
     1000            VERBOSE(VB_CHANNEL, LOC + "Waiting for switch"); 
     1001            usleep(DISEQC_LONG_WAIT); 
     1002        } 
     1003 
     1004        m_last_pos = pos; 
    10041005    } 
    10051006 
    1006     m_last_pos = pos; 
    1007  
    10081007    // chain to child if the switch was successful 
    10091008    if (success) 
    10101009        success = m_children[pos]->Execute(settings, tuning); 
     
    10151014void DiSEqCDevSwitch::Reset(void) 
    10161015{ 
    10171016    m_last_pos = (uint) -1; 
     1017    m_last_high_band = (uint) -1; 
     1018    m_last_horizontal = (uint) -1; 
    10181019    dvbdev_vec_t::iterator it = m_children.begin(); 
    10191020    for (; it != m_children.end(); ++it) 
    10201021    { 
     
    10231024    } 
    10241025} 
    10251026 
    1026 bool DiSEqCDevSwitch::IsCommandNeeded(const DiSEqCDevSettings &settings) const 
     1027bool DiSEqCDevSwitch::IsCommandNeeded(const DiSEqCDevSettings &settings, 
     1028                                      const DVBTuning         &tuning) const 
    10271029{ 
    1028     // sanity check switch position 
    10291030    int pos = GetPosition(settings); 
    10301031    if (pos < 0) 
    10311032        return false; 
    10321033 
    1033     // if position is changing, a command is definitely needed 
    1034     if ((uint)pos != m_last_pos) 
    1035         return true; 
    1036  
    1037     // otherwise, the child that will be selected may need a command 
    1038     return m_children[pos]->IsCommandNeeded(settings); 
     1034    return (ShouldSwitch(settings, tuning) || 
     1035            m_children[pos]->IsCommandNeeded(settings, tuning)); 
    10391036} 
    10401037 
    10411038DiSEqCDevDevice *DiSEqCDevSwitch::GetSelectedChild(const DiSEqCDevSettings &settings) const 
     
    13481345    return false; 
    13491346} 
    13501347 
     1348bool DiSEqCDevSwitch::ShouldSwitch(const DiSEqCDevSettings &settings, 
     1349                                   const DVBTuning &tuning) const 
     1350{ 
     1351    int pos = GetPosition(settings); 
     1352    if (pos < 0) 
     1353        return false; 
     1354 
     1355    // committed switch should change for band and polarity as well 
     1356    if (kTypeDiSEqCCommitted == m_type) 
     1357    { 
     1358        // retrieve LNB info 
     1359        bool high_band  = false; 
     1360        bool horizontal = false; 
     1361        DiSEqCDevLNB *lnb  = m_tree.FindLNB(settings); 
     1362        if (lnb) 
     1363        { 
     1364            high_band   = lnb->IsHighBand(tuning); 
     1365            horizontal  = lnb->IsHorizontal(tuning); 
     1366        } 
     1367 
     1368        if(high_band != m_last_high_band || 
     1369           horizontal != m_last_horizontal) 
     1370            return true; 
     1371    } 
     1372 
     1373    return m_last_pos != (uint)pos; 
     1374} 
     1375 
    13511376bool DiSEqCDevSwitch::ExecuteDiseqc(const DiSEqCDevSettings &settings, 
    13521377                                    const DVBTuning &tuning, 
    13531378                                    uint pos) 
     
    13851410    VERBOSE(VB_CHANNEL, LOC + "Changing to DiSEqC switch port " + 
    13861411            QString("%1/%2").arg(pos + 1).arg(m_num_ports)); 
    13871412 
    1388     return m_tree.SendCommand(DISEQC_ADR_SW_ALL, cmd, m_repeat, 1, &data); 
     1413    bool ret = m_tree.SendCommand(DISEQC_ADR_SW_ALL, cmd, m_repeat, 1, &data); 
     1414    if(ret) 
     1415    { 
     1416        m_last_high_band = high_band; 
     1417        m_last_horizontal = horizontal; 
     1418    } 
     1419    return ret; 
    13891420} 
    13901421 
    13911422int DiSEqCDevSwitch::GetPosition(const DiSEqCDevSettings &settings) const 
     
    14901521        m_child->Reset(); 
    14911522} 
    14921523 
    1493 bool DiSEqCDevRotor::IsCommandNeeded(const DiSEqCDevSettings &settings) const 
     1524bool DiSEqCDevRotor::IsCommandNeeded(const DiSEqCDevSettings &settings, 
     1525                                     const DVBTuning         &tuning) const 
    14941526{ 
    14951527    double position = settings.GetValue(GetDeviceID()); 
    14961528 
     
    14981530        return true; 
    14991531 
    15001532    if (m_child) 
    1501         return m_child->IsCommandNeeded(settings); 
     1533        return m_child->IsCommandNeeded(settings, tuning); 
    15021534 
    15031535    return false; 
    15041536} 
     
    15281560    return true; 
    15291561} 
    15301562 
    1531 uint DiSEqCDevRotor::GetVoltage(const DiSEqCDevSettings &settings, 
    1532                                 const DVBTuning         &tuning) const 
     1563bool DiSEqCDevRotor::IsMoving(const DiSEqCDevSettings &settings) const 
    15331564{ 
    15341565    double position = settings.GetValue(GetDeviceID()); 
    15351566    double completed = GetProgress(); 
    15361567    bool   moving   = (completed < 1.0) || (position != m_last_position); 
    15371568 
     1569    return (m_last_pos_known && moving); 
     1570} 
     1571 
     1572uint DiSEqCDevRotor::GetVoltage(const DiSEqCDevSettings &settings, 
     1573                                const DVBTuning         &tuning) const 
     1574{ 
    15381575    // override voltage if the last position is known and the rotor is moving 
    1539     if (m_last_pos_known && moving) 
     1576    if (IsMoving(settings)) 
    15401577    { 
    15411578        VERBOSE(VB_CHANNEL, LOC + 
    15421579                "Overriding voltage to 18V for faster rotor movement"); 
  • libs/libmythtv/diseqc.h

     
    159159    QString       GetDescription(void) const { return m_desc;        } 
    160160    virtual uint  GetChildCount(void)  const { return 0;             } 
    161161    virtual bool  IsCommandNeeded( 
    162         const DiSEqCDevSettings&)      const { return false;         } 
     162        const DiSEqCDevSettings&, const DVBTuning&) 
     163                                       const { return false;         } 
    163164    virtual uint  GetVoltage( 
    164165        const DiSEqCDevSettings&, const DVBTuning&) const = 0; 
    165166 
     
    230231    // Gets 
    231232    dvbdev_switch_t GetType(void)       const { return m_type;      } 
    232233    uint            GetNumPorts(void)   const { return m_num_ports; } 
     234    bool            ShouldSwitch(const DiSEqCDevSettings &settings, 
     235                                 const DVBTuning &tuning) const; 
    233236    virtual uint    GetChildCount(void) const; 
    234     virtual bool    IsCommandNeeded(const DiSEqCDevSettings&) const; 
     237    virtual bool    IsCommandNeeded(const DiSEqCDevSettings&, 
     238                                    const DVBTuning&) const; 
    235239    virtual uint    GetVoltage(const DiSEqCDevSettings&, 
    236240                               const DVBTuning&) const; 
    237241 
     
    257261    dvbdev_switch_t m_type; 
    258262    uint            m_num_ports; 
    259263    uint            m_last_pos; 
     264    uint            m_last_high_band; 
     265    uint            m_last_horizontal; 
    260266    dvbdev_vec_t    m_children; 
    261267 
    262268    static const TypeTable SwitchTypeTable[7]; 
     
    291297    double         GetProgress(void)     const; 
    292298    bool           IsPositionKnown(void) const; 
    293299    virtual uint   GetChildCount(void)   const { return 1;           } 
    294     virtual bool   IsCommandNeeded(const DiSEqCDevSettings&) const; 
     300    virtual bool   IsCommandNeeded(const DiSEqCDevSettings&, 
     301                                   const DVBTuning&) const; 
     302    bool           IsMoving(const DiSEqCDevSettings&) const; 
    295303    virtual uint   GetVoltage(const DiSEqCDevSettings&, 
    296304                              const DVBTuning&) const; 
    297305