Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/dist
_release/attiny-firmware.hex
_release/attiny-firmware.hex.sha256

/tc2-hat-controller
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ nfpms:
dst: /usr/bin/tc2-hat-rtc
- src: _release/tc2-hat-temp
dst: /usr/bin/tc2-hat-temp
- src: _release/tc2-hat-trap-cli
dst: /usr/bin/tc2-hat-trap-cli

dependencies:
#- python3-pip
Expand Down
2 changes: 2 additions & 0 deletions _release/tc2-hat-trap-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
exec /usr/bin/tc2-hat-controller trap-cli "$@"
3 changes: 3 additions & 0 deletions cmd/tc2-hat-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
rp2040 "github.com/TheCacophonyProject/tc2-hat-controller/internal/tc2-hat-rp2040"
rtc "github.com/TheCacophonyProject/tc2-hat-controller/internal/tc2-hat-rtc"
temp "github.com/TheCacophonyProject/tc2-hat-controller/internal/tc2-hat-temp"
trapcli "github.com/TheCacophonyProject/tc2-hat-controller/internal/tc2-hat-trap-cli"
)

var (
Expand Down Expand Up @@ -60,6 +61,8 @@ func runMain() error {
err = rtc.Run(args, version)
case "temp":
err = temp.Run(args, version)
case "trap-cli":
err = trapcli.Run(args, version)
default:
err = fmt.Errorf("unknown subcommand: %s", subcommand)
}
Expand Down
10 changes: 0 additions & 10 deletions internal/tc2-hat-comms/bluetooth.go

This file was deleted.

98 changes: 98 additions & 0 deletions internal/tc2-hat-comms/json-out.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Output mode: sends events out over serial in JSON format.

package comms

import (
"encoding/json"
"fmt"
"time"

"github.com/TheCacophonyProject/tc2-hat-controller/serialhelper"
"github.com/TheCacophonyProject/tc2-hat-controller/tracks"
)

type ClassificationData struct {
Species tracks.Species `json:"species"`
Confidence int32 `json:"confidence"`
}

type jsonOut struct {
Type string `json:"type,omitempty"`
Data ClassificationData `json:"data"`
}

func processJSONOut(config *CommsConfig, testClassification *TestClassification, trackingSignals chan event, port *serialhelper.SerialPort) error {
if testClassification != nil {
log.Println("Sending a test classification over UART")

species := tracks.Species{
testClassification.Animal: int32(testClassification.Confidence),
}

classificationData := ClassificationData{
Species: species,
Confidence: int32(testClassification.Confidence),
}

message := jsonOut{
Type: "classification",
Data: classificationData,
}
payload, err := json.Marshal(message)
if err != nil {
return err
}

log.Printf("Sending payload: '%s'", payload)
return port.Write(append(payload, '\r', '\n'))
}

for {
log.Debug("Waiting")
for e := range trackingSignals {
switch v := e.(type) {
case trackingEvent:
fmt.Println("Tracking event:", v.Species)
err := processTrackingEvent(v, port)
if err != nil {
log.Error("Error processing tracking event:", err)
}
default:
log.Debug("Not processing event:", v)
continue
}
}
}
}

func processTrackingEvent(t trackingEvent, port *serialhelper.SerialPort) error {
log.Debugf("Found new track: %+v", t)

species := tracks.Species{}
for k, v := range t.Species {
if v > 0 {
species[k] = v
}
}

message := jsonOut{
Type: "classification",
Data: ClassificationData{
Species: species,
Confidence: t.Confidence,
},
}

payload, err := json.Marshal(message)
if err != nil {
return err
}

log.Printf("Sending payload: '%s'", payload)
start := time.Now()

err = port.Write(append(payload, '\r', '\n'))

log.Printf("Sent payload in %s", time.Since(start))
return err
}
Loading
Loading