lis1a2

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

LIS1A2 - A Go library

Standard implementation for the lis1a2 protocol. This library is extensible, so instead of using a TCP connection, the user can use any other standard for communication like RS232 provided it adheres to the Connection interface provided in the library.

Features

  • Adheres to LIS1A2 Standard
  • Implementation for TCP Connection adhering to Connection interface is provided.

Installation

go get github.com/SigTuple/lis1a2

Usage

The user needs to initialize the Connection object. We'll use the TCP implementation bundled with the library. The user needs to use the connection object to create a ASTM Connection.

package main

import (
	"log"

	"github.com/SigTuple/lis1a2"
	"github.com/SigTuple/lis1a2/connection"
)

func main() {
	var tcpConn = connection.NewTCPConnection("localhost", "4000")

	var astmConn = lis1a2.NewASTMConnection(&tcpConn, false)
	err := astmConn.Connect()
	if err != nil {
		log.Fatalf("Failed to connect to the ASTM Service")
	}
	defer func(astmConn *lis1a2.ASTMConnection) {
		err := astmConn.Disconnect()
		if err != nil {

		}
	}(astmConn)
}

To send a new message to the astm connection the user needs to establish send mode

package main

import (
	"log"
	
	"github.com/SigTuple/lis1a2"
)

func SendMessageToConnection(astmConn lis1a2.ASTMConnection, data []byte) {
	establishedSendMode := astmConn.EstablishSendMode()
	if !establishedSendMode {
		log.Fatal("Could not establish send mode.")
	}
	astmConn.SendMessage(data)
	astmConn.StopSendMode()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ASTMConnection

type ASTMConnection struct {
	// contains filtered or unexported fields
}

func NewASTMConnection

func NewASTMConnection(conn connection.Connection, saveIncomingMessage bool, incomingMessageSaveDir ...string) *ASTMConnection

func (*ASTMConnection) CalculateChecksum

func (astmConn *ASTMConnection) CalculateChecksum(frame []byte) []byte

CalculateChecksum calculates the checksum of the given frame

func (*ASTMConnection) CheckChecksum

func (astmConn *ASTMConnection) CheckChecksum(frame []byte) bool

CheckChecksum calculates the checksum of the frame

func (*ASTMConnection) Connect

func (astmConn *ASTMConnection) Connect() error

Connect runs connect method of underlying Connection object

func (*ASTMConnection) Disconnect

func (astmConn *ASTMConnection) Disconnect() error

Disconnect runs the disconnect method of underlying Connection object and also closes channels

func (*ASTMConnection) EstablishSendMode

func (astmConn *ASTMConnection) EstablishSendMode() bool

EstablishSendMode sends an ENQ and waits for ACK/NAK

func (*ASTMConnection) IsConnected

func (astmConn *ASTMConnection) IsConnected() bool

IsConnected checks the connection status of the underlying connection object

func (*ASTMConnection) Listen

func (astmConn *ASTMConnection) Listen()

Listen listens to the incoming messages over the connection

func (*ASTMConnection) ReadMessage

func (astmConn *ASTMConnection) ReadMessage(timeout time.Duration) (string, error)

ReadMessage reads a single ASTM Message from the connection.

func (*ASTMConnection) SendMessage

func (astmConn *ASTMConnection) SendMessage(message []byte)

SendMessage takes single ASTM Record as input and sends it as one or more frames over the connection

func (*ASTMConnection) StopSendMode

func (astmConn *ASTMConnection) StopSendMode()

StopSendMode send an EOT byte and changes status to Idle

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL