Skip to content

Commit

Permalink
log hex octet lists for addresses for fixed column width
Browse files Browse the repository at this point in the history
  • Loading branch information
pascaldekloe committed Jul 17, 2024
1 parent 0312218 commit 72a2a89
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,132 +102,132 @@ func NewMonitor[COT info.Cause, Common info.ComAddr, Object info.Addr]() Monitor
func NewLog[COT info.Cause, Common info.ComAddr, Object info.Addr](w io.Writer) Monitor[COT, Common, Object] {
return Monitor[COT, Common, Object]{
SinglePt: func(u info.DataUnit[COT, Common, Object], addr Object, p info.SinglePtQual) {
fmt.Fprintf(w, "%s %s %d/%d: %s %s\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual())
fmt.Fprintf(w, "%s %s %#x/%#x %s %s\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual())
},
SinglePtWithTime: func(u info.DataUnit[COT, Common, Object], addr Object, p info.SinglePtQual, t CP24Time2a) {
min, secInMilli := t.MinuteAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %s %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %s %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual(),
min, secInMilli/1000, secInMilli%1000)
},
SinglePtWithDate: func(u info.DataUnit[COT, Common, Object], addr Object, p info.SinglePtQual, t CP56Time2a) {
y, m, d := t.Calendar()
H, M, secInMilli := t.ClockAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %s %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %s %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual(),
y, m, d, H, M, secInMilli/1000, secInMilli%1000)
},

DoublePt: func(u info.DataUnit[COT, Common, Object], addr Object, p info.DoublePtQual) {
fmt.Fprintf(w, "%s %s %d/%d: %s %s\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual())
fmt.Fprintf(w, "%s %s %#x/%#x %s %s\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual())
},
DoublePtWithTime: func(u info.DataUnit[COT, Common, Object], addr Object, p info.DoublePtQual, t CP24Time2a) {
min, secInMilli := t.MinuteAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %s %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %s %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual(),
min, secInMilli/1000, secInMilli%1000)
},
DoublePtWithDate: func(u info.DataUnit[COT, Common, Object], addr Object, p info.DoublePtQual, t CP56Time2a) {
y, m, d := t.Calendar()
H, M, secInMilli := t.ClockAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %s %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %s %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual(),
y, m, d, H, M, secInMilli/1000, secInMilli%1000)
},

Step: func(u info.DataUnit[COT, Common, Object], addr Object, p info.StepQual) {
fmt.Fprintf(w, "%s %s %d/%d: %s %s\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual())
fmt.Fprintf(w, "%s %s %#x/%#x %s %s\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual())
},
StepWithTime: func(u info.DataUnit[COT, Common, Object], addr Object, p info.StepQual, t CP24Time2a) {
min, secInMilli := t.MinuteAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %s %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %s %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual(),
min, secInMilli/1000, secInMilli%1000)
},
StepWithDate: func(u info.DataUnit[COT, Common, Object], addr Object, p info.StepQual, t CP56Time2a) {
y, m, d := t.Calendar()
H, M, secInMilli := t.ClockAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %s %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), p.Value(), p.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %s %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, p.Value(), p.Qual(),
y, m, d, H, M, secInMilli/1000, secInMilli%1000)
},

Bits: func(u info.DataUnit[COT, Common, Object], addr Object, b info.BitsQual) {
fmt.Fprintf(w, "%s %s %d/%d: %#x %s\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), b.Array(), b.Qual())
fmt.Fprintf(w, "%s %s %#x/%#x %#x %s\n",
u.Type, u.Cause, u.Addr, addr, b.Array(), b.Qual())
},
BitsWithTime: func(u info.DataUnit[COT, Common, Object], addr Object, b info.BitsQual, t CP24Time2a) {
min, secInMilli := t.MinuteAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %#x %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), b.Array(), b.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %#x %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, b.Array(), b.Qual(),
min, secInMilli/1000, secInMilli%1000)
},
BitsWithDate: func(u info.DataUnit[COT, Common, Object], addr Object, b info.BitsQual, t CP56Time2a) {
y, m, d := t.Calendar()
H, M, secInMilli := t.ClockAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %#x %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), b.Array(), b.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %#x %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, b.Array(), b.Qual(),
y, m, d, H, M, secInMilli/1000, secInMilli%1000)
},

