-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,867 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ | |
|
||
!/cmd/geottnd/geottnd | ||
!/cmd/ttncli/ttncli | ||
!/cmd/geottnd/geottnd | ||
!/cmd/geottnd/geo.db/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.EXPORT_ALL_VARIABLES: | ||
|
||
ifndef VERSION | ||
VERSION := $(shell git describe --always --tags) | ||
endif | ||
|
||
DATE := $(shell date -u +%Y%m%d.%H%M%S) | ||
|
||
LDFLAGS = -trimpath -ldflags "-X=main.version=$(VERSION)-$(DATE)" | ||
CGO_ENABLED=0 | ||
|
||
targets = geottnd | ||
|
||
.PHONY: all lint test geottnd clean | ||
|
||
all: test $(targets) | ||
|
||
test: CGO_ENABLED=1 | ||
test: lint | ||
go test -race ./... | ||
|
||
lint: | ||
golangci-lint run | ||
|
||
geottnd: | ||
cd cmd/geottnd && go build $(LDFLAGS) | ||
|
||
clean: | ||
rm -f cmd/geottnd/geottnd | ||
|
||
generate: | ||
go generate ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/hex" | ||
"flag" | ||
"fmt" | ||
|
||
"github.com/akhenakh/cayenne" | ||
) | ||
|
||
var ( | ||
lat = flag.Float64("lat", 48.8, "The Latitude") | ||
lng = flag.Float64("lng", 2.2, "The Longitude") | ||
channel = flag.Int("channel", 1, "The channel") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
e := cayenne.NewEncoder() | ||
e.AddGPS(uint8(*channel), float32(*lat), float32(*lng), 0.0) | ||
|
||
b := e.Bytes() | ||
hexPayload := hex.EncodeToString(b) | ||
fmt.Println("Data", hexPayload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"flag" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"github.com/akhenakh/cayenne" | ||
_ "github.com/mbobakov/grpc-consul-resolver" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/balancer/roundrobin" | ||
|
||
"github.com/akhenakh/geottn/geottnsvc" | ||
) | ||
|
||
var ( | ||
geoTTNURI = flag.String("geoTTNURI", "localhost:9200", "geoTTN grpc URI") | ||
lat = flag.Float64("lat", 48.8, "Lat") | ||
lng = flag.Float64("lng", 2.2, "Lng") | ||
radius = flag.Float64("radius", 1000, "Radius in meters") | ||
key = flag.String("key", "", "ask for a key, if empty perform radius search") | ||
topic = flag.String("topic", "metar", "topic") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
conn, err := grpc.Dial(*geoTTNURI, | ||
grpc.WithInsecure(), | ||
grpc.WithBalancerName(roundrobin.Name), //nolint:staticcheck | ||
) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
c := geottnsvc.NewGeoTTNClient(conn) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) | ||
defer cancel() | ||
|
||
if *key != "" { | ||
dp, err := c.Get(ctx, &geottnsvc.GetRequest{ | ||
Key: *key, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
dec := cayenne.NewDecoder(bytes.NewBuffer(dp.Payload)) | ||
msg, err := dec.DecodeUplink() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
response := make(map[string]interface{}) | ||
for k, v := range msg.Values() { | ||
response[k] = v | ||
} | ||
response["latitude"] = dp.Latitude | ||
response["longitude"] = dp.Longitude | ||
response["device_id"] = dp.DeviceId | ||
response["time"] = dp.Time | ||
|
||
log.Println(response) | ||
|
||
os.Exit(0) | ||
} | ||
rep, err := c.RadiusSearch(ctx, &geottnsvc.RadiusSearchRequest{ | ||
Lat: *lat, | ||
Lng: *lng, | ||
Radius: *radius, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
log.Println("query ok", len(rep.Points)) | ||
|
||
for _, dp := range rep.Points { | ||
dec := cayenne.NewDecoder(bytes.NewBuffer(dp.Payload)) | ||
msg, err := dec.DecodeUplink() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
response := make(map[string]interface{}) | ||
for k, v := range msg.Values() { | ||
response[k] = v | ||
} | ||
response["device_id"] = dp.DeviceId | ||
response["time"] = dp.Time | ||
|
||
log.Println(response) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//go:generate protoc --proto_path=..:. -I .. --go_out=plugins=grpc:. geottnsvc.proto | ||
|
||
package geottnsvc |
Oops, something went wrong.