<project version="4">
<component name="ChangeListManager">
<list default="true" id="352ce63a-b52a-41a2-979b-becda7920939" name="Default" comment=".">
+ <change afterPath="$PROJECT_DIR$/scripts/lib/proc.php" afterDir="false" />
+ <change afterPath="$PROJECT_DIR$/servers/logcat.php" afterDir="false" />
+ <change afterPath="$PROJECT_DIR$/servers/logcatb.php" afterDir="false" />
+ <change afterPath="$PROJECT_DIR$/servers/logcats.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/scripts/lib/lib.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/lib.php" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/scripts/lib/off.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/off.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/scripts/lib/scenes.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/scenes.php" afterDir="false" />
+ <change beforePath="$PROJECT_DIR$/scripts/lib/shield.php" beforeDir="false" afterPath="$PROJECT_DIR$/scripts/lib/shield.php" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<workItem from="1605001866699" duration="7793000" />
<workItem from="1605087671373" duration="102000" />
<workItem from="1605087787424" duration="33487000" />
- <workItem from="1605261347643" duration="600000" />
- </task>
- <task id="LOCAL-00340" summary=".">
- <created>1598265728108</created>
- <option name="number" value="00340" />
- <option name="presentableId" value="LOCAL-00340" />
- <option name="project" value="LOCAL" />
- <updated>1598265728109</updated>
+ <workItem from="1605261347643" duration="1199000" />
+ <workItem from="1605342171398" duration="4613000" />
+ <workItem from="1605355486465" duration="7740000" />
</task>
<task id="LOCAL-00341" summary=".">
<created>1599316711212</created>
<option name="project" value="LOCAL" />
<updated>1605188139134</updated>
</task>
- <option name="localTasksCounter" value="389" />
+ <task id="LOCAL-00389" summary=".">
+ <created>1605261980841</created>
+ <option name="number" value="00389" />
+ <option name="presentableId" value="LOCAL-00389" />
+ <option name="project" value="LOCAL" />
+ <updated>1605261980842</updated>
+ </task>
+ <option name="localTasksCounter" value="390" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<screen x="0" y="0" width="1707" height="920" />
</state>
<state x="740" y="229" key="#com.jetbrains.php.refactoring.extractMethod.PhpExtractMethodDialog#function0/0.0.1707.920@0.0.1707.920" timestamp="1604146905948" />
- <state x="701" y="75" width="737" height="502" key="CommitChangelistDialog2" timestamp="1605188136787">
- <screen x="0" y="0" width="1920" height="1160" />
+ <state x="198" y="0" width="737" height="502" key="CommitChangelistDialog2" timestamp="1605261958132">
+ <screen x="0" y="0" width="2560" height="1040" />
</state>
<state x="132" y="0" width="737" height="502" key="CommitChangelistDialog2/0.0.1707.920@0.0.1707.920" timestamp="1605086955514" />
<state x="701" y="75" key="CommitChangelistDialog2/0.0.1920.1160@0.0.1920.1160" timestamp="1605188136787" />
- <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1605171492435" />
+ <state x="198" y="0" width="745" height="567" key="CommitChangelistDialog2/0.0.2560.1040@0.0.2560.1040" timestamp="1605261958132" />
<state x="952" y="244" key="FileChooserDialogImpl" timestamp="1605104496549">
<screen x="0" y="0" width="2560" height="1040" />
</state>
<state x="635" y="216" key="FileChooserDialogImpl/0.0.1707.920@0.0.1707.920" timestamp="1604227698339" />
<state x="952" y="244" key="FileChooserDialogImpl/0.0.2560.1040@0.0.2560.1040" timestamp="1605104496549" />
- <state x="1114" y="443" key="NewPhpFileDialog" timestamp="1605089580764">
+ <state x="1114" y="443" key="NewPhpFileDialog" timestamp="1605344146097">
<screen x="0" y="0" width="2560" height="1040" />
</state>
<state x="743" y="392" key="NewPhpFileDialog/0.0.1707.920@0.0.1707.920" timestamp="1604238041494" />
- <state x="1114" y="443" key="NewPhpFileDialog/0.0.2560.1040@0.0.2560.1040" timestamp="1605089580764" />
+ <state x="1114" y="443" key="NewPhpFileDialog/0.0.2560.1040@0.0.2560.1040" timestamp="1605344146097" />
<state x="546" y="120" key="SettingsEditor" timestamp="1605087773918">
<screen x="0" y="0" width="2560" height="1040" />
</state>
require_once ROOT . '/scripts/lib/router.php';
require_once ROOT . '/scripts/lib/flowerpower.php';
require_once ROOT . '/scripts/lib/denon.php';
+require_once ROOT . '/scripts/lib/proc.php';
require_once ROOT . '/scripts/lib/shield.php';
function offBureau()
{
- domoticzSwitch(1, false);
- irsend('bureau', 'Projector', 'PowerOff');
+ execScene('bureau/media/stop');
}
function offSdb()
--- /dev/null
+<?php
+
+/**
+ * this is a pure php implementation of something like 'expect'. this is for
+ * automating cli applications where the apps block while waiting for user
+ * input. In the end, the goal is to automate these input blocking cli apps for
+ * example, subversion asking for svn username and password.
+ * @since april 23rd, 2012
+ * @author shean massey
+ */
+class proc
+{
+ private $_proc_resource = null;
+ private $_cases = array();
+ private $_output_text = '';
+ private $_pipes = null;
+
+ public function __construct($process = '')
+ {
+ if ($process) {
+ $this->open($process);
+ }
+ }
+
+ /**
+ * create the internal pipes for reading and writing to the opened process
+ */
+ public function open($process)
+ {
+ $descriptors = array(
+ 0 => array('pipe', 'r'),
+ 1 => array('pipe', 'w'),
+ 2 => array('pipe', 'w'),
+ );
+ $this->_proc_resource = proc_open($process, $descriptors, $pipes);
+ if (!is_resource($this->_proc_resource)) {
+ throw new \exception('proc_open() failed to create a resource');
+ }
+ $this->_pipes = $pipes;
+ return $this;
+ }
+
+ /**
+ * close the opened pipes+process and return the return code of that process
+ */
+ public function close()
+ {
+ fclose($this->_pipes[0]);
+ fclose($this->_pipes[1]);
+ $return_code = proc_close($this->_proc_resource);
+ return $return_code;
+ }
+
+ /**
+ * set the rules, and assoc array where the keys are strings
+ * of 'expected text' and the values are closures to be executed
+ * once the expected string has been matched
+ */
+ public function on(array $cases)
+ {
+ $this->_cases = $cases;
+ return $this;
+ }
+
+ /**
+ * write to the opened processes input stream
+ */
+ public function write($text)
+ {
+ fwrite($this->_pipes[0], $text);
+ return $this;
+ }
+
+ /**
+ * write() + newline
+ */
+ public function writeln($text)
+ {
+ return $this->write($text . PHP_EOL);
+ }
+
+ /**
+ * run the script that was previously open()d and apply the expectation rules
+ */
+ public function run()
+ {
+ $buffer = '';
+ while ($block = stream_get_contents($this->_pipes[1], 20)) {
+ $e = explode("\n", $block);
+ $buffer .= $e[0];
+ $linesToParse = [];
+ if (count($e) > 1) {
+ for ($i = 1; $i < count($e); $i++) {
+ $linesToParse[] = $buffer;
+ $buffer = $e[$i];
+ }
+ }
+ foreach ($linesToParse as $line) {
+ $this->_parseLine($line);
+ }
+ }
+ }
+
+ protected function _parseLine($line)
+ {
+ if ($this->tooLate($line)) {
+ return;
+ }
+
+ foreach ($this->_cases as $expected_text => $closure) {
+ if (strpos($line, $expected_text)) {
+ $closure();
+ }
+ }
+ }
+
+ protected function tooLate($line)
+ {
+ // Time 11-14 14:31:35.586
+ $month = (int)substr($line, 0, 2);
+ $day = (int)substr($line, 3, 2);
+ $hour = (int)substr($line, 6, 2);
+ $min = (int)substr($line, 9, 2);
+ $sec = (int)substr($line, 12, 2);
+
+ $t = mktime($hour, $min, $sec, $month, $day, date('Y'));
+ $c = time();
+
+ return $t < $c - 5 || $t > $c;
+ }
+}
\ No newline at end of file
['type' => 'function', 'function' => 'bureauAuto', 'args' => [false]],
['type' => 'ir', 'room' => 'bureausun', 'device' => 'Projector', 'command' => 'PowerOn'],
],
+ 'bureau/media/stop' => [
+ /* domoticzSwitch(1, false);
+ irsend('bureau', 'Projector', 'PowerOff');*/
+ ['type' => 'scene', 'scene' => 'bureau/screen/up'],
+ ['type' => 'scene', 'scene' => 'bureau/rideaux/open'],
+ ['type' => 'scene', 'scene' => 'bureau/auto'],
+ ['type' => 'ir', 'room' => 'bureausun', 'device' => 'Projector', 'command' => 'PowerOff'],
+ ],
'bureau/screen/down' => [
['type' => 'domoticz', 'device' => '1', 'command' => true, 'priority' => true],
],
shieldCommand('shell am start', '-a android.intent.action.VIEW -d \'"' . $content . '"\'', $device);
}
+function shieldLogcat($cases = [], $device = null)
+{
+ shieldConnect(false, $device);
+ $proc = new proc();
+ $cmd=_adbcmd('logcat', '', $device);
+ echo $cmd."\n";
+ $proc->open($cmd);
+ $proc->on($cases);
+ $proc->run();
+}
+
function _adb($command, $params = '', $device = null)
+{
+ $c = _adbcmd($command, $params, $device);
+ echo $c . ' :: ' . `$c` . "\n";
+}
+
+function _adbcmd($command, $params, $device = null)
{
$device = getDevice($device);
$c = 'adb -s ' . $device['shield'] . ':5555 ' . $command;
if ($params) {
$c .= ' ' . $params;
}
- echo $c . ' :: ' . `$c` . "\n";
+ return $c;
}
\ No newline at end of file
--- /dev/null
+<?php
+require_once __DIR__ . "/../scripts/import.php";
+
+if (!isset($device)) {
+ $device = 'salon';
+}
+
+// Set time limit to indefinite execution
+set_time_limit(0);
+ignore_user_abort(true);
+
+$cases = [
+ 'Going to sleep due to power button' => function () use ($device) {
+ echo 'sleep' . "\n";
+ off($device);
+ },
+ 'Waking up from sleep' => function () use ($device) {
+ echo 'wakeup' . "\n";
+ shieldRunActivity($device);
+ },
+];
+
+echo 'Run home server logcat ' . $device . "\n";
+
+while (true) {
+ shieldLogcat($cases, $device);
+ echo 'Logcat ended' . "\n----\n";
+}
--- /dev/null
+#!/usr/bin/php
+<?php
+$device = 'bureau';
+include_once "logcat.php";
\ No newline at end of file
--- /dev/null
+#!/usr/bin/php
+<?php
+$device = 'salon';
+include_once "logcat.php";
\ No newline at end of file