Skip to content

Commit

Permalink
initial commit of SunSpec protocol support
Browse files Browse the repository at this point in the history
README, struct generator, SunSpec model files, etc.
  • Loading branch information
activeshadow committed Jun 14, 2024
1 parent 5787355 commit 5c5359b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"GOLANG_VERSION": "1.21.1"
"GOLANG_VERSION": "1.22.4"
}
},

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "src/c++/deps/opendnp3"]
path = src/c++/deps/opendnp3
url = https://github.com/dnp3/opendnp3.git
[submodule "src/go/sunspec/models"]
path = src/go/sunspec/models
url = https://github.com/sunspec/models.git
1 change: 1 addition & 0 deletions src/go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sunspec/types.go
50 changes: 46 additions & 4 deletions src/go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,45 @@ prefix := /usr/local
# DATE := $(shell date -u)
# VERSION := $(VER) (commit $(COMMIT)) $(DATE)

MSGBUS_SOURCES := $(shell find msgbus \( -name '*.go' \))
THISFILE := $(lastword $(MAKEFILE_LIST))
THISDIR := $(shell dirname $(realpath $(THISFILE)))
GOBIN := $(THISDIR)/bin

# Prepend this repo's bin directory to our path since we'll want to
# install some build tools there for use during the build process.
PATH := $(GOBIN):$(PATH)

# Export GOBIN env variable so `go install` picks it up correctly.
export GOBIN

.PHONY: install-build-deps
install-build-deps: bin/go-jsonschema bin/xsdgen

.PHONY: remove-build-deps
remove-build-deps:
$(RM) bin/go-json-schema

bin/go-jsonschema:
go install github.com/atombender/go-jsonschema@latest

all: bin/ot-sim-cpu-module bin/ot-sim-logic-module bin/ot-sim-modbus-module \
bin/ot-sim-mqtt-module bin/ot-sim-node-red-module bin/ot-sim-sunspec-module \
bin/ot-sim-tailscale-module bin/ot-sim-telnet-module

clean:
$(RM) bin/*
$(RM) bin/ot-sim-cpu-module
$(RM) bin/ot-sim-logic-module
$(RM) bin/ot-sim-modbus-module
$(RM) bin/ot-sim-mqtt-module
$(RM) bin/ot-sim-node-red-module
$(RM) bin/ot-sim-sunspec-module
$(RM) bin/ot-sim-tailscale-module
$(RM) bin/ot-sim-telnet-module

sunspec/types.go: sunspec/models/json/schema.json bin/go-jsonschema
$(GOBIN)/go-jsonschema -p sunspec -o sunspec/types.go sunspec/models/json/schema.json

all: bin/ot-sim-cpu-module bin/ot-sim-logic-module bin/ot-sim-modbus-module bin/ot-sim-mqtt-module bin/ot-sim-node-red-module bin/ot-sim-tailscale-module bin/ot-sim-telnet-module
MSGBUS_SOURCES := $(shell find msgbus \( -name '*.go' \))

CPU_SOURCES := $(shell find cpu \( -name '*.go' \))

Expand Down Expand Up @@ -46,6 +79,12 @@ bin/ot-sim-node-red-module: $(NODERED_SOURCES)
mkdir -p bin
GOOS=linux go build -a -ldflags="-s -w" -trimpath -o bin/ot-sim-node-red-module cmd/ot-sim-node-red-module/main.go

SUNSPEC_SOURCES := $(shell find sunspec \( -name '*.go' \))

bin/ot-sim-sunspec-module: $(SUNSPEC_SOURCES) sunspec/types.go
mkdir -p bin
GOOS=linux go build -a -ldflags="-s -w" -trimpath -o bin/ot-sim-sunspec-module cmd/ot-sim-sunspec-module/main.go

TAILSCALE_SOURCES := $(shell find tailscale \( -name '*.go' \))

bin/ot-sim-tailscale-module: $(TAILSCALE_SOURCES) $(MSGBUS_SOURCES)
Expand All @@ -59,11 +98,14 @@ bin/ot-sim-telnet-module: $(TELNET_SOURCES) $(MSGBUS_SOURCES)
GOOS=linux go build -a -ldflags="-s -w" -trimpath -o bin/ot-sim-telnet-module cmd/ot-sim-telnet-module/main.go

.PHONY: install
install: bin/ot-sim-cpu-module bin/ot-sim-logic-module bin/ot-sim-modbus-module bin/ot-sim-mqtt-module bin/ot-sim-node-red-module bin/ot-sim-tailscale-module bin/ot-sim-telnet-module
install: bin/ot-sim-cpu-module bin/ot-sim-logic-module bin/ot-sim-modbus-module \
bin/ot-sim-mqtt-module bin/ot-sim-node-red-module bin/ot-sim-sunspec-module \
bin/ot-sim-tailscale-module bin/ot-sim-telnet-module
cp bin/ot-sim-cpu-module $(prefix)/bin/ot-sim-cpu-module
cp bin/ot-sim-logic-module $(prefix)/bin/ot-sim-logic-module
cp bin/ot-sim-modbus-module $(prefix)/bin/ot-sim-modbus-module
cp bin/ot-sim-mqtt-module $(prefix)/bin/ot-sim-mqtt-module
cp bin/ot-sim-node-red-module $(prefix)/bin/ot-sim-node-red-module
cp bin/ot-sim-sunspec-module $(prefix)/bin/ot-sim-sunspec-module
cp bin/ot-sim-tailscale-module $(prefix)/bin/ot-sim-tailscale-module
cp bin/ot-sim-telnet-module $(prefix)/bin/ot-sim-telnet-module
2 changes: 1 addition & 1 deletion src/go/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/patsec/ot-sim

go 1.21
go 1.22

require (
actshad.dev/mbserver v0.3.1
Expand Down
28 changes: 28 additions & 0 deletions src/go/sunspec/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# OT-sim SunSpec Module

Specify list of model IDs to include in SunSpec device.

Use existing Modbus server and client implementations with support for different
holding register data types.

* will need to add support for string types that are used by SunSpec

Client requests should be for groups of holding registers that map to entire
SunSpec model point groups. On the server side, this means parsing through the
point IDs and grabbing configured static values or values from OT-sim tags to
stuff into the response.

What will be different between client and server config options?

* hopefully nothing?

How do we go about mapping certain SunSpec model points (correct term?) to
OT-sim tags?

* map point IDs to OT-sim tag or static value?
* have default static values for point IDs that can be overwritten?

How do we want to specify point scalings?

* map scaling values to SF values?
* have deault scaling values for SF's that can be overwritten?
1 change: 1 addition & 0 deletions src/go/sunspec/models
Submodule models added at a11843

0 comments on commit 5c5359b

Please sign in to comment.