From 70c65a3fbae4b84859977ee40177b67f65f745cd Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Mon, 15 Dec 2014 08:14:47 +0100 Subject: [PATCH] linuxdvb rotor: another fix for last orbital position caching, code shuffle --- src/input/mpegts/linuxdvb/linuxdvb_rotor.c | 55 +++++++++++++--------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/input/mpegts/linuxdvb/linuxdvb_rotor.c b/src/input/mpegts/linuxdvb/linuxdvb_rotor.c index 19948a61..2fda6ee1 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_rotor.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_rotor.c @@ -131,6 +131,37 @@ const idclass_t linuxdvb_rotor_usals_class = } }; +/* + * + */ + +static inline +int pos_to_integer( double pos ) +{ + if (pos < 0) + return (pos - 0.05) * 10; + else + return (pos + 0.05) * 10; +} + +static inline +double to_radians( double val ) +{ + return ((val * M_PI) / 180.0); +} + +static inline +double to_degrees( double val ) +{ + return ((val * 180.0) / M_PI); +} + +static inline +double to_rev( double val ) +{ + return val - floor(val / 360.0) * 360; +} + /* ************************************************************************** * Class methods * *************************************************************************/ @@ -146,7 +177,7 @@ linuxdvb_rotor_grace if (!ls->ls_last_orbital_pos || lr->lr_rate == 0) return ls->ls_max_rotor_move; - newpos = (lr->lr_sat_lon + 0.05) * 10; + newpos = pos_to_integer(lr->lr_sat_lon); if (idnode_is_instance(&lr->ld_id, &linuxdvb_rotor_gotox_class)) { tunit = 1000; /* GOTOX */ } else { @@ -174,7 +205,7 @@ linuxdvb_rotor_check_orbital_pos if (!pos) return 0; - if (abs((int)((lr->lr_sat_lon + 0.05) * 10) - pos) > 2) + if (abs(pos_to_integer(lr->lr_sat_lon) - pos) > 2) return 0; dir = 'E'; @@ -207,24 +238,6 @@ linuxdvb_rotor_gotox_tune return linuxdvb_rotor_grace((linuxdvb_diseqc_t*)lr,lm); } -static inline -double to_radians( double val ) -{ - return ((val * M_PI) / 180.0); -} - -static inline -double to_degrees( double val ) -{ - return ((val * 180.0) / M_PI); -} - -static inline -double to_rev( double val ) -{ - return val - floor(val / 360.0) * 360; -} - static void usals_sat_azimuth_and_elevation ( double site_lat, double site_lon, double site_alt, double sat_lon, @@ -399,7 +412,7 @@ linuxdvb_rotor_post { linuxdvb_rotor_t *lr = (linuxdvb_rotor_t*)ld; - ls->lse_parent->ls_last_orbital_pos = lr->lr_sat_lon; + ls->lse_parent->ls_last_orbital_pos = pos_to_integer(lr->lr_sat_lon); return 0; }