-
Notifications
You must be signed in to change notification settings - Fork 0
/
jason.php
executable file
·89 lines (81 loc) · 2.94 KB
/
jason.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/*
Simple php udp socket client
*/
//Reduce errors
error_reporting(~E_WARNING);
$server = '127.0.0.1';
$port = 1210;
if(!($sock = socket_create(AF_INET, SOCK_DGRAM, 0)))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
//echo 'Satellite ' . htmlspecialchars($_GET["satellite"]) . '!';
//echo "Socket created \n";
//Communication loop
//while(1)
{
//Take some input to send
// echo 'Enter a message to send : ';
// $input = fgets(STDIN);
// $input = "GET_SAT PCSAT\n";
$satellite = htmlspecialchars($_GET["satellite"]);
if($satellite == NULL) {
// echo 'is null';
$satellite ="PCSAT";
}
$input = "GET_SAT ". $satellite ."\n";
//Send the message to the server
if( ! socket_sendto($sock, $input , strlen($input) , 0 , $server , $port))
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not send data: [$errorcode] $errormsg \n");
}
//Now receive reply from server and print it
if(socket_recv ( $sock , $reply , 2045 , MSG_WAITALL ) === FALSE)
{
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not receive data: [$errorcode] $errormsg \n");
}
//echo "Reply : $reply"."<br>";
$satellite = explode("\n", $reply);
//print_r (explode(" ",$reply));
//echo $return_str. "<br>";
$myObj->name = $satellite[0];
$myObj->long = $satellite[1];
$myObj->lat = $satellite[2];
$myObj->az = $satellite[3];
$myObj->el = $satellite[4];
$myObj->aollos = $satellite[5];
$myObj->footprint = $satellite[6];
$myObj->range = $satellite[7];
$myObj->altitude = $satellite[8];
$myObj->velocity = $satellite[9];
$myObj->orbitnr = $satellite[10];
$myObj->visibility = $satellite[11];
$myObj->orbitalphase = $satellite[12];
$myObj->eclipsephase = $satellite[13];
$myObj->squint = $satellite[14];
$myJSON = json_encode($myObj);
echo $myJSON;
//echo "Name " . $satellite[0]."<br>"; // Name
//echo "Long " . $satellite[1]."<br>"; // Long
//echo "Lat " . $satellite[2]."<br>"; // Lat
//echo "Az " . $satellite[3]."<br>"; //
//echo "El " . $satellite[4]."<br>"; //
//echo "Next AOL/LOS " . $satellite[5]."<br>"; //
//echo "Footprint " . $satellite[6]."<br>"; //
//echo "Range " . $satellite[7]."<br>"; //
//echo "Altitude " . $satellite[8]."<br>"; //
//echo "Velocity " . $satellite[9]."<br>"; //
//echo "Orbit Nr " . $satellite[10]."<br>"; //
//echo "Visibility " . $satellite[11]."<br>"; //
//echo "Orbital Phase " . $satellite[12]."<br>"; //
//echo "Eclipse Phase " . $satellite[13]."<br>"; //
//echo "Squint " . $satellite[14]."<br>"; //
}
?>