NormUnqual: func(u info.DataUnit[COT, Common, Object], addr Object, n info.Norm) {
fmt.Fprintf(w, "%s %s %d/%d: %f\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), n.Float64())
fmt.Fprintf(w, "%s %s %#x/%#x %f\n",
u.Type, u.Cause, u.Addr, addr, n.Float64())
},
Norm: func(u info.DataUnit[COT, Common, Object], addr Object, n info.NormQual) {
fmt.Fprintf(w, "%s %s %d/%d: %f %s\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), n.Link().Float64(), n.Qual())
fmt.Fprintf(w, "%s %s %#x/%#x %f %s\n",
u.Type, u.Cause, u.Addr, addr, n.Link().Float64(), n.Qual())
},
NormWithTime: func(u info.DataUnit[COT, Common, Object], addr Object, n info.NormQual, t CP24Time2a) {
min, secInMilli := t.MinuteAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %f %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), n.Link().Float64(), n.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %f %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, n.Link().Float64(), n.Qual(),
min, secInMilli/1000, secInMilli%1000)
},
NormWithDate: func(u info.DataUnit[COT, Common, Object], addr Object, n info.NormQual, t CP56Time2a) {
y, m, d := t.Calendar()
H, M, secInMilli := t.ClockAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %f %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), n.Link().Float64(), n.Qual(),
fmt.Fprintf(w, "%s %s %#x/%#x %f %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, n.Link().Float64(), n.Qual(),
y, m, d, H, M, secInMilli/1000, secInMilli%1000)
},

Scaled: func(u info.DataUnit[COT, Common, Object], addr Object, v int16, q info.Qual) {
fmt.Fprintf(w, "%s %s %d/%d: %d %s\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), v, q)
fmt.Fprintf(w, "%s %s %#x/%#x %d %s\n",
u.Type, u.Cause, u.Addr, addr, v, q)
},
ScaledWithTime: func(u info.DataUnit[COT, Common, Object], addr Object, v int16, q info.Qual, t CP24Time2a) {
min, secInMilli := t.MinuteAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %d %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), v, q,
fmt.Fprintf(w, "%s %s %#x/%#x %d %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, v, q,
min, secInMilli/1000, secInMilli%1000)
},
ScaledWithDate: func(u info.DataUnit[COT, Common, Object], addr Object, v int16, q info.Qual, t CP56Time2a) {
y, m, d := t.Calendar()
H, M, secInMilli := t.ClockAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %d %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), v, q,
fmt.Fprintf(w, "%s %s %#x/%#x %d %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, v, q,
y, m, d, H, M, secInMilli/1000, secInMilli%1000)
},

Float: func(u info.DataUnit[COT, Common, Object], addr Object, f float32, q info.Qual) {
fmt.Fprintf(w, "%s %s %d/%d: %g %s\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), f, q)
fmt.Fprintf(w, "%s %s %#x/%#x %g %s\n",
u.Type, u.Cause, u.Addr, addr, f, q)
},
FloatWithTime: func(u info.DataUnit[COT, Common, Object], addr Object, f float32, q info.Qual, t CP24Time2a) {
min, secInMilli := t.MinuteAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %g %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), f, q,
fmt.Fprintf(w, "%s %s %#x/%#x %g %s :%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, f, q,
min, secInMilli/1000, secInMilli%1000)
},
FloatWithDate: func(u info.DataUnit[COT, Common, Object], addr Object, f float32, q info.Qual, t CP56Time2a) {
y, m, d := t.Calendar()
H, M, secInMilli := t.ClockAndMillis()
fmt.Fprintf(w, "%s %s %d/%d: %g %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr.N(), addr.N(), f, q,
fmt.Fprintf(w, "%s %s %#x/%#x %g %s %02d-%02d-%02dT%02d:%02d:%02d.%03d\n",
u.Type, u.Cause, u.Addr, addr, f, q,
y, m, d, H, M, secInMilli/1000, secInMilli%1000)
},
}
Expand Down

0 comments on commit 72a2a89

Please sign in to comment.