|
1
|
|
|
<?php |
|
2
|
|
|
require_once(dirname(__FILE__).'/class.Connection.php'); |
|
3
|
|
|
require_once(dirname(__FILE__).'/libs/Predict/Predict.php'); |
|
4
|
|
|
require_once(dirname(__FILE__).'/libs/Predict/Predict/Sat.php'); |
|
5
|
|
|
require_once(dirname(__FILE__).'/libs/Predict/Predict/QTH.php'); |
|
6
|
|
|
require_once(dirname(__FILE__).'/libs/Predict/Predict/Time.php'); |
|
7
|
|
|
require_once(dirname(__FILE__).'/libs/Predict/Predict/TLE.php'); |
|
8
|
|
|
|
|
9
|
|
|
class Satellite { |
|
10
|
|
|
public $db; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct($dbc = null) { |
|
13
|
|
|
$Connection = new Connection($dbc); |
|
14
|
|
|
$this->db = $Connection->db(); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function get_tle($name) { |
|
18
|
|
|
$query = 'SELECT tle_name, tle_tle1, tle_tle2, tle_type FROM tle WHERE tle_name = :name LIMIT 1'; |
|
19
|
|
|
try { |
|
20
|
|
|
$sth = $this->db->prepare($query); |
|
21
|
|
|
$sth->execute(array(':name' => $name)); |
|
22
|
|
|
} catch(PDOException $e) { |
|
23
|
|
|
echo $e->getMessage(); |
|
24
|
|
|
} |
|
25
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
26
|
|
|
if (isset($result[0])) return $result[0]; |
|
27
|
|
|
else return array(); |
|
28
|
|
|
} |
|
29
|
|
|
public function get_tle_types() { |
|
30
|
|
|
$query = 'SELECT DISTINCT tle_type FROM tle ORDER BY tle_type'; |
|
31
|
|
|
try { |
|
32
|
|
|
$sth = $this->db->prepare($query); |
|
33
|
|
|
$sth->execute(); |
|
34
|
|
|
} catch(PDOException $e) { |
|
35
|
|
|
echo $e->getMessage(); |
|
36
|
|
|
} |
|
37
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
38
|
|
|
if (isset($result[0])) return $result; |
|
39
|
|
|
else return array(); |
|
40
|
|
|
} |
|
41
|
|
|
public function get_tle_names() { |
|
42
|
|
|
$query = 'SELECT DISTINCT tle_name, tle_type FROM tle'; |
|
43
|
|
|
try { |
|
44
|
|
|
$sth = $this->db->prepare($query); |
|
45
|
|
|
$sth->execute(); |
|
46
|
|
|
} catch(PDOException $e) { |
|
47
|
|
|
echo $e->getMessage(); |
|
48
|
|
|
} |
|
49
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
50
|
|
|
if (isset($result[0])) return $result; |
|
51
|
|
|
else return array(); |
|
52
|
|
|
} |
|
53
|
|
|
public function get_tle_names_type($type) { |
|
54
|
|
|
$query = 'SELECT tle_name, tle_type FROM tle WHERE tle_type = :type ORDER BY tle_name'; |
|
55
|
|
|
try { |
|
56
|
|
|
$sth = $this->db->prepare($query); |
|
57
|
|
|
$sth->execute(array(':type' => $type)); |
|
58
|
|
|
} catch(PDOException $e) { |
|
59
|
|
|
echo $e->getMessage(); |
|
60
|
|
|
} |
|
61
|
|
|
$result = $sth->fetchAll(PDO::FETCH_ASSOC); |
|
62
|
|
|
if (isset($result[0])) return $result; |
|
63
|
|
|
else return array(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function position_all($timestamp_begin = '',$timestamp_end = '',$second = 10) { |
|
67
|
|
|
$all_sat = $this->get_tle_names(); |
|
68
|
|
|
$result = array(); |
|
69
|
|
|
foreach ($all_sat as $sat) { |
|
70
|
|
|
$position = $this->position($sat['tle_name'],$timestamp_begin,$timestamp_end,$second); |
|
71
|
|
|
$result = array_merge($position,$result); |
|
72
|
|
|
} |
|
73
|
|
|
return $result; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function position_all_type($type,$timestamp_begin = '',$timestamp_end = '',$second = 10) { |
|
77
|
|
|
$all_sat = $this->get_tle_names_type($type); |
|
78
|
|
|
$result = array(); |
|
79
|
|
|
foreach ($all_sat as $sat) { |
|
80
|
|
|
$position = $this->position($sat['tle_name'],$timestamp_begin,$timestamp_end,$second); |
|
81
|
|
|
$result = array_merge($position,$result); |
|
82
|
|
|
} |
|
83
|
|
|
return $result; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function position($name,$timestamp_begin = '',$timestamp_end = '',$second = 10) { |
|
87
|
|
|
$qth = new Predict_QTH(); |
|
88
|
|
|
$qth->lat = 37.790252; |
|
89
|
|
|
$qth->lon = -122.419968; |
|
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
$tle_file = $this->get_tle($name); |
|
92
|
|
|
//print_r($tle_file); |
|
93
|
|
|
$type = $tle_file['tle_type']; |
|
94
|
|
|
$tle = new Predict_TLE($tle_file['tle_name'],$tle_file['tle_tle1'],$tle_file['tle_tle2']); |
|
95
|
|
|
$sat = new Predict_Sat($tle); |
|
96
|
|
|
$predict = new Predict(); |
|
97
|
|
|
//if ($timestamp == '') $now = Predict_Time::get_current_daynum(); |
|
98
|
|
|
if ($timestamp_begin == '') $timestamp_begin = time(); |
|
99
|
|
|
if ($timestamp_end == '') { |
|
100
|
|
|
$now = Predict_Time::unix2daynum($timestamp_begin); |
|
101
|
|
|
//echo $now; |
|
102
|
|
|
$predict->predict_calc($sat,$qth,$now); |
|
103
|
|
|
return array('name' => $name, 'latitude' => $sat->ssplat,'longitude' => $sat->ssplon, 'altitude' => $sat->alt,'speed' => $sat->velo*60*60,'timestamp' => $timestamp_begin,'type' => $type); |
|
104
|
|
|
} else { |
|
105
|
|
|
for ($timestamp = $timestamp_begin; $timestamp <= $timestamp_end; $timestamp=$timestamp+$second) { |
|
106
|
|
|
//echo $timestamp."\n"; |
|
107
|
|
|
$now = Predict_Time::unix2daynum($timestamp); |
|
108
|
|
|
//echo $now; |
|
109
|
|
|
$predict->predict_calc($sat,$qth,$now); |
|
110
|
|
|
$result[] = array('name' => $name,'latitude' => $sat->ssplat,'longitude' => $sat->ssplon, 'altitude' => $sat->alt,'speed' => $sat->velo*60*60,'timestamp' => $timestamp,'type' => $type); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
return $result; |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
/* |
|
117
|
|
|
$sat = new Satellite(); |
|
118
|
|
|
print_r($sat->position('ISS (ZARYA)',time(),time()+100)); |
|
119
|
|
|
print_r($sat->get_tle_types()); |
|
120
|
|
|
*/ |
|
121
|
|
|
?> |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.