Apply php-cs-fixer
* Apply php-cs-fixer * Use short array syntax
Esse commit está contido em:
+12
-11
@@ -1,37 +1,38 @@
|
|||||||
<?php
|
<?php
|
||||||
$loader = require_once __DIR__ . '/../vendor/autoload.php';
|
|
||||||
$loader->add('Joli\ArDrone', __DIR__ . '/../src/');
|
$loader = require_once __DIR__.'/../vendor/autoload.php';
|
||||||
|
$loader->add('Joli\ArDrone', __DIR__.'/../src/');
|
||||||
|
|
||||||
$client = new \Joli\ArDrone\Client();
|
$client = new \Joli\ArDrone\Client();
|
||||||
|
|
||||||
$client->takeoff();
|
$client->takeoff();
|
||||||
|
|
||||||
$client
|
$client
|
||||||
->after(3, function() use ($client) {
|
->after(3, function () use ($client) {
|
||||||
$client->up(0.6);
|
$client->up(0.6);
|
||||||
})
|
})
|
||||||
->after(4, function() use ($client) {
|
->after(4, function () use ($client) {
|
||||||
$client->stop();
|
$client->stop();
|
||||||
})
|
})
|
||||||
->after(1, function() use ($client) {
|
->after(1, function () use ($client) {
|
||||||
$client->left(0.3);
|
$client->left(0.3);
|
||||||
})
|
})
|
||||||
->after(1, function() use ($client) {
|
->after(1, function () use ($client) {
|
||||||
$client->stop();
|
$client->stop();
|
||||||
})
|
})
|
||||||
->after(1, function() use ($client) {
|
->after(1, function () use ($client) {
|
||||||
$client->down(0.5);
|
$client->down(0.5);
|
||||||
})
|
})
|
||||||
->after(2, function() use ($client) {
|
->after(2, function () use ($client) {
|
||||||
$client->stop();
|
$client->stop();
|
||||||
})
|
})
|
||||||
->after(1, function() use ($client) {
|
->after(1, function () use ($client) {
|
||||||
$client->right(0.3);
|
$client->right(0.3);
|
||||||
})
|
})
|
||||||
->after(1, function() use ($client) {
|
->after(1, function () use ($client) {
|
||||||
$client->stop();
|
$client->stop();
|
||||||
})
|
})
|
||||||
->after(3, function() use ($client) {
|
->after(3, function () use ($client) {
|
||||||
$client->land();
|
$client->land();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
$loader = require_once __DIR__ . '/../vendor/autoload.php';
|
|
||||||
$loader->add('Joli\ArDrone', __DIR__ . '/../src/');
|
$loader = require_once __DIR__.'/../vendor/autoload.php';
|
||||||
|
$loader->add('Joli\ArDrone', __DIR__.'/../src/');
|
||||||
|
|
||||||
$client = new \Joli\ArDrone\Client();
|
$client = new \Joli\ArDrone\Client();
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone\Buffer;
|
namespace Joli\ArDrone\Buffer;
|
||||||
|
|
||||||
class Buffer {
|
class Buffer
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -20,14 +22,15 @@ class Buffer {
|
|||||||
|
|
||||||
public function getUint32LE()
|
public function getUint32LE()
|
||||||
{
|
{
|
||||||
$value = unpack('V/', substr($this->data, $this->offset, ($this->offset + 4)));
|
$value = unpack('V/', substr($this->data, $this->offset, ($this->offset + 4)));
|
||||||
$this->moveOffset(4);
|
$this->moveOffset(4);
|
||||||
|
|
||||||
return dechex($value[1]);
|
return dechex($value[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUint16LE()
|
public function getUint16LE()
|
||||||
{
|
{
|
||||||
$value = unpack('v/', substr($this->data, $this->offset, ($this->offset + 2)));
|
$value = unpack('v/', substr($this->data, $this->offset, ($this->offset + 2)));
|
||||||
$this->moveOffset(2);
|
$this->moveOffset(2);
|
||||||
|
|
||||||
return dechex($value[1]);
|
return dechex($value[1]);
|
||||||
@@ -35,7 +38,7 @@ class Buffer {
|
|||||||
|
|
||||||
public function getFloat32()
|
public function getFloat32()
|
||||||
{
|
{
|
||||||
$value = unpack('f/', substr($this->data, $this->offset, ($this->offset + 4)));
|
$value = unpack('f/', substr($this->data, $this->offset, ($this->offset + 4)));
|
||||||
$this->moveOffset(4);
|
$this->moveOffset(4);
|
||||||
|
|
||||||
return dechex($value[1]);
|
return dechex($value[1]);
|
||||||
@@ -43,7 +46,7 @@ class Buffer {
|
|||||||
|
|
||||||
public function getUint8()
|
public function getUint8()
|
||||||
{
|
{
|
||||||
$value = unpack('C/', substr($this->data, $this->offset, ($this->offset + 1)));
|
$value = unpack('C/', substr($this->data, $this->offset, ($this->offset + 1)));
|
||||||
$this->moveOffset(1);
|
$this->moveOffset(1);
|
||||||
|
|
||||||
return dechex($value[1]);
|
return dechex($value[1]);
|
||||||
@@ -51,7 +54,7 @@ class Buffer {
|
|||||||
|
|
||||||
public function getInt32()
|
public function getInt32()
|
||||||
{
|
{
|
||||||
$value = unpack('I/', substr($this->data, $this->offset, ($this->offset + 4)));
|
$value = unpack('I/', substr($this->data, $this->offset, ($this->offset + 4)));
|
||||||
$this->moveOffset(4);
|
$this->moveOffset(4);
|
||||||
|
|
||||||
return dechex($value[1]);
|
return dechex($value[1]);
|
||||||
@@ -62,16 +65,18 @@ class Buffer {
|
|||||||
return $this->mask($masks, $this->getUint32LE());
|
return $this->mask($masks, $this->getUint32LE());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVector31() {
|
public function getVector31()
|
||||||
return array(
|
{
|
||||||
|
return [
|
||||||
'x' => $this->getFloat32(),
|
'x' => $this->getFloat32(),
|
||||||
'y' => $this->getFloat32(),
|
'y' => $this->getFloat32(),
|
||||||
'z' => $this->getFloat32(),
|
'z' => $this->getFloat32(),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMatrix33() {
|
public function getMatrix33()
|
||||||
return array(
|
{
|
||||||
|
return [
|
||||||
'm11' => $this->getFloat32(),
|
'm11' => $this->getFloat32(),
|
||||||
'm12' => $this->getFloat32(),
|
'm12' => $this->getFloat32(),
|
||||||
'm13' => $this->getFloat32(),
|
'm13' => $this->getFloat32(),
|
||||||
@@ -81,7 +86,7 @@ class Buffer {
|
|||||||
'm31' => $this->getFloat32(),
|
'm31' => $this->getFloat32(),
|
||||||
'm32' => $this->getFloat32(),
|
'm32' => $this->getFloat32(),
|
||||||
'm33' => $this->getFloat32(),
|
'm33' => $this->getFloat32(),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBytes($nbBytes)
|
public function getBytes($nbBytes)
|
||||||
@@ -100,13 +105,13 @@ class Buffer {
|
|||||||
//todo: move this function ?
|
//todo: move this function ?
|
||||||
private function mask($masks, $value)
|
private function mask($masks, $value)
|
||||||
{
|
{
|
||||||
$flags = array();
|
$flags = [];
|
||||||
|
|
||||||
foreach($masks as $name => $mask) {
|
foreach ($masks as $name => $mask) {
|
||||||
$flags[$name] = (hexdec($value) & ($mask)) ? 1 : 0;
|
$flags[$name] = (hexdec($value) & ($mask)) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $flags;
|
return $flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,7 +122,8 @@ class Buffer {
|
|||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLength() {
|
public function getLength()
|
||||||
|
{
|
||||||
return strlen($this->data);
|
return strlen($this->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone;
|
namespace Joli\ArDrone;
|
||||||
|
|
||||||
use Evenement\EventEmitter;
|
use Evenement\EventEmitter;
|
||||||
use Joli\ArDrone\Control\UdpControl;
|
use Joli\ArDrone\Control\UdpControl;
|
||||||
use Joli\ArDrone\Navdata\Frame;
|
use Joli\ArDrone\Navdata\Frame;
|
||||||
use Joli\ArDrone\Navdata\UdpNavdata;
|
use Joli\ArDrone\Navdata\UdpNavdata;
|
||||||
use React\EventLoop\Factory AS LoopFactory;
|
use React\EventLoop\Factory as LoopFactory;
|
||||||
use React\Datagram\Factory AS UdpFactory;
|
use React\Datagram\Factory as UdpFactory;
|
||||||
use Joli\ArDrone\Config\Config;
|
use Joli\ArDrone\Config\Config;
|
||||||
|
|
||||||
class Client extends EventEmitter {
|
class Client extends EventEmitter
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Joli\ArDrone\Control\UdpControl
|
* @var \Joli\ArDrone\Control\UdpControl
|
||||||
*/
|
*/
|
||||||
@@ -26,7 +28,7 @@ class Client extends EventEmitter {
|
|||||||
private $timerOffset;
|
private $timerOffset;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $disableEmergency;
|
public $disableEmergency;
|
||||||
|
|
||||||
@@ -52,12 +54,12 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->loop = LoopFactory::create();
|
$this->loop = LoopFactory::create();
|
||||||
|
|
||||||
$this->udpFactory = new UdpFactory($this->loop);
|
$this->udpFactory = new UdpFactory($this->loop);
|
||||||
$this->timerOffset = 0;
|
$this->timerOffset = 0;
|
||||||
$this->lastState = 'CTRL_LANDED';
|
$this->lastState = 'CTRL_LANDED';
|
||||||
$this->lastBattery = 100;
|
$this->lastBattery = 100;
|
||||||
$this->lastAltitude = 0;
|
$this->lastAltitude = 0;
|
||||||
$this->disableEmergency = false;
|
$this->disableEmergency = false;
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ class Client extends EventEmitter {
|
|||||||
$this->udpNavdata = new UdpNavdata($this->loop);
|
$this->udpNavdata = new UdpNavdata($this->loop);
|
||||||
$self = $this;
|
$self = $this;
|
||||||
|
|
||||||
$this->udpNavdata->on('navdata', function(Frame $navdata) use (&$self) {
|
$this->udpNavdata->on('navdata', function (Frame $navdata) use (&$self) {
|
||||||
if (count($navdata->getDroneState()) > 0) {
|
if (count($navdata->getDroneState()) > 0) {
|
||||||
$stateData = $navdata->getDroneState();
|
$stateData = $navdata->getDroneState();
|
||||||
if ($stateData['emergencyLanding'] && $self->disableEmergency) {
|
if ($stateData['emergencyLanding'] && $self->disableEmergency) {
|
||||||
@@ -102,11 +104,11 @@ class Client extends EventEmitter {
|
|||||||
$stateData = $navdata->getDroneState();
|
$stateData = $navdata->getDroneState();
|
||||||
|
|
||||||
if ($stateData['lowBattery'] === 1) {
|
if ($stateData['lowBattery'] === 1) {
|
||||||
$self->emit('lowBattery', array($battery));
|
$self->emit('lowBattery', [$battery]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($battery !== $self->lastBattery) {
|
if ($battery !== $self->lastBattery) {
|
||||||
$self->emit('batteryChange', array($battery));
|
$self->emit('batteryChange', [$battery]);
|
||||||
$self->lastBattery = $battery;
|
$self->lastBattery = $battery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,19 +116,19 @@ class Client extends EventEmitter {
|
|||||||
$altitude = $demoData['altitudeMeters'];
|
$altitude = $demoData['altitudeMeters'];
|
||||||
|
|
||||||
if ($altitude !== $self->lastAltitude) {
|
if ($altitude !== $self->lastAltitude) {
|
||||||
$self->emit('altitudeChange', array($altitude));
|
$self->emit('altitudeChange', [$altitude]);
|
||||||
$self->lastAltitude = $altitude;
|
$self->lastAltitude = $altitude;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->emit('navdata', array($navdata));
|
$self->emit('navdata', [$navdata]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function emitState($e, $state, $currentState)
|
public function emitState($e, $state, $currentState)
|
||||||
{
|
{
|
||||||
if ($currentState === $state && $this->lastState !== $state) {
|
if ($currentState === $state && $this->lastState !== $state) {
|
||||||
$this->emit($e, array());
|
$this->emit($e, []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +144,7 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
$udpControl = $this->udpControl;
|
$udpControl = $this->udpControl;
|
||||||
|
|
||||||
$repl->on('action', function($action) use (&$udpControl) {
|
$repl->on('action', function ($action) use (&$udpControl) {
|
||||||
$udpControl->emit($action);
|
$udpControl->emit($action);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -178,23 +180,23 @@ class Client extends EventEmitter {
|
|||||||
|
|
||||||
public function __call($name, $arguments)
|
public function __call($name, $arguments)
|
||||||
{
|
{
|
||||||
if(in_array($name, Config::$commands)) {
|
if (in_array($name, Config::$commands)) {
|
||||||
if ($name === 'takeoff' || $name === 'land') {
|
if ($name === 'takeoff' || $name === 'land') {
|
||||||
// process callback function
|
// process callback function
|
||||||
$callback = (count($arguments) === 1) ? $arguments[0] : function() {};
|
$callback = (count($arguments) === 1) ? $arguments[0] : function () {};
|
||||||
$eventName = ($name === 'takeoff') ? 'hovering' : 'landed';
|
$eventName = ($name === 'takeoff') ? 'hovering' : 'landed';
|
||||||
|
|
||||||
$this->once($eventName, $callback);
|
$this->once($eventName, $callback);
|
||||||
|
|
||||||
$this->udpControl->emit($name);
|
$this->udpControl->emit($name);
|
||||||
} else if ($name === 'stop' || $name === 'ftrim' || $name === 'flip') {
|
} elseif ($name === 'stop' || $name === 'ftrim' || $name === 'flip') {
|
||||||
$this->udpControl->emit($name);
|
$this->udpControl->emit($name);
|
||||||
// Control commands
|
// Control commands
|
||||||
} else {
|
} else {
|
||||||
if (count($arguments) > 1) {
|
if (count($arguments) > 1) {
|
||||||
new \Exception('There are too many arguments');
|
new \Exception('There are too many arguments');
|
||||||
}
|
}
|
||||||
$this->udpControl->emit($name, array($arguments[0]));
|
$this->udpControl->emit($name, [$arguments[0]]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new \Exception('Invalid function');
|
new \Exception('Invalid function');
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone\Config;
|
namespace Joli\ArDrone\Config;
|
||||||
|
|
||||||
class Config {
|
class Config
|
||||||
|
{
|
||||||
const DRONE_IP = '192.168.1.1';
|
const DRONE_IP = '192.168.1.1';
|
||||||
const NAVDATA_PORT = 5554;
|
const NAVDATA_PORT = 5554;
|
||||||
const CONTROL_PORT = 5556;
|
const CONTROL_PORT = 5556;
|
||||||
|
|
||||||
static $commands = array(
|
public static $commands = [
|
||||||
'takeoff',
|
'takeoff',
|
||||||
'land',
|
'land',
|
||||||
'clockwise',
|
'clockwise',
|
||||||
@@ -21,6 +22,6 @@ class Config {
|
|||||||
'stop',
|
'stop',
|
||||||
'exit',
|
'exit',
|
||||||
'ftrim',
|
'ftrim',
|
||||||
'flip'
|
'flip',
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone\Control;
|
namespace Joli\ArDrone\Control;
|
||||||
|
|
||||||
class AtCommand {
|
class AtCommand
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@@ -18,31 +19,30 @@ class AtCommand {
|
|||||||
*/
|
*/
|
||||||
private $sequence;
|
private $sequence;
|
||||||
|
|
||||||
const TYPE_REF = 'REF';
|
const TYPE_REF = 'REF';
|
||||||
const TYPE_PCMD = 'PCMD';
|
const TYPE_PCMD = 'PCMD';
|
||||||
const TYPE_CALIB = 'CALIB';
|
const TYPE_CALIB = 'CALIB';
|
||||||
const TYPE_CONFIG = 'CONFIG';
|
const TYPE_CONFIG = 'CONFIG';
|
||||||
const TYPE_FTRIM = 'FTRIM';
|
const TYPE_FTRIM = 'FTRIM';
|
||||||
const TYPE_ANIM = 'ANIM';
|
const TYPE_ANIM = 'ANIM';
|
||||||
|
|
||||||
public function __construct($sequence, $type, $args)
|
public function __construct($sequence, $type, $args)
|
||||||
{
|
{
|
||||||
$this->args = $args;
|
$this->args = $args;
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->sequence = $sequence;
|
$this->sequence = $sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
$command = 'AT*' . $this->type . '=' . $this->sequence;
|
$command = 'AT*'.$this->type.'='.$this->sequence;
|
||||||
|
|
||||||
if (count($this->args) > 0) {
|
if (count($this->args) > 0) {
|
||||||
$command .= ','. implode(',', $this->args);
|
$command .= ','.implode(',', $this->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
$command .= "\r";
|
$command .= "\r";
|
||||||
|
|
||||||
return $command;
|
return $command;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone\Control;
|
namespace Joli\ArDrone\Control;
|
||||||
|
|
||||||
use Joli\ArDrone\Control\AtCommand;
|
class AtCommandCreator
|
||||||
|
{
|
||||||
class AtCommandCreator {
|
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
@@ -12,16 +12,16 @@ class AtCommandCreator {
|
|||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $pcmdAlias = array(
|
private $pcmdAlias = [
|
||||||
'left' => array('index' => 1, 'invert' => true),
|
'left' => ['index' => 1, 'invert' => true],
|
||||||
'right' => array('index' => 1, 'invert' => false),
|
'right' => ['index' => 1, 'invert' => false],
|
||||||
'front' => array('index' => 2, 'invert' => true),
|
'front' => ['index' => 2, 'invert' => true],
|
||||||
'back' => array('index' => 2, 'invert' => false),
|
'back' => ['index' => 2, 'invert' => false],
|
||||||
'up' => array('index' => 3, 'invert' => false),
|
'up' => ['index' => 3, 'invert' => false],
|
||||||
'down' => array('index' => 3, 'invert' => true),
|
'down' => ['index' => 3, 'invert' => true],
|
||||||
'clockwise' => array('index' => 4, 'invert' => false),
|
'clockwise' => ['index' => 4, 'invert' => false],
|
||||||
'counterClockwise' => array('index' => 4, 'invert' => true)
|
'counterClockwise' => ['index' => 4, 'invert' => true],
|
||||||
);
|
];
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -30,11 +30,11 @@ class AtCommandCreator {
|
|||||||
|
|
||||||
public function createConfigCommand($name, $value)
|
public function createConfigCommand($name, $value)
|
||||||
{
|
{
|
||||||
$args = array();
|
$args = [];
|
||||||
$config = '"' . $name . '","' . $value . '"';
|
$config = '"'.$name.'","'.$value.'"';
|
||||||
array_push($args, $config);
|
array_push($args, $config);
|
||||||
|
|
||||||
$this->sequence++;
|
++$this->sequence;
|
||||||
|
|
||||||
return new AtCommand($this->sequence, AtCommand::TYPE_CONFIG, $args);
|
return new AtCommand($this->sequence, AtCommand::TYPE_CONFIG, $args);
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ class AtCommandCreator {
|
|||||||
public function createRefCommand($options)
|
public function createRefCommand($options)
|
||||||
{
|
{
|
||||||
$config = 0;
|
$config = 0;
|
||||||
$args = array();
|
$args = [];
|
||||||
|
|
||||||
if ($options['fly'] === true) {
|
if ($options['fly'] === true) {
|
||||||
$config = $config | (1 << 9);
|
$config = $config | (1 << 9);
|
||||||
@@ -54,16 +54,16 @@ class AtCommandCreator {
|
|||||||
|
|
||||||
array_push($args, $config);
|
array_push($args, $config);
|
||||||
|
|
||||||
$this->sequence++;
|
++$this->sequence;
|
||||||
|
|
||||||
return new AtCommand($this->sequence, AtCommand::TYPE_REF, $args);
|
return new AtCommand($this->sequence, AtCommand::TYPE_REF, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPcmdCommand($options)
|
public function createPcmdCommand($options)
|
||||||
{
|
{
|
||||||
$args = array(0, 0, 0, 0, 0);
|
$args = [0, 0, 0, 0, 0];
|
||||||
|
|
||||||
foreach($options as $key => $value) {
|
foreach ($options as $key => $value) {
|
||||||
$alias = $this->pcmdAlias[$key];
|
$alias = $this->pcmdAlias[$key];
|
||||||
|
|
||||||
if ($alias['invert']) {
|
if ($alias['invert']) {
|
||||||
@@ -73,23 +73,23 @@ class AtCommandCreator {
|
|||||||
$args[$alias['index']] = $this->floatToIEEE($value);
|
$args[$alias['index']] = $this->floatToIEEE($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($args[1] != 0 || $args[2] != 0 ) {
|
if ($args[1] != 0 || $args[2] != 0) {
|
||||||
$args[0] = 1;
|
$args[0] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->sequence++;
|
++$this->sequence;
|
||||||
|
|
||||||
return new AtCommand($this->sequence, AtCommand::TYPE_PCMD, $args);
|
return new AtCommand($this->sequence, AtCommand::TYPE_PCMD, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createFtrimCommand()
|
public function createFtrimCommand()
|
||||||
{
|
{
|
||||||
return new AtCommand($this->sequence, AtCommand::TYPE_FTRIM, array());
|
return new AtCommand($this->sequence, AtCommand::TYPE_FTRIM, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createAnimCommand()
|
public function createAnimCommand()
|
||||||
{
|
{
|
||||||
$args = array(17, 1);
|
$args = [17, 1];
|
||||||
|
|
||||||
return new AtCommand($this->sequence, AtCommand::TYPE_ANIM, $args);
|
return new AtCommand($this->sequence, AtCommand::TYPE_ANIM, $args);
|
||||||
}
|
}
|
||||||
@@ -99,17 +99,17 @@ class AtCommandCreator {
|
|||||||
$floatInt = (float) $floatInt;
|
$floatInt = (float) $floatInt;
|
||||||
$binInt = pack('f', $floatInt);
|
$binInt = pack('f', $floatInt);
|
||||||
|
|
||||||
$hexInt = "";
|
$hexInt = '';
|
||||||
for($i = 0; $i < strlen($binInt); $i++) {
|
for ($i = 0; $i < strlen($binInt); ++$i) {
|
||||||
$c = ord($binInt{$i});
|
$c = ord($binInt{$i});
|
||||||
$hexInt = sprintf("%02X", $c).$hexInt;
|
$hexInt = sprintf('%02X', $c).$hexInt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($floatInt < 0) {
|
if ($floatInt < 0) {
|
||||||
$binIntString = decbin(hexdec($hexInt));
|
$binIntString = decbin(hexdec($hexInt));
|
||||||
$twoComplement = '';
|
$twoComplement = '';
|
||||||
|
|
||||||
for($i=0; $i < strlen($binIntString); $i++) {
|
for ($i = 0; $i < strlen($binIntString); ++$i) {
|
||||||
if ($binIntString[$i] == '0') {
|
if ($binIntString[$i] == '0') {
|
||||||
$twoComplement .= '1';
|
$twoComplement .= '1';
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ namespace Joli\ArDrone\Control;
|
|||||||
|
|
||||||
use Evenement\EventEmitter;
|
use Evenement\EventEmitter;
|
||||||
use Joli\ArDrone\Config\Config;
|
use Joli\ArDrone\Config\Config;
|
||||||
use React\Datagram\Factory AS UdpFactory;
|
use React\Datagram\Factory as UdpFactory;
|
||||||
use React\Datagram\Socket AS UdpSocket;
|
use React\Datagram\Socket as UdpSocket;
|
||||||
|
|
||||||
class UdpControl extends EventEmitter
|
class UdpControl extends EventEmitter
|
||||||
{
|
{
|
||||||
@@ -26,14 +26,14 @@ class UdpControl extends EventEmitter
|
|||||||
|
|
||||||
public function __construct($loop)
|
public function __construct($loop)
|
||||||
{
|
{
|
||||||
$this->loop = $loop;
|
$this->loop = $loop;
|
||||||
$this->port = Config::CONTROL_PORT;
|
$this->port = Config::CONTROL_PORT;
|
||||||
$this->ip = Config::DRONE_IP;
|
$this->ip = Config::DRONE_IP;
|
||||||
$this->commandCreator = new AtCommandCreator();
|
$this->commandCreator = new AtCommandCreator();
|
||||||
$this->speed = 0.3;
|
$this->speed = 0.3;
|
||||||
$this->ref = array('fly' => false, 'emergency' => false);
|
$this->ref = ['fly' => false, 'emergency' => false];
|
||||||
$this->pcmd = array();
|
$this->pcmd = [];
|
||||||
$this->anim = array();
|
$this->anim = [];
|
||||||
|
|
||||||
$this->start();
|
$this->start();
|
||||||
}
|
}
|
||||||
@@ -41,21 +41,21 @@ class UdpControl extends EventEmitter
|
|||||||
private function start()
|
private function start()
|
||||||
{
|
{
|
||||||
$udpFactory = new UdpFactory($this->loop);
|
$udpFactory = new UdpFactory($this->loop);
|
||||||
$loop = $this->loop;
|
$loop = $this->loop;
|
||||||
$udpControl = $this;
|
$udpControl = $this;
|
||||||
|
|
||||||
$udpFactory->createClient($this->ip.':'.$this->port)->then(function (UdpSocket $client) use (&$loop, $udpControl) {
|
$udpFactory->createClient($this->ip.':'.$this->port)->then(function (UdpSocket $client) use (&$loop, $udpControl) {
|
||||||
$commandCreator = $udpControl->commandCreator;
|
$commandCreator = $udpControl->commandCreator;
|
||||||
$ref = $udpControl->ref;
|
$ref = $udpControl->ref;
|
||||||
$pcmd = $udpControl->pcmd;
|
$pcmd = $udpControl->pcmd;
|
||||||
$anim = $udpControl->anim;
|
$anim = $udpControl->anim;
|
||||||
|
|
||||||
// Start dialog
|
// Start dialog
|
||||||
$client->send('1');
|
$client->send('1');
|
||||||
$client->send('1');
|
$client->send('1');
|
||||||
|
|
||||||
for ($j = 0; $j < 5; $j++) {
|
for ($j = 0; $j < 5; ++$j) {
|
||||||
$cmds = array();
|
$cmds = [];
|
||||||
|
|
||||||
array_push($cmds,
|
array_push($cmds,
|
||||||
$commandCreator->createConfigCommand('general:navdata_demo',
|
$commandCreator->createConfigCommand('general:navdata_demo',
|
||||||
@@ -71,14 +71,14 @@ class UdpControl extends EventEmitter
|
|||||||
// According to tests, a satisfying control of the AR.Drone 2.0 is reached
|
// According to tests, a satisfying control of the AR.Drone 2.0 is reached
|
||||||
// by sending the AT-commands every 30 ms for smooth drone movements.
|
// by sending the AT-commands every 30 ms for smooth drone movements.
|
||||||
$loop->addPeriodicTimer(0.03,
|
$loop->addPeriodicTimer(0.03,
|
||||||
function() use ($client, $commandCreator, &$ref, &$pcmd, &$anim) {
|
function () use ($client, $commandCreator, &$ref, &$pcmd, &$anim) {
|
||||||
$cmds = array();
|
$cmds = [];
|
||||||
|
|
||||||
array_push($cmds, $commandCreator->createRefCommand($ref));
|
array_push($cmds, $commandCreator->createRefCommand($ref));
|
||||||
array_push($cmds, $commandCreator->createPcmdCommand($pcmd));
|
array_push($cmds, $commandCreator->createPcmdCommand($pcmd));
|
||||||
|
|
||||||
if (count($anim) > 0) {
|
if (count($anim) > 0) {
|
||||||
for ($i = 0; $i <= 10; $i++) {
|
for ($i = 0; $i <= 10; ++$i) {
|
||||||
foreach ($anim as $name => $duration) {
|
foreach ($anim as $name => $duration) {
|
||||||
array_push($cmds,
|
array_push($cmds,
|
||||||
$commandCreator->createConfigCommand($name,
|
$commandCreator->createConfigCommand($name,
|
||||||
@@ -86,88 +86,87 @@ class UdpControl extends EventEmitter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$anim = array();
|
$anim = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$cmds = implode('', $cmds);
|
$cmds = implode('', $cmds);
|
||||||
$client->send($cmds);
|
$client->send($cmds);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$udpControl->on('land',
|
$udpControl->on('land',
|
||||||
function() use (&$ref, &$pcmd) {
|
function () use (&$ref, &$pcmd) {
|
||||||
$pcmd = array();
|
$pcmd = [];
|
||||||
$ref['fly'] = false;
|
$ref['fly'] = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('ftrim',
|
$udpControl->on('ftrim',
|
||||||
function() use (&$client, &$commandCreator) {
|
function () use (&$client, &$commandCreator) {
|
||||||
$client->send($commandCreator->createFtrimCommand());
|
$client->send($commandCreator->createFtrimCommand());
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('takeoff',
|
$udpControl->on('takeoff',
|
||||||
function() use (&$ref, &$pcmd) {
|
function () use (&$ref, &$pcmd) {
|
||||||
$pcmd = array();
|
$pcmd = [];
|
||||||
$ref['fly'] = true;
|
$ref['fly'] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('clockwise',
|
$udpControl->on('clockwise',
|
||||||
function($speed = 0.5) use (&$pcmd) {
|
function ($speed = 0.5) use (&$pcmd) {
|
||||||
$pcmd['clockwise'] = $speed;
|
$pcmd['clockwise'] = $speed;
|
||||||
unset($pcmd['counterClockwise']);
|
unset($pcmd['counterClockwise']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('counterClockwise',
|
$udpControl->on('counterClockwise',
|
||||||
function($speed = 0.5) use (&$pcmd) {
|
function ($speed = 0.5) use (&$pcmd) {
|
||||||
$pcmd['counterClockwise'] = $speed;
|
$pcmd['counterClockwise'] = $speed;
|
||||||
unset($pcmd['clockwise']);
|
unset($pcmd['clockwise']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('stop',
|
$udpControl->on('stop',
|
||||||
function() use (&$pcmd) {
|
function () use (&$pcmd) {
|
||||||
$pcmd = array();
|
$pcmd = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('front',
|
$udpControl->on('front',
|
||||||
function($speed = 0.3) use (&$pcmd) {
|
function ($speed = 0.3) use (&$pcmd) {
|
||||||
$pcmd['front'] = $speed;
|
$pcmd['front'] = $speed;
|
||||||
unset($pcmd['back']);
|
unset($pcmd['back']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('back',
|
$udpControl->on('back',
|
||||||
function($speed = 0.3) use (&$pcmd) {
|
function ($speed = 0.3) use (&$pcmd) {
|
||||||
$pcmd['back'] = $speed;
|
$pcmd['back'] = $speed;
|
||||||
unset($pcmd['front']);
|
unset($pcmd['front']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('right',
|
$udpControl->on('right',
|
||||||
function($speed = 0.3) use (&$pcmd) {
|
function ($speed = 0.3) use (&$pcmd) {
|
||||||
$pcmd['right'] = $speed;
|
$pcmd['right'] = $speed;
|
||||||
unset($pcmd['left']);
|
unset($pcmd['left']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('left',
|
$udpControl->on('left',
|
||||||
function($speed = 0.3) use (&$pcmd) {
|
function ($speed = 0.3) use (&$pcmd) {
|
||||||
$pcmd['left'] = $speed;
|
$pcmd['left'] = $speed;
|
||||||
unset($pcmd['right']);
|
unset($pcmd['right']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('up',
|
$udpControl->on('up',
|
||||||
function($speed = 0.6) use (&$pcmd) {
|
function ($speed = 0.6) use (&$pcmd) {
|
||||||
$pcmd['up'] = $speed;
|
$pcmd['up'] = $speed;
|
||||||
unset($pcmd['down']);
|
unset($pcmd['down']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('down',
|
$udpControl->on('down',
|
||||||
function($speed = 0.6) use (&$pcmd) {
|
function ($speed = 0.6) use (&$pcmd) {
|
||||||
$pcmd['down'] = $speed;
|
$pcmd['down'] = $speed;
|
||||||
unset($pcmd['up']);
|
unset($pcmd['up']);
|
||||||
});
|
});
|
||||||
|
|
||||||
$udpControl->on('flip',
|
$udpControl->on('flip',
|
||||||
function() use (&$anim) {
|
function () use (&$anim) {
|
||||||
$anim['control:flight_anim'] = '16,5';
|
$anim['control:flight_anim'] = '16,5';
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone\Navdata;
|
namespace Joli\ArDrone\Navdata;
|
||||||
|
|
||||||
use Joli\ArDrone\Buffer\Buffer;
|
use Joli\ArDrone\Buffer\Buffer;
|
||||||
use Joli\ArDrone\Navdata\Util;
|
class Frame
|
||||||
use Joli\ArDrone\Navdata\Option;
|
{
|
||||||
|
|
||||||
class Frame {
|
|
||||||
/**
|
/**
|
||||||
* @var \Joli\ArDrone\Buffer
|
* @var \Joli\ArDrone\Buffer
|
||||||
*/
|
*/
|
||||||
@@ -44,43 +43,43 @@ class Frame {
|
|||||||
public function __construct($binaryFrame)
|
public function __construct($binaryFrame)
|
||||||
{
|
{
|
||||||
// from ARDrone_SDK_2_0/ARDroneLib/Soft/Common/config.h
|
// from ARDrone_SDK_2_0/ARDroneLib/Soft/Common/config.h
|
||||||
$this->droneStateMasks = array(
|
$this->droneStateMasks = [
|
||||||
'flying' => (1 << 0), /*!< FLY MASK => (0) ardrone is landed, (1) ardrone is flying */
|
'flying' => (1 << 0), /*!< FLY MASK => (0) ardrone is landed, (1) ardrone is flying */
|
||||||
'videoEnabled' => (1 << 1), /*!< VIDEO MASK => (0) video disable, (1) video enable */
|
'videoEnabled' => (1 << 1), /*!< VIDEO MASK => (0) video disable, (1) video enable */
|
||||||
'visionEnabled' => (1 << 2), /*!< VISION MASK => (0) vision disable, (1) vision enable */
|
'visionEnabled' => (1 << 2), /*!< VISION MASK => (0) vision disable, (1) vision enable */
|
||||||
'controlAlgorithm' => (1 << 3), /*!< CONTROL ALGO => (0) euler angles control, (1) angular speed control */
|
'controlAlgorithm' => (1 << 3), /*!< CONTROL ALGO => (0) euler angles control, (1) angular speed control */
|
||||||
'altitudeControlAlgorithm' => (1 << 4), /*!< ALTITUDE CONTROL ALGO => (0) altitude control inactive (1) altitude control active */
|
'altitudeControlAlgorithm' => (1 << 4), /*!< ALTITUDE CONTROL ALGO => (0) altitude control inactive (1) altitude control active */
|
||||||
'startButtonState' => (1 << 5), /*!< USER feedback => Start button state */
|
'startButtonState' => (1 << 5), /*!< USER feedback => Start button state */
|
||||||
'controlCommandAck' => (1 << 6), /*!< Control command ACK => (0) None, (1) one received */
|
'controlCommandAck' => (1 << 6), /*!< Control command ACK => (0) None, (1) one received */
|
||||||
'cameraReady' => (1 << 7), /*!< CAMERA MASK => (0) camera not ready, (1) Camera ready */
|
'cameraReady' => (1 << 7), /*!< CAMERA MASK => (0) camera not ready, (1) Camera ready */
|
||||||
'travellingEnabled' => (1 << 8), /*!< Travelling mask => (0) disable, (1) enable */
|
'travellingEnabled' => (1 << 8), /*!< Travelling mask => (0) disable, (1) enable */
|
||||||
'usbReady' => (1 << 9), /*!< USB key => (0) usb key not ready, (1) usb key ready */
|
'usbReady' => (1 << 9), /*!< USB key => (0) usb key not ready, (1) usb key ready */
|
||||||
'navdataDemo' => (1 << 10), /*!< Navdata demo => (0) All navdata, (1) only navdata demo */
|
'navdataDemo' => (1 << 10), /*!< Navdata demo => (0) All navdata, (1) only navdata demo */
|
||||||
'navdataBootstrap' => (1 << 11), /*!< Navdata bootstrap => (0) options sent in all or demo mode, (1) no navdata options sent */
|
'navdataBootstrap' => (1 << 11), /*!< Navdata bootstrap => (0) options sent in all or demo mode, (1) no navdata options sent */
|
||||||
'motorProblem' => (1 << 12), /*!< Motors status => (0) Ok, (1) Motors problem */
|
'motorProblem' => (1 << 12), /*!< Motors status => (0) Ok, (1) Motors problem */
|
||||||
'communicationLost' => (1 << 13), /*!< Communication Lost => (1) com problem, (0) Com is ok */
|
'communicationLost' => (1 << 13), /*!< Communication Lost => (1) com problem, (0) Com is ok */
|
||||||
'softwareFault' => (1 << 14), /*!< Software fault detected - user should land as quick as possible (1) */
|
'softwareFault' => (1 << 14), /*!< Software fault detected - user should land as quick as possible (1) */
|
||||||
'lowBattery' => (1 << 15), /*!< VBat low => (1) too low, (0) Ok */
|
'lowBattery' => (1 << 15), /*!< VBat low => (1) too low, (0) Ok */
|
||||||
'userEmergencyLanding' => (1 << 16), /*!< User Emergency Landing => (1) User EL is ON, (0) User EL is OFF*/
|
'userEmergencyLanding' => (1 << 16), /*!< User Emergency Landing => (1) User EL is ON, (0) User EL is OFF*/
|
||||||
'timerElapsed' => (1 << 17), /*!< Timer elapsed => (1) elapsed, (0) not elapsed */
|
'timerElapsed' => (1 << 17), /*!< Timer elapsed => (1) elapsed, (0) not elapsed */
|
||||||
'MagnometerNeedsCalibration' => (1 << 18), /*!< Magnetometer calibration state => (0) Ok, no calibration needed, (1) not ok, calibration needed */
|
'MagnometerNeedsCalibration' => (1 << 18), /*!< Magnetometer calibration state => (0) Ok, no calibration needed, (1) not ok, calibration needed */
|
||||||
'anglesOutOfRange' => (1 << 19), /*!< Angles => (0) Ok, (1) out of range */
|
'anglesOutOfRange' => (1 << 19), /*!< Angles => (0) Ok, (1) out of range */
|
||||||
'tooMuchWind' => (1 << 20), /*!< WIND MASK=> (0) ok, (1) Too much wind */
|
'tooMuchWind' => (1 << 20), /*!< WIND MASK=> (0) ok, (1) Too much wind */
|
||||||
'ultrasonicSensorDeaf' => (1 << 21), /*!< Ultrasonic sensor => (0) Ok, (1) deaf */
|
'ultrasonicSensorDeaf' => (1 << 21), /*!< Ultrasonic sensor => (0) Ok, (1) deaf */
|
||||||
'cutoutDetected' => (1 << 22), /*!< Cutout system detection => (0) Not detected, (1) detected */
|
'cutoutDetected' => (1 << 22), /*!< Cutout system detection => (0) Not detected, (1) detected */
|
||||||
'picVersionNumberOk' => (1 << 23), /*!< PIC Version number OK => (0) a bad version number, (1) version number is OK */
|
'picVersionNumberOk' => (1 << 23), /*!< PIC Version number OK => (0) a bad version number, (1) version number is OK */
|
||||||
'atCodecThreadOn' => (1 << 24), /*!< ATCodec thread ON => (0) thread OFF (1) thread ON */
|
'atCodecThreadOn' => (1 << 24), /*!< ATCodec thread ON => (0) thread OFF (1) thread ON */
|
||||||
'navdataThreadOn' => (1 << 25), /*!< Navdata thread ON => (0) thread OFF (1) thread ON */
|
'navdataThreadOn' => (1 << 25), /*!< Navdata thread ON => (0) thread OFF (1) thread ON */
|
||||||
'videoThreadOn' => (1 << 26), /*!< Video thread ON => (0) thread OFF (1) thread ON */
|
'videoThreadOn' => (1 << 26), /*!< Video thread ON => (0) thread OFF (1) thread ON */
|
||||||
'acquisitionThreadOn' => (1 << 27), /*!< Acquisition thread ON => (0) thread OFF (1) thread ON */
|
'acquisitionThreadOn' => (1 << 27), /*!< Acquisition thread ON => (0) thread OFF (1) thread ON */
|
||||||
'controlWatchdogDelay' => (1 << 28), /*!< CTRL watchdog => (1) delay in control execution (> 5ms), (0) control is well scheduled */
|
'controlWatchdogDelay' => (1 << 28), /*!< CTRL watchdog => (1) delay in control execution (> 5ms), (0) control is well scheduled */
|
||||||
'adcWatchdogDelay' => (1 << 29), /*!< ADC Watchdog => (1) delay in uart2 dsr (> 5ms), (0) uart2 is good */
|
'adcWatchdogDelay' => (1 << 29), /*!< ADC Watchdog => (1) delay in uart2 dsr (> 5ms), (0) uart2 is good */
|
||||||
'comWatchdogProblem' => (1 << 30), /*!< Communication Watchdog => (1) com problem, (0) Com is ok */
|
'comWatchdogProblem' => (1 << 30), /*!< Communication Watchdog => (1) com problem, (0) Com is ok */
|
||||||
'emergencyLanding' => (1 << 31) /*!< Emergency landing : (0) no emergency, (1) emergency */
|
'emergencyLanding' => (1 << 31), /*!< Emergency landing : (0) no emergency, (1) emergency */
|
||||||
);
|
];
|
||||||
|
|
||||||
$this->buffer = new Buffer($binaryFrame);
|
$this->buffer = new Buffer($binaryFrame);
|
||||||
$this->options = array();
|
$this->options = [];
|
||||||
|
|
||||||
$this->header = $this->buffer->getUint32LE();
|
$this->header = $this->buffer->getUint32LE();
|
||||||
|
|
||||||
@@ -109,8 +108,8 @@ class Frame {
|
|||||||
{
|
{
|
||||||
$isChecksum = false;
|
$isChecksum = false;
|
||||||
|
|
||||||
while(!$isChecksum) {
|
while (!$isChecksum) {
|
||||||
$idOption = hexdec($this->buffer->getUint16LE());
|
$idOption = hexdec($this->buffer->getUint16LE());
|
||||||
$nameOption = Option::$optionIds[$idOption];
|
$nameOption = Option::$optionIds[$idOption];
|
||||||
$sizeOption = $this->buffer->getUint16LE();
|
$sizeOption = $this->buffer->getUint16LE();
|
||||||
|
|
||||||
@@ -119,19 +118,16 @@ class Frame {
|
|||||||
$expectedChecksum = 0;
|
$expectedChecksum = 0;
|
||||||
$checksum = $this->buffer->getUint32LE();
|
$checksum = $this->buffer->getUint32LE();
|
||||||
|
|
||||||
|
|
||||||
$data = $this->buffer->getData();
|
$data = $this->buffer->getData();
|
||||||
|
|
||||||
for ($i = 0; $i < $this->buffer->getLength() - $sizeOption; $i++) {
|
for ($i = 0; $i < $this->buffer->getLength() - $sizeOption; ++$i) {
|
||||||
$expectedChecksum = $expectedChecksum + hexdec(bin2hex($data[$i]));
|
$expectedChecksum = $expectedChecksum + hexdec(bin2hex($data[$i]));
|
||||||
}
|
}
|
||||||
$expectedChecksum = dechex($expectedChecksum);
|
$expectedChecksum = dechex($expectedChecksum);
|
||||||
|
|
||||||
|
|
||||||
if ($checksum !== $expectedChecksum) {
|
if ($checksum !== $expectedChecksum) {
|
||||||
throw new \Exception('Invalid checksum');
|
throw new \Exception('Invalid checksum');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$option = new Option($idOption, $this->buffer);
|
$option = new Option($idOption, $this->buffer);
|
||||||
@@ -142,7 +138,7 @@ class Frame {
|
|||||||
|
|
||||||
private function checkHeaderIntegrity()
|
private function checkHeaderIntegrity()
|
||||||
{
|
{
|
||||||
return ($this->header === '55667788' || $this->header === '55667789');
|
return $this->header === '55667788' || $this->header === '55667789';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getHeader()
|
public function getHeader()
|
||||||
@@ -173,22 +169,22 @@ class Frame {
|
|||||||
return $this->options;
|
return $this->options;
|
||||||
}
|
}
|
||||||
|
|
||||||
function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
$toString = '';
|
$toString = '';
|
||||||
|
|
||||||
$toString .= 'HEADER: ' . $this->getHeader() . PHP_EOL;
|
$toString .= 'HEADER: '.$this->getHeader().PHP_EOL;
|
||||||
$toString .= 'DRONE STATE: ' . print_r($this->getDroneState()) . PHP_EOL;
|
$toString .= 'DRONE STATE: '.print_r($this->getDroneState()).PHP_EOL;
|
||||||
$toString .= 'SEQUENCE NUMBER: ' . $this->getSequenceNumber() . PHP_EOL;
|
$toString .= 'SEQUENCE NUMBER: '.$this->getSequenceNumber().PHP_EOL;
|
||||||
$toString .= 'VISION FLAG: ' . $this->getVisionFlag() . PHP_EOL;
|
$toString .= 'VISION FLAG: '.$this->getVisionFlag().PHP_EOL;
|
||||||
|
|
||||||
foreach($this->getOptions() as $option) {
|
foreach ($this->getOptions() as $option) {
|
||||||
$toString .= '------------------------------------------' . PHP_EOL;
|
$toString .= '------------------------------------------'.PHP_EOL;
|
||||||
$toString .= 'OPTION: ' . $option->getOptionName() . PHP_EOL;
|
$toString .= 'OPTION: '.$option->getOptionName().PHP_EOL;
|
||||||
print_r($option->getData());
|
print_r($option->getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
$toString .= '==========================================' . PHP_EOL;
|
$toString .= '=========================================='.PHP_EOL;
|
||||||
|
|
||||||
return $toString;
|
return $toString;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone\Navdata;
|
namespace Joli\ArDrone\Navdata;
|
||||||
|
|
||||||
use Joli\ArDrone\Buffer\Buffer;
|
use Joli\ArDrone\Buffer\Buffer;
|
||||||
|
|
||||||
class Option {
|
class Option
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var \Joli\ArDrone\Buffer
|
* @var \Joli\ArDrone\Buffer
|
||||||
*/
|
*/
|
||||||
@@ -26,41 +28,42 @@ class Option {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @property array
|
* @property array
|
||||||
|
*
|
||||||
* @see from ARDrone_SDK_2_0/ARDroneLib/Soft/Common/navdata_keys.h
|
* @see from ARDrone_SDK_2_0/ARDroneLib/Soft/Common/navdata_keys.h
|
||||||
*/
|
*/
|
||||||
public static $optionIds = array(
|
public static $optionIds = [
|
||||||
0 => 'demo',
|
0 => 'demo',
|
||||||
1 => 'time',
|
1 => 'time',
|
||||||
2 => 'rawMeasures',
|
2 => 'rawMeasures',
|
||||||
3 => 'physMeasures',
|
3 => 'physMeasures',
|
||||||
4 => 'gyrosOffsets',
|
4 => 'gyrosOffsets',
|
||||||
5 => 'eulerAngles',
|
5 => 'eulerAngles',
|
||||||
6 => 'references',
|
6 => 'references',
|
||||||
7 => 'trims',
|
7 => 'trims',
|
||||||
8 => 'rcReferences',
|
8 => 'rcReferences',
|
||||||
9 => 'pwm',
|
9 => 'pwm',
|
||||||
10 => 'altitude',
|
10 => 'altitude',
|
||||||
11 => 'visionRaw',
|
11 => 'visionRaw',
|
||||||
12 => 'visionOf',
|
12 => 'visionOf',
|
||||||
13 => 'vision',
|
13 => 'vision',
|
||||||
14 => 'visionPerf',
|
14 => 'visionPerf',
|
||||||
15 => 'trackersSend',
|
15 => 'trackersSend',
|
||||||
16 => 'visionDetect',
|
16 => 'visionDetect',
|
||||||
17 => 'watchdog',
|
17 => 'watchdog',
|
||||||
18 => 'adcDataFrame',
|
18 => 'adcDataFrame',
|
||||||
19 => 'videoStream',
|
19 => 'videoStream',
|
||||||
20 => 'games',
|
20 => 'games',
|
||||||
21 => 'pressureRaw',
|
21 => 'pressureRaw',
|
||||||
22 => 'magneto',
|
22 => 'magneto',
|
||||||
23 => 'windSpeed',
|
23 => 'windSpeed',
|
||||||
24 => 'kalmanPressure',
|
24 => 'kalmanPressure',
|
||||||
25 => 'hdvideoStream',
|
25 => 'hdvideoStream',
|
||||||
26 => 'wifi',
|
26 => 'wifi',
|
||||||
27 => 'zimmu3000',
|
27 => 'zimmu3000',
|
||||||
65535 => 'checksum'
|
65535 => 'checksum',
|
||||||
);
|
];
|
||||||
|
|
||||||
public static $controlState = array(
|
public static $controlState = [
|
||||||
0 => 'CTRL_DEFAULT',
|
0 => 'CTRL_DEFAULT',
|
||||||
1 => 'CTRL_INIT',
|
1 => 'CTRL_INIT',
|
||||||
2 => 'CTRL_LANDED',
|
2 => 'CTRL_LANDED',
|
||||||
@@ -70,25 +73,25 @@ class Option {
|
|||||||
6 => 'CTRL_TRANS_TAKEOFF',
|
6 => 'CTRL_TRANS_TAKEOFF',
|
||||||
7 => 'CTRL_TRANS_GOTOFIX',
|
7 => 'CTRL_TRANS_GOTOFIX',
|
||||||
8 => 'CTRL_TRANS_LANDING',
|
8 => 'CTRL_TRANS_LANDING',
|
||||||
9 => 'CTRL_TRANS_LOOPING'
|
9 => 'CTRL_TRANS_LOOPING',
|
||||||
);
|
];
|
||||||
|
|
||||||
public static $flyState = array(
|
public static $flyState = [
|
||||||
0 => 'FLYING_OK',
|
0 => 'FLYING_OK',
|
||||||
1 => 'FLYING_LOST_ALT',
|
1 => 'FLYING_LOST_ALT',
|
||||||
2 => 'FLYING_LOST_ALT_GO_DOWN',
|
2 => 'FLYING_LOST_ALT_GO_DOWN',
|
||||||
3 => 'FLYING_ALT_OUT_ZONE',
|
3 => 'FLYING_ALT_OUT_ZONE',
|
||||||
4 => 'FLYING_COMBINED_YAW',
|
4 => 'FLYING_COMBINED_YAW',
|
||||||
5 => 'FLYING_BRAKE',
|
5 => 'FLYING_BRAKE',
|
||||||
6 => 'FLYING_NO_VISION'
|
6 => 'FLYING_NO_VISION',
|
||||||
);
|
];
|
||||||
|
|
||||||
public function __construct($idOption, Buffer $buffer)
|
public function __construct($idOption, Buffer $buffer)
|
||||||
{
|
{
|
||||||
$this->buffer = $buffer;
|
$this->buffer = $buffer;
|
||||||
$this->idOption = $idOption;
|
$this->idOption = $idOption;
|
||||||
$this->data = array();
|
$this->data = [];
|
||||||
$this->name = Option::$optionIds[$idOption];
|
$this->name = self::$optionIds[$idOption];
|
||||||
$this->processOption();
|
$this->processOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,154 +116,153 @@ class Option {
|
|||||||
|
|
||||||
private function getDemoOptionData()
|
private function getDemoOptionData()
|
||||||
{
|
{
|
||||||
$flyState = Option::$flyState[$this->buffer->getUint16LE()];
|
$flyState = self::$flyState[$this->buffer->getUint16LE()];
|
||||||
$controlState = Option::$controlState[$this->buffer->getUint16LE()];
|
$controlState = self::$controlState[$this->buffer->getUint16LE()];
|
||||||
$batteryPercentage = $this->buffer->getUint32LE();
|
$batteryPercentage = $this->buffer->getUint32LE();
|
||||||
$theta = $this->buffer->getFloat32() / 1000; // [mdeg]
|
$theta = $this->buffer->getFloat32() / 1000; // [mdeg]
|
||||||
$phi = $this->buffer->getFloat32() / 1000; // [mdeg]
|
$phi = $this->buffer->getFloat32() / 1000; // [mdeg]
|
||||||
$psi = $this->buffer->getFloat32() / 1000; // [mdeg]
|
$psi = $this->buffer->getFloat32() / 1000; // [mdeg]
|
||||||
$altitude = $this->buffer->getUint32LE() / 1000; // [mm]
|
$altitude = $this->buffer->getUint32LE() / 1000; // [mm]
|
||||||
$velocity = $this->buffer->getVector31(); // [mm/s]
|
$velocity = $this->buffer->getVector31(); // [mm/s]
|
||||||
$frameIndex = $this->buffer->getUint32LE();
|
$frameIndex = $this->buffer->getUint32LE();
|
||||||
|
|
||||||
$detection = array(
|
$detection = [
|
||||||
'camera' => array(
|
'camera' => [
|
||||||
'rotation' => $this->buffer->getMatrix33(),
|
'rotation' => $this->buffer->getMatrix33(),
|
||||||
'translation' => $this->buffer->getVector31()
|
'translation' => $this->buffer->getVector31(),
|
||||||
),
|
],
|
||||||
'tagIndex' => $this->buffer->getUint32LE()
|
'tagIndex' => $this->buffer->getUint32LE(),
|
||||||
);
|
];
|
||||||
|
|
||||||
$detection['camera']['type'] = $this->buffer->getUint32LE();
|
$detection['camera']['type'] = $this->buffer->getUint32LE();
|
||||||
|
|
||||||
$drone = array(
|
$drone = [
|
||||||
'camera' => array(
|
'camera' => [
|
||||||
'rotation' => $this->buffer->getMatrix33(),
|
'rotation' => $this->buffer->getMatrix33(),
|
||||||
'translation' => $this->buffer->getVector31()
|
'translation' => $this->buffer->getVector31(),
|
||||||
),
|
],
|
||||||
);
|
];
|
||||||
|
|
||||||
$rotation = array(
|
$rotation = [
|
||||||
'frontBack' => $theta,
|
'frontBack' => $theta,
|
||||||
'pitch' => $theta,
|
'pitch' => $theta,
|
||||||
'theta' => $theta,
|
'theta' => $theta,
|
||||||
'y' => $theta,
|
'y' => $theta,
|
||||||
'leftRight' => $phi,
|
'leftRight' => $phi,
|
||||||
'roll' => $phi,
|
'roll' => $phi,
|
||||||
'phi' => $phi,
|
'phi' => $phi,
|
||||||
'x' => $phi,
|
'x' => $phi,
|
||||||
'clockwise' => $psi,
|
'clockwise' => $psi,
|
||||||
'yaw' => $psi,
|
'yaw' => $psi,
|
||||||
'psi' => $psi,
|
'psi' => $psi,
|
||||||
'z' => $psi
|
'z' => $psi,
|
||||||
);
|
];
|
||||||
|
|
||||||
$data = array(
|
$data = [
|
||||||
'controlState' => $controlState,
|
'controlState' => $controlState,
|
||||||
'flyState' => $flyState,
|
'flyState' => $flyState,
|
||||||
'batteryPercentage' => hexdec($batteryPercentage),
|
'batteryPercentage' => hexdec($batteryPercentage),
|
||||||
'rotation' => $rotation,
|
'rotation' => $rotation,
|
||||||
'frontBackDegrees' => $theta,
|
'frontBackDegrees' => $theta,
|
||||||
'leftRightDegrees' => $phi,
|
'leftRightDegrees' => $phi,
|
||||||
'clockwiseDegrees' => $psi,
|
'clockwiseDegrees' => $psi,
|
||||||
'altitude' => $altitude,
|
'altitude' => $altitude,
|
||||||
'altitudeMeters' => $altitude,
|
'altitudeMeters' => $altitude,
|
||||||
'velocity' => $velocity,
|
'velocity' => $velocity,
|
||||||
'xVelocity' => $velocity['x'],
|
'xVelocity' => $velocity['x'],
|
||||||
'yVelocity' => $velocity['y'],
|
'yVelocity' => $velocity['y'],
|
||||||
'zVelocity' => $velocity['z'],
|
'zVelocity' => $velocity['z'],
|
||||||
'frameIndex' => $frameIndex,
|
'frameIndex' => $frameIndex,
|
||||||
'detection' => $detection,
|
'detection' => $detection,
|
||||||
'drone' => $drone
|
'drone' => $drone,
|
||||||
);
|
];
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getVisionDetectData()
|
private function getVisionDetectData()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'nbDetected' => $this->buffer->getUint32LE(),
|
'nbDetected' => $this->buffer->getUint32LE(),
|
||||||
'type' => $this->timesMap(4, 'uint32LE'),
|
'type' => $this->timesMap(4, 'uint32LE'),
|
||||||
'xc' => $this->timesMap(4, 'uint32LE'),
|
'xc' => $this->timesMap(4, 'uint32LE'),
|
||||||
'yc' => $this->timesMap(4, 'uint32LE'),
|
'yc' => $this->timesMap(4, 'uint32LE'),
|
||||||
'width' => $this->timesMap(4, 'uint32LE'),
|
'width' => $this->timesMap(4, 'uint32LE'),
|
||||||
'height' => $this->timesMap(4, 'uint32LE'),
|
'height' => $this->timesMap(4, 'uint32LE'),
|
||||||
'dist' => $this->timesMap(4, 'uint32LE'),
|
'dist' => $this->timesMap(4, 'uint32LE'),
|
||||||
'orientationAngle' => $this->timesMap(4, 'float32'),
|
'orientationAngle' => $this->timesMap(4, 'float32'),
|
||||||
'rotation' => $this->timesMap(4, 'matrix33'),
|
'rotation' => $this->timesMap(4, 'matrix33'),
|
||||||
'translation' => $this->timesMap(4, 'vector31'),
|
'translation' => $this->timesMap(4, 'vector31'),
|
||||||
'cameraSource' => $this->timesMap(4, 'uint32LE')
|
'cameraSource' => $this->timesMap(4, 'uint32LE'),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPwmData()
|
private function getPwmData()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'motor' => $this->timesMap(4, 'uint8'),
|
'motor' => $this->timesMap(4, 'uint8'),
|
||||||
'satMotors' => $this->timesMap(4, 'uint8'),
|
'satMotors' => $this->timesMap(4, 'uint8'),
|
||||||
'gazFeedForward' => $this->buffer->getFloat32(),
|
'gazFeedForward' => $this->buffer->getFloat32(),
|
||||||
'gazAltitude' => $this->buffer->getFloat32(),
|
'gazAltitude' => $this->buffer->getFloat32(),
|
||||||
'altitudeIntegral' => $this->buffer->getFloat32(),
|
'altitudeIntegral' => $this->buffer->getFloat32(),
|
||||||
'vzRef' => $this->buffer->getFloat32(),
|
'vzRef' => $this->buffer->getFloat32(),
|
||||||
'uPitch' => $this->buffer->getInt32(),
|
'uPitch' => $this->buffer->getInt32(),
|
||||||
'uRoll' => $this->buffer->getInt32(),
|
'uRoll' => $this->buffer->getInt32(),
|
||||||
'uYaw' => $this->buffer->getInt32(),
|
'uYaw' => $this->buffer->getInt32(),
|
||||||
'yawUI' => $this->buffer->getFloat32(),
|
'yawUI' => $this->buffer->getFloat32(),
|
||||||
'uPitchPlanif' => $this->buffer->getInt32(),
|
'uPitchPlanif' => $this->buffer->getInt32(),
|
||||||
'uRollPlanif' => $this->buffer->getInt32(),
|
'uRollPlanif' => $this->buffer->getInt32(),
|
||||||
'uYawPlanif' => $this->buffer->getInt32(),
|
'uYawPlanif' => $this->buffer->getInt32(),
|
||||||
'uGazPlanif' => $this->buffer->getFloat32(),
|
'uGazPlanif' => $this->buffer->getFloat32(),
|
||||||
'motorCurrents' => $this->timesMap(4, 'uint16LE'),
|
'motorCurrents' => $this->timesMap(4, 'uint16LE'),
|
||||||
'altitudeProp' => $this->buffer->getFloat32(),
|
'altitudeProp' => $this->buffer->getFloat32(),
|
||||||
'altitudeDer' => $this->buffer->getFloat32()
|
'altitudeDer' => $this->buffer->getFloat32(),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPhysMeasuresData()
|
private function getPhysMeasuresData()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
'temperature' => array(
|
'temperature' => [
|
||||||
'accelerometer' => $this->buffer->getFloat32(),
|
'accelerometer' => $this->buffer->getFloat32(),
|
||||||
'gyroscope' => $this->buffer->getUint16LE()
|
'gyroscope' => $this->buffer->getUint16LE(),
|
||||||
),
|
],
|
||||||
'accelerometers' => $this->buffer->getVector31(),
|
'accelerometers' => $this->buffer->getVector31(),
|
||||||
'gyroscopes' => $this->buffer->getVector31(),
|
'gyroscopes' => $this->buffer->getVector31(),
|
||||||
'alim3V3' => $this->buffer->getUint32LE(),
|
'alim3V3' => $this->buffer->getUint32LE(),
|
||||||
'vrefEpson' => $this->buffer->getUint32LE(),
|
'vrefEpson' => $this->buffer->getUint32LE(),
|
||||||
'vrefIDG' => $this->buffer->getUint32LE()
|
'vrefIDG' => $this->buffer->getUint32LE(),
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function timesMap($n, $type)
|
private function timesMap($n, $type)
|
||||||
{
|
{
|
||||||
$data = array();
|
$data = [];
|
||||||
|
|
||||||
for($i = 0; $i < $n; $i++) {
|
for ($i = 0; $i < $n; ++$i) {
|
||||||
$value = null;
|
$value = null;
|
||||||
|
|
||||||
if ($type === 'uint32LE') {
|
if ($type === 'uint32LE') {
|
||||||
$value = $this->buffer->getUint32LE();
|
$value = $this->buffer->getUint32LE();
|
||||||
} else if ($type === 'uint16LE') {
|
} elseif ($type === 'uint16LE') {
|
||||||
$value = $this->buffer->getUint16LE();
|
$value = $this->buffer->getUint16LE();
|
||||||
} else if ($type === 'float32') {
|
} elseif ($type === 'float32') {
|
||||||
$value = $this->buffer->getFloat32();
|
$value = $this->buffer->getFloat32();
|
||||||
} else if ($type === 'matrix33') {
|
} elseif ($type === 'matrix33') {
|
||||||
$value = $this->buffer->getMatrix33();
|
$value = $this->buffer->getMatrix33();
|
||||||
} else if ($type === 'vector31') {
|
} elseif ($type === 'vector31') {
|
||||||
$value = $this->buffer->getVector31();
|
$value = $this->buffer->getVector31();
|
||||||
} else if ($type === 'uint8') {
|
} elseif ($type === 'uint8') {
|
||||||
$value = $this->buffer->getUint8();
|
$value = $this->buffer->getUint8();
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($data, $value);
|
array_push($data, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOptionName()
|
public function getOptionName()
|
||||||
{
|
{
|
||||||
return Option::$optionIds[$this->idOption];
|
return self::$optionIds[$this->idOption];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ namespace Joli\ArDrone\Navdata;
|
|||||||
|
|
||||||
use Evenement\EventEmitter;
|
use Evenement\EventEmitter;
|
||||||
use Joli\ArDrone\Config\Config;
|
use Joli\ArDrone\Config\Config;
|
||||||
use React\Datagram\Factory AS UdpFactory;
|
use React\Datagram\Factory as UdpFactory;
|
||||||
use React\Datagram\Socket AS UdpSocket;
|
use React\Datagram\Socket as UdpSocket;
|
||||||
use Joli\ArDrone\Navdata\Frame;
|
|
||||||
|
|
||||||
class UdpNavdata extends EventEmitter
|
class UdpNavdata extends EventEmitter
|
||||||
{
|
{
|
||||||
@@ -28,7 +27,7 @@ class UdpNavdata extends EventEmitter
|
|||||||
public function __construct($loop)
|
public function __construct($loop)
|
||||||
{
|
{
|
||||||
$this->port = Config::CONTROL_PORT;
|
$this->port = Config::CONTROL_PORT;
|
||||||
$this->ip = Config::DRONE_IP;
|
$this->ip = Config::DRONE_IP;
|
||||||
$this->loop = $loop;
|
$this->loop = $loop;
|
||||||
|
|
||||||
$this->start();
|
$this->start();
|
||||||
@@ -36,11 +35,9 @@ class UdpNavdata extends EventEmitter
|
|||||||
|
|
||||||
private function start()
|
private function start()
|
||||||
{
|
{
|
||||||
|
|
||||||
// $socket = $this->socket;
|
|
||||||
$udpFactory = new UdpFactory($this->loop);
|
$udpFactory = new UdpFactory($this->loop);
|
||||||
$udpNavdata = $this;
|
$udpNavdata = $this;
|
||||||
//var_dump(Config::DRONE_IP); var_dump(Config::NAVDATA_PORT);die();
|
|
||||||
// Navdata stream
|
// Navdata stream
|
||||||
$udpFactory->createClient(Config::DRONE_IP.':'.Config::NAVDATA_PORT)->then(function (UdpSocket $client) use (&$udpNavdata) {
|
$udpFactory->createClient(Config::DRONE_IP.':'.Config::NAVDATA_PORT)->then(function (UdpSocket $client) use (&$udpNavdata) {
|
||||||
// Start dialog
|
// Start dialog
|
||||||
@@ -48,10 +45,10 @@ class UdpNavdata extends EventEmitter
|
|||||||
$client->send('1');
|
$client->send('1');
|
||||||
|
|
||||||
$client->on('message',
|
$client->on('message',
|
||||||
function($message) use (&$udpNavdata) {
|
function ($message) use (&$udpNavdata) {
|
||||||
$frame = new Frame($message);
|
$frame = new Frame($message);
|
||||||
$udpNavdata->emit('navdata', array($frame));
|
$udpNavdata->emit('navdata', [$frame]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Joli\ArDrone;
|
namespace Joli\ArDrone;
|
||||||
|
|
||||||
use Evenement\EventEmitter;
|
use Evenement\EventEmitter;
|
||||||
use Joli\ArDrone\Config\Config;
|
use Joli\ArDrone\Config\Config;
|
||||||
|
|
||||||
class Repl extends EventEmitter {
|
class Repl extends EventEmitter
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @var \React\EventLoop\LibEventLoop|\React\EventLoop\StreamSelectLoop
|
* @var \React\EventLoop\LibEventLoop|\React\EventLoop\StreamSelectLoop
|
||||||
*/
|
*/
|
||||||
@@ -18,7 +19,7 @@ class Repl extends EventEmitter {
|
|||||||
|
|
||||||
public function __construct($loop)
|
public function __construct($loop)
|
||||||
{
|
{
|
||||||
$this->loop = $loop;
|
$this->loop = $loop;
|
||||||
$this->prompt = 'drone> ';
|
$this->prompt = 'drone> ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,14 +31,14 @@ class Repl extends EventEmitter {
|
|||||||
$this->loop->addReadStream(STDIN, function ($stdin) use ($that) {
|
$this->loop->addReadStream(STDIN, function ($stdin) use ($that) {
|
||||||
$input = trim(fgets($stdin));
|
$input = trim(fgets($stdin));
|
||||||
|
|
||||||
if(in_array($input, Config::$commands)) {
|
if (in_array($input, Config::$commands)) {
|
||||||
if($input === 'exit') {
|
if ($input === 'exit') {
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
$that->emit('action', array($input));
|
$that->emit('action', [$input]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo 'Unknown command' . PHP_EOL;
|
echo 'Unknown command'.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $that->prompt;
|
echo $that->prompt;
|
||||||
@@ -48,7 +49,8 @@ class Repl extends EventEmitter {
|
|||||||
echo $this->prompt;
|
echo $this->prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getAsciiArt() {
|
private function getAsciiArt()
|
||||||
|
{
|
||||||
return "
|
return "
|
||||||
_ __ | |__ _ __ __ _ _ __ __| |_ __ ___ _ __ ___
|
_ __ | |__ _ __ __ _ _ __ __| |_ __ ___ _ __ ___
|
||||||
| '_ \| '_ \| '_ \ _____ / _` | '__|____ / _` | '__/ _ \| '_ \ / _ \
|
| '_ \| '_ \| '_ \ _____ / _` | '__|____ / _` | '__/ _ \| '_ \ / _ \
|
||||||
@@ -57,4 +59,4 @@ class Repl extends EventEmitter {
|
|||||||
|_| |_|
|
|_| |_|
|
||||||
";
|
";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Referência em uma Nova Issue
Bloquear um usuário