Skip to content

Commit

Permalink
feat: complete refactor to split router matrix and protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
monoxane committed May 4, 2024
1 parent abd7919 commit e3ef178
Show file tree
Hide file tree
Showing 11 changed files with 452 additions and 345 deletions.
71 changes: 0 additions & 71 deletions model.go

This file was deleted.

240 changes: 0 additions & 240 deletions nk.go

This file was deleted.

7 changes: 7 additions & 0 deletions pkg/levels/levels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package levels

type Level = int

const (
MD_Vid uint32 = 1
)
48 changes: 47 additions & 1 deletion matrix.go → pkg/matrix/matrix.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
package nk
package matrix

import (
"encoding/json"
"fmt"
"sort"
"sync"
)

type Destination struct {
Label string `json:"label"`
Id uint16 `json:"id"`
Source *Source `json:"source"`
}

type Source struct {
Label string `json:"label"`
Id uint16 `json:"id"`
}

type Matrix struct {
destinations map[uint16]*Destination
sources map[uint16]*Source
mux sync.Mutex
}

func (matrix *Matrix) Init(numDestinations, numSources uint16) {
matrix.destinations = make(map[uint16]*Destination)
matrix.sources = make(map[uint16]*Source)

for i := 0; i < int(numSources)+1; i++ {
matrix.sources[uint16(i)] = &Source{
Id: uint16(i),
Label: fmt.Sprintf("IN %d", i),
}
}

matrix.sources[0].SetLabel("DISCONNECTED")

for i := 0; i < int(numDestinations)+1; i++ {
matrix.destinations[uint16(i)] = &Destination{
Id: uint16(i),
Label: fmt.Sprintf("OUT %d", i),
}
}
}

func (matrix *Matrix) MarshalJSON() ([]byte, error) {
type res struct {
Destinations []*Destination `json:"destinations,omitempty"`
Expand Down Expand Up @@ -89,3 +129,9 @@ func (src *Source) GetLabel() string {
func (src *Source) SetLabel(lbl string) {
src.Label = lbl
}

func (matrix *Matrix) ForEachDestination(callback func(uint16, *Destination)) {
for i, d := range matrix.destinations {
callback(i, d)
}
}
13 changes: 13 additions & 0 deletions pkg/models/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package models

type Model = string

const (
NK_3G72 Model = "NK-3G72"
NK_3G64 Model = "NK-3G64"
NK_3G34 Model = "NK-3G34"
NK_3G16 Model = "NK-3G16"
NK_3G16_RCP Model = "NK-3G16-RCP"
NK_3G164 Model = "NK-3G164"
NK_3G164_RCP Model = "NK-3G164-RCP"
)
Loading

0 comments on commit e3ef178

Please sign in to comment.