Skip to content
Draft
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
6 changes: 3 additions & 3 deletions cmd/optic-programmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func main() {
log.Printf("Tuning Status: %b", resultPage12.Status)
log.Printf("Grid Spacing: %v", resultPage12.GridDisplay)
log.Printf("Frequency Offset: %v", resultPage12.FrequencyOffset)
log.Printf("Frequency: %v THz", float32(resultPage12.Frequency)/100.0)
log.Printf("Frequency: %v THz", float64(resultPage12.Frequency)*1e-12)
if resultPage12.Channel != nil {
log.Printf("Channel: %v", *resultPage12.Channel)
} else {
Expand Down Expand Up @@ -135,7 +135,7 @@ func main() {
router := cmd.StringArg("device")
iface := cmd.StringArg("interface")

gridSpacing := cmd.Int("grid-spacing")
gridSpacing := cmd.Float64("grid-spacing")
channel := cmd.Int("channel")

routerConnection, err := connection.New(user, router)
Expand Down Expand Up @@ -225,7 +225,7 @@ func main() {
log.Printf("Flex Tune is already disabled...")
}

needsGridProgramming := resultPage12.GridDisplay != strconv.Itoa(gridSpacing)
needsGridProgramming := resultPage12.GridDisplay != strconv.FormatFloat(gridSpacing, 'f', 3, 64)
needsChannelProgramming := resultPage12.Channel == nil || *resultPage12.Channel != channel

if needsGridProgramming {
Expand Down
223 changes: 76 additions & 147 deletions internal/pkg/rtbrick/dwdm.go
Original file line number Diff line number Diff line change
@@ -1,153 +1,82 @@
package rtbrick

// This is taken from https://www.opternus.de/wissen/netzwerkprotokoll-messtechnik/dwdm-grid-saemtliche-dwdm-kanaele-mit-ihren-absoluten-werten-nach-frequenz-und-wellenlaenge
// We multiply the float values by 100 to get rid of floating point errors.

// DWDMGridMap Hz unit
var DWDMGridMap = map[int]int{

1: 19010,

38: 19380,

2: 19020,

39: 19390,

3: 19030,

40: 19400,

4: 19040,

41: 19410,

5: 19050,

42: 19420,

6: 19060,

43: 19430,

7: 19070,

44: 19440,

8: 19080,

45: 19450,

9: 19090,

46: 19460,

10: 19100,

47: 19470,

11: 19110,

48: 19480,

12: 19120,

49: 19490,

13: 19130,

50: 19500,

14: 19140,

51: 19510,

15: 19150,

52: 19520,

16: 19160,

53: 19530,

17: 19170,

54: 19540,

18: 19180,

55: 19550,

19: 19190,

56: 19560,

20: 19200,

57: 19570,

21: 19210,

58: 19580,

22: 19220,

59: 19590,

23: 19230,

60: 19600,

24: 19240,

61: 19610,

25: 19250,

62: 19620,

26: 19260,

63: 19630,

27: 19270,

64: 19640,

28: 19280,

65: 19650,

29: 19290,

66: 19660,

30: 19300,

67: 19670,

31: 19310,

68: 19680,

32: 19320,

69: 19690,

33: 19330,

70: 19700,

34: 19340,

71: 19710,

35: 19350,

72: 19720,

36: 19360,

73: 19730,

37: 19370,
1: 190.10e12,
38: 193.80e12,
2: 190.20e12,
39: 193.90e12,
3: 190.30e12,
40: 194.00e12,
4: 190.40e12,
41: 194.10e12,
5: 190.50e12,
42: 194.20e12,
6: 190.60e12,
43: 194.30e12,
7: 190.70e12,
44: 194.40e12,
8: 190.80e12,
45: 194.50e12,
9: 190.90e12,
46: 194.60e12,
10: 191.00e12,
47: 194.70e12,
11: 191.10e12,
48: 194.80e12,
12: 191.20e12,
49: 194.90e12,
13: 191.30e12,
50: 195.00e12,
14: 191.40e12,
51: 195.10e12,
15: 191.50e12,
52: 195.20e12,
16: 191.60e12,
53: 195.30e12,
17: 191.70e12,
54: 195.40e12,
18: 191.80e12,
55: 195.50e12,
19: 191.90e12,
56: 195.60e12,
20: 192.00e12,
57: 195.70e12,
21: 192.10e12,
58: 195.80e12,
22: 192.20e12,
59: 195.90e12,
23: 192.30e12,
60: 196.00e12,
24: 192.40e12,
61: 196.10e12,
25: 192.50e12,
62: 196.20e12,
26: 192.60e12,
63: 196.30e12,
27: 192.70e12,
64: 196.40e12,
28: 192.80e12,
65: 196.50e12,
29: 192.90e12,
66: 196.60e12,
30: 193.00e12,
67: 196.70e12,
31: 193.10e12,
68: 196.80e12,
32: 193.20e12,
69: 196.90e12,
33: 193.30e12,
70: 197.00e12,
34: 193.40e12,
71: 197.10e12,
35: 193.50e12,
72: 197.20e12,
36: 193.60e12,
73: 197.30e12,
37: 193.70e12,
}

const DWDMCenterFreqHz = 193.1e12
92 changes: 73 additions & 19 deletions internal/pkg/rtbrick/i2c.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,77 @@ func ParseASCIIToString(part []byte) string {
type I2CPage12Grid int

const (
I2CPage12Grid50Ghz = iota
I2CPage12Grid100Ghz
I2CPage12Grid3p125 = iota
I2CPage12Grid6p25
I2CPage12Grid12p5
I2CPage12Grid25
I2CPage12Grid50
I2CPage12Grid100
I2CPage12Grid33
I2CPage12Grid75
I2CPage12GridRESERVED
I2CPage12GridUNAVAILABLE
)

var I2CPage12GridMap = map[I2CPage12Grid]byte{
I2CPage12Grid50Ghz: 0x40,
I2CPage12Grid100Ghz: 0x50,
type DefaultMap[K comparable, V comparable] struct {
m map[K]V
d V
}

func (m DefaultMap[K, V]) get(key K) V {
if v, ok := m.m[key]; ok {
return v
}
return m.d
}

func (m DefaultMap[K, V]) getKey(val V) K {
for k, v := range m.m {
if v == val {
return k
}
}
panic("value not found")
}

// I2CPage12GridMap cmis 12h reg 128-135 grid spacing
var I2CPage12GridMap = DefaultMap[byte, I2CPage12Grid]{
m: map[byte]I2CPage12Grid{
0b0000_0000: I2CPage12Grid3p125,
0b0010_0000: I2CPage12Grid12p5,
0b0001_0000: I2CPage12Grid6p25,
0b0011_0000: I2CPage12Grid25,
0b0100_0000: I2CPage12Grid50,
0b0101_0000: I2CPage12Grid100,
0b0110_0000: I2CPage12Grid33,
0b0111_0000: I2CPage12Grid75,
0b1111_0000: I2CPage12GridUNAVAILABLE,
},
d: I2CPage12GridRESERVED,
}

// I2CPage12GridMultiplierMap Hz
var I2CPage12GridMultiplierMap = map[I2CPage12Grid]int{
I2CPage12Grid50Ghz: 5,
I2CPage12Grid100Ghz: 10,
I2CPage12Grid3p125: 3.125e9,
I2CPage12Grid6p25: 6.25e9,
I2CPage12Grid12p5: 12.5e9,
I2CPage12Grid25: 25.0e9,
I2CPage12Grid50: 50.0e9,
I2CPage12Grid100: 100.0e9,
I2CPage12Grid33: 33.0e9,
I2CPage12Grid75: 75.0e9,
}

var I2CPage12GridNameMap = map[I2CPage12Grid]int{
I2CPage12Grid50Ghz: 50,
I2CPage12Grid100Ghz: 100,
// I2CPage12GridNameMap Ghz
var I2CPage12GridNameMap = map[I2CPage12Grid]float64{
I2CPage12Grid3p125: 3.125,
I2CPage12Grid6p25: 6.25,
I2CPage12Grid12p5: 12.5,
I2CPage12Grid25: 25.0,
I2CPage12Grid50: 50.0,
I2CPage12Grid100: 100.0,
I2CPage12Grid33: 33.0,
I2CPage12Grid75: 75.0,
}

type I2CPage12 struct {
Expand All @@ -104,40 +158,40 @@ type I2CPage12 struct {

func InterpretPage12(dump []byte) I2CPage12 {
bitfieldGrid := dump[128]
gridSetting := keysByValue(I2CPage12GridMap, bitfieldGrid)
gridSetting := I2CPage12GridMap.get(bitfieldGrid)

u := binary.BigEndian.Uint16(dump[136:138])
frequencyOffset := int(TwoComplement16(16, u))
gridMultiplier := I2CPage12GridMultiplierMap[*gridSetting]
gridMultiplier := I2CPage12GridMultiplierMap[gridSetting]

opticFrequency := 19310 + (frequencyOffset * gridMultiplier)
opticFrequency := DWDMCenterFreqHz + (frequencyOffset * gridMultiplier)
channelSetting := keysByValue(DWDMGridMap, opticFrequency)

status := dump[231]

return I2CPage12{
Grid: *gridSetting,
GridDisplay: strconv.Itoa(I2CPage12GridNameMap[*gridSetting]),
Grid: gridSetting,
GridDisplay: strconv.FormatFloat(I2CPage12GridNameMap[gridSetting], 'f', 3, 64),
FrequencyOffset: frequencyOffset,
Frequency: opticFrequency,
Channel: channelSetting,
Status: status,
}
}

func GetGridProgramming(gridStr int) (page, byte int, value byte) {
func GetGridProgramming(gridStr float64) (page, byte int, value byte) {
grid := keysByValue(I2CPage12GridNameMap, gridStr)
newValue := I2CPage12GridMap[*grid]
newValue := I2CPage12GridMap.getKey(*grid)
return 0x12, 128, newValue
}

func GetChannelProgramming(gridStr int, newChannel int) (page, byte int, value byte, page2, byte2 int, value2 byte) {
func GetChannelProgramming(gridStr float64, newChannel int) (page, byte int, value byte, page2, byte2 int, value2 byte) {
gridSetting := keysByValue(I2CPage12GridNameMap, gridStr)

targetFrequency := DWDMGridMap[newChannel]
gridMultiplier := I2CPage12GridMultiplierMap[*gridSetting]

targetOffset := (targetFrequency - 19310) / gridMultiplier
targetOffset := (targetFrequency - DWDMCenterFreqHz) / gridMultiplier

sendBytes := ToTwoComplement16(int16(targetOffset))

Expand Down