Ticket #1945: diseqc-cleanup.patch
File diseqc-cleanup.patch, 10.7 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/diseqc.cpp
72 72 #define LOC QString("DiSEqCDevTree: ") 73 73 #define LOC_ERR QString("DiSEqCDevTree, Error: ") 74 74 75 static QStringTableToString(uint type, const TypeTable *table)75 QString DiSEqCDevDevice::TableToString(uint type, const TypeTable *table) 76 76 { 77 77 for (; !table->name.isEmpty(); table++) 78 78 { … … 82 82 return QString::null; 83 83 } 84 84 85 static uintTableFromString(const QString &type, const TypeTable *table)85 uint DiSEqCDevDevice::TableFromString(const QString &type, const TypeTable *table) 86 86 { 87 87 uint first_val = table->value; 88 88 for (; !table->name.isEmpty(); table++) … … 428 428 * \return True if execution completed successfully. 429 429 */ 430 430 bool DiSEqCDevTree::Execute(const DiSEqCDevSettings &settings, 431 const DVBTuning &tuning)431 const DVBTuning &tuning) 432 432 { 433 433 if (!m_root) 434 434 { … … 572 572 * \param data Pointer to optional data. 573 573 */ 574 574 bool DiSEqCDevTree::SendCommand(uint adr, uint cmd, uint repeats, 575 uint data_len, unsigned char *data)575 uint data_len, unsigned char *data) 576 576 { 577 577 // check payload validity 578 578 if (data_len > 3 || (data_len > 0 && !data)) … … 691 691 } 692 692 693 693 bool DiSEqCDevTree::ApplyVoltage(const DiSEqCDevSettings &settings, 694 const DVBTuning&tuning)694 const DVBTuning &tuning) 695 695 { 696 696 uint voltage = SEC_VOLTAGE_18; 697 697 … … 707 707 * \brief Represents a node in a DVB-S device network. 708 708 */ 709 709 710 const TypeTable DiSEqCDevDevice::dvbdev_lookup[4] =710 const DiSEqCDevDevice::TypeTable DiSEqCDevDevice::dvbdev_lookup[4] = 711 711 { 712 712 { "switch", kTypeSwitch }, 713 713 { "rotor", kTypeRotor }, … … 795 795 } 796 796 797 797 DiSEqCDevDevice *DiSEqCDevDevice::CreateByType(DiSEqCDevTree &tree, 798 dvbdev_t type,799 uint dev_id)798 dvbdev_t type, 799 uint dev_id) 800 800 { 801 801 if (!dev_id) 802 802 dev_id = tree.NextFakeID(); … … 902 902 * \brief Switch class, including tone, legacy and DiSEqC switches. 903 903 */ 904 904 905 const TypeTable DiSEqCDevSwitch::SwitchTypeTable[7] =905 const DiSEqCDevDevice::TypeTable DiSEqCDevSwitch::SwitchTypeTable[7] = 906 906 { 907 907 { "legacy_sw21", kTypeLegacySW21 }, 908 908 { "legacy_sw42", kTypeLegacySW42 }, … … 914 914 }; 915 915 916 916 DiSEqCDevSwitch::DiSEqCDevSwitch(DiSEqCDevTree &tree, 917 uint devid)917 uint devid) 918 918 : DiSEqCDevDevice(tree, devid), 919 919 m_type(kTypeTone), m_num_ports(2) 920 920 { … … 937 937 } 938 938 939 939 bool DiSEqCDevSwitch::Execute(const DiSEqCDevSettings &settings, 940 const DVBTuning&tuning)940 const DVBTuning &tuning) 941 941 { 942 942 bool success = true; 943 943 … … 1057 1057 } 1058 1058 1059 1059 uint DiSEqCDevSwitch::GetVoltage(const DiSEqCDevSettings &settings, 1060 const DVBTuning&tuning) const1060 const DVBTuning &tuning) const 1061 1061 { 1062 1062 uint voltage = SEC_VOLTAGE_18; 1063 1063 DiSEqCDevDevice *child = GetSelectedChild(settings); … … 1310 1310 } 1311 1311 1312 1312 bool DiSEqCDevSwitch::ExecuteTone(const DiSEqCDevSettings &/*settings*/, 1313 const DVBTuning &/*tuning*/,1314 uint pos)1313 const DVBTuning &/*tuning*/, 1314 uint pos) 1315 1315 { 1316 1316 VERBOSE(VB_CHANNEL, LOC + "Changing to Tone switch port " + 1317 1317 QString("%1/2").arg(pos + 1)); … … 1324 1324 } 1325 1325 1326 1326 bool DiSEqCDevSwitch::ExecuteDiseqc(const DiSEqCDevSettings &settings, 1327 const DVBTuning &tuning,1328 uint pos)1327 const DVBTuning &tuning, 1328 uint pos) 1329 1329 { 1330 1330 // retrieve LNB info 1331 1331 bool high_band = false; … … 1388 1388 1389 1389 //////////////////////////////////////// DiSEqCDevRotor 1390 1390 1391 static 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 1391 1398 /** \class DiSEqCDevRotor 1392 1399 * \brief Rotor class. 1393 1400 */ 1394 1401 1395 const TypeTable DiSEqCDevRotor::RotorTypeTable[] =1402 const DiSEqCDevDevice::TypeTable DiSEqCDevRotor::RotorTypeTable[] = 1396 1403 { 1397 1404 { "diseqc_1_2", kTypeDiSEqC_1_2 }, 1398 1405 { "diseqc_1_3", kTypeDiSEqC_1_3 }, … … 1400 1407 }; 1401 1408 1402 1409 DiSEqCDevRotor::DiSEqCDevRotor(DiSEqCDevTree &tree, 1403 uint devid)1410 uint devid) 1404 1411 : DiSEqCDevDevice(tree, devid), 1405 1412 m_type(kTypeDiSEqC_1_3), 1406 1413 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), 1409 1416 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) 1411 1418 { 1412 1419 Reset(); 1413 1420 } … … 1419 1426 } 1420 1427 1421 1428 bool DiSEqCDevRotor::Execute(const DiSEqCDevSettings &settings, 1422 const DVBTuning &tuning)1429 const DVBTuning &tuning) 1423 1430 { 1424 1431 bool success = true; 1425 1432 … … 1498 1505 } 1499 1506 1500 1507 uint DiSEqCDevRotor::GetVoltage(const DiSEqCDevSettings &settings, 1501 const DVBTuning&tuning) const1508 const DVBTuning &tuning) const 1502 1509 { 1503 1510 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); 1506 1513 1507 1514 // override voltage if the last position is known and the rotor is moving 1508 1515 if (m_last_pos_known && moving) … … 1669 1676 double duration = change / speed; 1670 1677 1671 1678 // 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) 1682 1682 { 1683 RotationComplete(); 1683 1684 completed = 1.0; 1684 m_move_time = 0.0;1685 m_last_pos_known = true;1686 1685 } 1687 1686 1688 1687 return completed; … … 1720 1719 } 1721 1720 1722 1721 bool DiSEqCDevRotor::ExecuteRotor(const DiSEqCDevSettings&, const DVBTuning&, 1723 double angle)1722 double angle) 1724 1723 { 1725 1724 // determine stored position from position map 1726 1725 dbl_to_uint_t::const_iterator it = m_posmap.find(angle); … … 1739 1738 } 1740 1739 1741 1740 bool DiSEqCDevRotor::ExecuteUSALS(const DiSEqCDevSettings&, const DVBTuning&, 1742 double angle)1741 double angle) 1743 1742 { 1744 1743 double azimuth = CalculateAzimuth(angle); 1745 1744 StartRotorPositionTracking(azimuth); … … 1793 1792 m_desired_azimuth = azimuth; 1794 1793 1795 1794 // 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) 1798 1796 m_last_azimuth = GetApproxAzimuth(); 1797 else 1798 m_last_azimuth = azimuth > 0.0 ? -75.0 : 75.0; 1799 1799 1800 struct timeval curtime;1801 gettimeofday(&curtime, NULL); 1800 m_move_time = GetCurTimeFloating(); 1801 } 1802 1802 1803 m_move_time = curtime.tv_sec + (((double)curtime.tv_usec) / 1000000); 1803 void DiSEqCDevRotor::RotationComplete(void) const 1804 { 1805 m_move_time = 0.0; 1806 m_last_pos_known = true; 1807 m_last_azimuth = m_desired_azimuth; 1804 1808 } 1805 1809 1806 1810 //////////////////////////////////////// … … 1835 1840 } 1836 1841 1837 1842 uint DiSEqCDevLNB::GetVoltage(const DiSEqCDevSettings&, 1838 1843 const DVBTuning &tuning) const 1839 1844 { 1840 1845 uint voltage = SEC_VOLTAGE_18; 1841 1846 -
libs/libmythtv/diseqc.h
34 34 typedef QMap<uint, DiSEqCDevTree*> cardid_to_diseqc_tree_t; 35 35 typedef vector<DiSEqCDevDevice*> dvbdev_vec_t; 36 36 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 41 37 class DiSEqCDevSettings 42 38 { 43 39 public: … … 149 145 // Gets 150 146 dvbdev_t GetDeviceType(void) const { return m_dev_type; } 151 147 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; } 153 149 DiSEqCDevDevice *GetParent(void) const { return m_parent; } 154 150 uint GetOrdinal(void) const { return m_ordinal; } 155 151 QString GetDescription(void) const { return m_desc; } … … 188 184 uint m_ordinal; 189 185 uint m_repeat; 190 186 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 191 191 private: 192 192 static const TypeTable dvbdev_lookup[4]; 193 193 }; … … 272 272 void SetHiSpeed(double speed) { m_speed_hi = speed; } 273 273 void SetPosMap(const uint_to_dbl_t &posmap); 274 274 virtual bool SetChild(uint ordinal, DiSEqCDevDevice* device); 275 void RotationComplete(void) const; 275 276 276 277 // Gets 277 278 dvbdev_rotor_t GetType(void) const { return m_type; } … … 315 316 316 317 // state 317 318 double m_last_position; 318 double m_last_azimuth;319 319 double m_desired_azimuth; 320 320 bool m_reset; 321 321 322 322 // rotor position tracking state 323 323 mutable double m_move_time; 324 324 mutable bool m_last_pos_known; 325 mutable double m_last_azimuth; 325 326 326 327 // statics 327 328 static const TypeTable RotorTypeTable[3];