Skip to content

taka-wang/psmb

Repository files navigation

psmb

Docker GoDoc Go Report Card codecov

Proactive service library for modbusd


Continuous Integration

I do continuous integration and deploy docker images after git push by self-hosted drone.io server, circleci service, codecov service and dockerhub service.

CI Server Target Status
CircleCI x86 CircleCI
Travis x86 Build Status
Drone armhf Drone

Environment variables

Why environment variable? Refer to the 12 factors

  • CONF_PSMBTCP: config file path
  • EP_BACKEND: endpoint of remote service discovery server (optional)

Contracts (Interfaces)

  • IProactiveService: proactive service
  • IReaderTaskDataStore: read/poll task data store
  • IWriterTaskDataStore: write task data store
  • IHistoryDataStore: history data store
  • IFilterDataStore: filter data store
  • IConfig: config management

Golang package management

  • I adopted glide as package management system for this repository.

Worker Pool Model

Request from upstream

uml

Response from downstream

uml


Up and Running

Docker Compose

docker-compose build --pull
docker-compose up

Manually

Install libzmq (3.2.5)

wget https://github.com/zeromq/zeromq3-x/releases/download/v3.2.5/zeromq-3.2.5.tar.gz
tar xvzf zeromq-3.2.5.tar.gz
cd zeromq-3.2.5
./configure
make
sudo make install
sudo ldconfig

Build

# install glide
curl https://glide.sh/get | sh

# install dependencies
glide up

# build
cd tcp-srv
go build -o psmbtcp-srv

Deployment Diagram

uml


Unit tests

  • binary
  • types

Test cases

Binary

  • Bytes to 16-bit integer array tests
    • BytesToUInt16s in big endian order - (1/4)
    • BytesToUInt16s in little endian order - (2/4)
    • BytesToInt16s in big endian order - (3/4)
    • BytesToInt16s in little endian order - (4/4)
  • Bytes to 32-bit integer array tests
    • BytesToUInt32s in (ABCD) Big Endian order - (1/4)
    • BytesToUInt32s in (DCBA) Little Endian order - (2/4)
    • BytesToUInt32s in (BADC) Mid-Big Endian order - (3/4)
    • BytesToUInt32s in (CDAB) Mid-Little Endian order - (4/4)
    • BytesToInt32s in (ABCD) Big Endian order - (1/4)
    • BytesToInt32s in (DCBA) Little Endian order - (2/4)
    • BytesToInt32s in (BADC) Mid-Big Endian order - (3/4)
    • BytesToInt32s in (CDAB) Mid-Little Endian order - (4/4)
  • Bytes to 32-bit float array tests
    • BytesToFloat32s in (ABCD) Big Endian order - (1/4)
    • BytesToFloat32s in (DCBA) Little Endian order - (2/4)
    • BytesToFloat32s in (BADC) Mid-Big Endian order - (3/4)
    • BytesToFloat32s in (CDAB) Mid-Little Endian order - (4/4)
  • Bytes/registers utility tests
    • BitStringToUInt8s test
    • BitStringToUInt8s test - left comma
    • BitStringToUInt8s test - right comma
    • BitStringToUInt8s test - left, right comma
    • RegistersToBytes test
    • BytesToHexString test
    • DecimalStringToRegisters test
    • DecimalStringToRegisters test - left comma
    • DecimalStringToRegisters test - right comma
    • DecimalStringToRegisters test - left, right comma
    • HexStringToRegisters test
    • HexStringToRegisters test - wrong length
    • LinearScalingRegisters test
    • LinearScalingRegisters test - (0,0,0,0)
    • LinearScalingRegisters test - reverse

Types

Upstream structure test

  • One-off modbus tcp struct tests
    • mbtcp.once.read request test
    • mbtcp.once.read response test
  • get/set modbus tcp timeout struct tests
    • mbtcp.timeout.read request test
    • mbtcp.timeout.read response test
    • mbtcp.timeout.update request test
    • mbtcp.timeout.update response test
    • mbtcp.once.write request test
    • mbtcp.once.write response test

Downstream structure test

  • modbus tcp downstreamstruct tests
    • read request test
    • single read response test
    • multiple read response test
    • single write request test
    • multiple write request test
    • set timeout request test
    • get timeout response test

UML

uml


License

MIT