Skip to content

elementaire/teltonika-fm-parser

 
 

Repository files navigation

Teltonika FM-XXXX Parser

Build Status Scrutinizer Code Quality CodeFactor Latest Stable Version Total Downloads

This repository is object oriented library to translate Teltonika protocols.

You could use this library in your server, it will help you talk with Teltonika devices.

It was build with Teltonika protocols v2.10 documentation.

Requirements:

{
    "require": {
        "php": ">=7.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^5.7"
    }
}

Usage:

$parser = new FmParser('tcp');

// Decode IMEI
$imei = $parser->decodeImei($payload);

// Decode Data Packet
$packet = $parser->decodeData($payload);

Examples

TCP

	$parser = new FmParser('tcp');
	$socket = stream_socket_server("tcp://0.0.0.0:8043", $errno, $errstr);
	if (!$socket) {
		throw new \Exception("$errstr ($errno)");
	} else {
		while ($conn = stream_socket_accept($socket)) {

			// Read IMEI
			$payload = fread($conn, 1024);
			$imei = $parser->decodeImei($payload);

			// Accept packet
			fwrite($conn, Reply::accept());

			// Decline packet
			// fwrite($conn, Reply::reject());
			
			// Read Data
			$payload = fread($conn, 1024);
			$packet = $parser->decodeData($payload);

			// Send acknowledge
			fwrite($conn, $parser->encodeAcknowledge($packet));

			// Close connection
			fclose($conn);
		}

		fclose($socket);
	}
}

License:

Public domain

About

Teltonika fm xxxx protocol encoder and decoder

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 98.6%
  • Other 1.4%