mirror of https://git.sr.ht/~michalr/go-satel
Compare commits
3 Commits
c93d9db530
...
053187c5d1
Author | SHA1 | Date |
---|---|---|
Michał Rudowicz | 053187c5d1 | |
Michał Rudowicz | 6b3159eed0 | |
Michał Rudowicz | 75f849a7b1 |
|
@ -5,6 +5,13 @@ tasks:
|
||||||
- go-get: |
|
- go-get: |
|
||||||
cd go-satel
|
cd go-satel
|
||||||
go get -t
|
go get -t
|
||||||
|
- precommit: |
|
||||||
|
cd go-satel
|
||||||
|
python3 -m venv .venv
|
||||||
|
source .venv/bin/activate
|
||||||
|
pip3 install pre-commit
|
||||||
|
pre-commit install
|
||||||
|
pre-commit run -a
|
||||||
- test: |
|
- test: |
|
||||||
cd go-satel
|
cd go-satel
|
||||||
go test
|
go test
|
|
@ -0,0 +1,16 @@
|
||||||
|
# See https://pre-commit.com for more information
|
||||||
|
# See https://pre-commit.com/hooks.html for more hooks
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
|
rev: v3.2.0
|
||||||
|
hooks:
|
||||||
|
- id: trailing-whitespace
|
||||||
|
- id: end-of-file-fixer
|
||||||
|
- id: check-added-large-files
|
||||||
|
- repo: https://github.com/TekWizely/pre-commit-golang
|
||||||
|
rev: v0.8.3
|
||||||
|
hooks:
|
||||||
|
- id: go-fmt
|
||||||
|
args: [ -w, -s ]
|
||||||
|
- id: go-vet-mod
|
||||||
|
- id: go-test-repo-mod
|
31
README.md
31
README.md
|
@ -4,14 +4,15 @@ go-satel is a Go library to integrate
|
||||||
with [Satel ETHM-1/ETHM-1 Plus](https://www.satel.pl/produkty/sswin/komunikacja-i-powiadamianie/komunikacja-tcp-ip/ethm-1-plus/)
|
with [Satel ETHM-1/ETHM-1 Plus](https://www.satel.pl/produkty/sswin/komunikacja-i-powiadamianie/komunikacja-tcp-ip/ethm-1-plus/)
|
||||||
module
|
module
|
||||||
|
|
||||||
[![Build](https://github.com/probakowski/go-satel/actions/workflows/build.yml/badge.svg)](https://github.com/probakowski/go-satel/actions/workflows/build.yml)
|
[![builds.sr.ht status](https://builds.sr.ht/~michalr/go-satel.svg)](https://builds.sr.ht/~michalr/go-satel?) [![Go Report Card](https://goreportcard.com/badge/git.sr.ht/~michalr/go-satel)](https://goreportcard.com/report/git.sr.ht/~michalr/go-satel)
|
||||||
[![Go Report Card](https://goreportcard.com/badge/github.com/probakowski/go-satel)](https://goreportcard.com/report/github.com/probakowski/go-satel)
|
|
||||||
|
The library is based on https://github.com/probakowski/go-satel .
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
go-satel is compatible with modern Go releases in module mode, with Go installed:
|
go-satel is compatible with modern Go releases in module mode, with Go installed:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
go get github.com/probakowski/go-satel
|
go get git.sr.ht/~michalr/go-satel
|
||||||
```
|
```
|
||||||
|
|
||||||
will resolve and add the package to the current development module, along with its dependencies.
|
will resolve and add the package to the current development module, along with its dependencies.
|
||||||
|
@ -19,29 +20,11 @@ will resolve and add the package to the current development module, along with i
|
||||||
Alternatively the same can be achieved if you use import in a package:
|
Alternatively the same can be achieved if you use import in a package:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
import "github.com/probakowski/go-satel"
|
import "git.sr.ht/~michalr/go-satel"
|
||||||
```
|
```
|
||||||
|
|
||||||
and run `go get` without parameters.
|
and run `go get` without parameters.
|
||||||
|
|
||||||
Finally, to use the top-of-trunk version of this repo, use the following command:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
go get github.com/probakowski/go-satel@master
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
```go
|
|
||||||
s := satel.NewConfig("<ip:port>", satel.Config{EventsQueueSize: 1000})
|
**TODO**
|
||||||
go func() {
|
|
||||||
value := true
|
|
||||||
for {
|
|
||||||
s.SetOutput("<user code>", <port number>, value)
|
|
||||||
time.Sleep(5 * time.Second)
|
|
||||||
value = !value
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
for e, ok := <-s.Events; ok; e, ok = <-s.Events {
|
|
||||||
logger.Print("change from satel", "type", e.Type, "index", e.Index, "value", e.Value)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
12
satel.go
12
satel.go
|
@ -8,12 +8,16 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type BasicEventElement struct {
|
||||||
Type ChangeType
|
Type ChangeType
|
||||||
Index int
|
Index int
|
||||||
Value bool
|
Value bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Event struct {
|
||||||
|
BasicEvents []BasicEventElement
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
EventsQueueSize int
|
EventsQueueSize int
|
||||||
LongCommands bool
|
LongCommands bool
|
||||||
|
@ -125,16 +129,18 @@ func (s *Satel) readRawEvents() {
|
||||||
if cmd == 0xEF {
|
if cmd == 0xEF {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
basicElements := make([]BasicEventElement, 0)
|
||||||
for i, bb := range bytes {
|
for i, bb := range bytes {
|
||||||
for j := 0; j < 8; j++ {
|
for j := 0; j < 8; j++ {
|
||||||
index := byte(1 << j)
|
index := byte(1 << j)
|
||||||
s.Events <- Event{
|
basicElements = append(basicElements, BasicEventElement{
|
||||||
Type: ChangeType(cmd),
|
Type: ChangeType(cmd),
|
||||||
Index: i*8 + j,
|
Index: i*8 + j,
|
||||||
Value: bb&index != 0,
|
Value: bb&index != 0,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
s.Events <- Event{basicElements}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Satel) read() {
|
func (s *Satel) read() {
|
||||||
|
|
Loading…
Reference in New Issue