1. Go to this page and download the library: Download track-any-device/drivers library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
track-any-device / drivers example snippets
use TrackAnyDevice\Drivers\Contracts\DeviceDriverInterface;
class HandleIncomingSignal
{
public function __construct(private DeviceDriverInterface $driver) {}
public function handle(array $rawEvent, Device $device): void
{
$signal = $this->driver->parseEventToSignal($rawEvent, $device);
// $signal is a normalised SignalObject regardless of device model
}
}
// true when device has reported within the last 10 minutes
$driver->supportsStream($device);
// 'jt808' | 'none'
$driver->getStreamChannel();
use TrackAnyDevice\Drivers\Concerns\QueuesSmsCommands;
use TrackAnyDevice\Drivers\Contracts\DeviceDriverInterface;
use TrackAnyDevice\Drivers\ValueObjects\AddOnCommand;
use TrackAnyDevice\Drivers\ValueObjects\SignalObject;
use TrackAnyDevice\Core\Models\Device;
class MyTrackerDriver implements DeviceDriverInterface
{
use QueuesSmsCommands;
public function getStreamChannel(): string { return 'none'; }
public function supportsStream(Device $device): bool { return false; }
public function parseEventToSignal(array $rawEvent, Device $device): SignalObject
{
return $this->parseSmsToSignal((string) ($rawEvent['raw'] ?? ''), $device);
}
public function parseSmsToSignal(string $rawSms, Device $device): SignalObject
{
// parse $rawSms and return a SignalObject — never throw
return new SignalObject(
eventType: SignalEventType::Update,
source: SignalSource::GsmSms,
rawPayload: $rawSms,
);
}
public function requestSignal(string $signalType, Device $device): void
{
$this->queueSms('query_location', [], $device);
}
public function setMode(string $mode, Device $device, array $params = []): void {}
public function getMode(Device $device): ?string { return null; }
public function onboardingAction(Device $device): void {}
public function addOnCommands(): array { return []; }
public function addOnCommand(string $commandName, array $parameters, Device $device): void
{
$this->queueSms($commandName, $parameters, $device);
}
public function buildSmsBody(string $commandType, array $params): ?string
{
return match ($commandType) {
'query_location' => 'WHERE#',
default => null,
};
}
}
// In a service provider
$this->app->bind(DeviceConnectorInterface::class, SMSConnector::class);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.