Giter Site home page Giter Site logo

leshak / egts-protocol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kuznetsovin/egts-protocol

0.0 0.0 0.0 4.2 MB

EGTS protocol receiver write on Golang

Home Page: https://www.swe-notes.ru/post/protocol-egts/

License: GNU General Public License v3.0

Go 99.09% Python 0.62% Makefile 0.29%

egts-protocol's Introduction

EGTS receiver

EGTS receiver server realization writen on Go.

Library for implementation EGTS protocol that parsing binary packag based on GOST R 54619 - 2011 and Order No. 285 of the Ministry of Transport of Russia dated July 31, 2012. Describe fields you can find in these documents.

More information you can read in article (Russian).

Server save all navigation data from EGTS_SR_POS_DATA section. If packet have several records with EGTS_SR_POS_DATA section, it saves all of them.

Storage for data realized as plugins. Any plugin must have [store] section in configure file. Plugin interface will be described below.

If configure file has't section for a plugin ([store]), then packet will be print to stdout.

Install

git clone https://github.com/kuznetsovin/egts-protocol
cd egts-protocol
make

Run

./receiver config.toml

config.toml - configure file

Config format

[srv]
host = "127.0.0.1"
port = "6000"
con_ttl = 10
log_level = "DEBUG"

Parameters description:

  • host - bind address
  • port - bind port
  • conn_ttl - if server not received data longer time in the parameter, then the connection is closed.
  • log_level - logging level

Usage only Golang EGTS library

Example for encoding packet:

package main 

import (
    "github.com/kuznetsovin/egts-protocol/libs/egts"
    "log"
)

func main() {
    pkg := egts.Package{
    		ProtocolVersion:  1,
    		SecurityKeyID:    0,
    		Prefix:           "00",
    		Route:            "0",
    		EncryptionAlg:    "00",
    		Compression:      "0",
    		Priority:         "11",
    		HeaderLength:     11,
    		HeaderEncoding:   0,
    		FrameDataLength:  3,
    		PacketIdentifier: 137,
    		PacketType:       egts.PtResponsePacket,
    		HeaderCheckSum:   74,
    		ServicesFrameData: &egts.PtResponse{
    			ResponsePacketID: 14357,
    			ProcessingResult: 0,
    		},
    	}
    
    rawPkg, err := pkg.Encode()
	if err != nil {
		log.Fatal(err)
	}
    
    log.Println("Bytes packet: ", rawPkg)
}

Example for decoding packet:

package main 

import (
    "github.com/kuznetsovin/egts-protocol/libs/egts"
    "log"
)

func main() {
    pkg := []byte{0x01, 0x00, 0x03, 0x0B, 0x00, 0x03, 0x00, 0x89, 0x00, 0x00, 0x4A, 0x15, 0x38, 0x00, 0x33, 0xE8}
    result := egts.Package{}

    state, err := result.Decode(pkg)
    if err != nil {
 		log.Fatal(err)
 	}
    
    log.Println("State: ", state)
    log.Println("Package: ", result)
}

Store plugins

That create a new plugin you must implement Connector interface:

type Connector interface {
	// setup store connection
	Init(map[string]string) error
	
	// save to store method
	Save(interface{ ToBytes() ([]byte, error) }) error
	
	// close connection with store
	Close() error
}

All plugins available in store folder.

egts-protocol's People

Contributors

imhy avatar jinsem avatar kuznetsovin avatar rowdyroad avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.