summaryrefslogtreecommitdiff
path: root/localwebsite/classes/InverterdClient.php
diff options
context:
space:
mode:
authorEvgeny Sorokin <me@ch1p.io>2024-01-17 03:35:59 +0300
committerEvgeny Sorokin <me@ch1p.io>2024-01-17 03:35:59 +0300
commita9a241ad19449c29b68cd4a5b539bcbec816e341 (patch)
tree2ebfc73b206e4cec30fd94613bd6bf42ef5b269d /localwebsite/classes/InverterdClient.php
parent8a89dd77be03ca8eb9cdc378ba8e912292494fa9 (diff)
lws: pump page rewritten to python
Diffstat (limited to 'localwebsite/classes/InverterdClient.php')
-rw-r--r--localwebsite/classes/InverterdClient.php69
1 files changed, 0 insertions, 69 deletions
diff --git a/localwebsite/classes/InverterdClient.php b/localwebsite/classes/InverterdClient.php
deleted file mode 100644
index b68b784..0000000
--- a/localwebsite/classes/InverterdClient.php
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-class InverterdClient extends MySimpleSocketClient {
-
- /**
- * @throws Exception
- */
- public function setProtocol(int $v): string
- {
- $this->send("v $v");
- return $this->recv();
- }
-
- /**
- * @throws Exception
- */
- public function setFormat(string $fmt): string
- {
- $this->send("format $fmt");
- return $this->recv();
- }
-
- /**
- * @throws Exception
- */
- public function exec(string $command, array $arguments = []): string
- {
- $buf = "exec $command";
- if (!empty($arguments)) {
- foreach ($arguments as $arg)
- $buf .= " $arg";
- }
- $this->send($buf);
- return $this->recv();
- }
-
- /**
- * @throws Exception
- */
- public function recv()
- {
- $recv_buf = '';
- $buf = '';
-
- while (true) {
- $result = socket_recv($this->sock, $recv_buf, 1024, 0);
- if ($result === false)
- throw new Exception(__METHOD__ . ": socket_recv() failed: " . $this->getSocketError());
-
- // peer disconnected
- if ($result === 0)
- break;
-
- $buf .= $recv_buf;
- if (endsWith($buf, "\r\n\r\n"))
- break;
- }
-
- $response = explode("\r\n", $buf);
- $status = array_shift($response);
- if (!in_array($status, ['ok', 'err']))
- throw new Exception(__METHOD__.': unexpected status ('.$status.')');
- if ($status == 'err')
- throw new Exception(empty($response) ? 'unknown inverterd error' : $response[0]);
-
- return trim(implode("\r\n", $response));
- }
-
-} \ No newline at end of file