Repository navigation
Expand file tree
/
Copy pathrigctld.php
More file actions
91 lines (76 loc) · 1.56 KB
/
Copy pathrigctld.php
File metadata and controls
91 lines (76 loc) · 1.56 KB
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
90
91
<?php
/**
* @brief rigctld API
* @date 2018-12-03
* @author Tobias Mädel <t.maedel@alfeld.de>
* @copyright MIT-licensed
*
*/
class rigctldAPI
{
private $host;
private $port;
private $socket = false;
function __construct($host = "127.0.0.1", $port = 4532)
{
$this->host = $host;
$this->port = $port;
$this->connect();
}
function __destruct()
{
fclose($this->fp);
}
public function connect()
{
$this->fp = fsockopen($this->host, $this->port, $errno, $errstr, 5);
if (!$this->fp)
return false;
return true;
}
private function runCommand($command, $returnSize = 1)
{
if ($this->fp === false)
return false;
if (feof($this->fp))
{
$this->fp = false;
return false;
}
stream_set_timeout($this->fp, 2);
fwrite($this->fp, $command . "\n");
$result = "";
for ($i=0; $i < $returnSize; $i++)
{
$result .= trim(fgets($this->fp)) . "\n";
}
return trim($result);
}
public function getFrequencyAndMode()
{
$data = $this->runCommand("fm", 3);
if ($data === false)
return false;
$data = explode("\n", $data);
return [
"frequency" => $data[0],
"mode" => $data[1],
"passband" => $data[2]
];
}
public function getFrequency()
{
return $this->runCommand("f");
}
public function getMode()
{
$mode = $this->runCommand("m", 2);
if ($mode === false)
return false;
$mode = explode("\n", $mode);
return [
"mode" => $mode[0],
"passband" => $mode[1]
];
}
}