replace sor reader library
This commit is contained in:
parent
bbfc690da7
commit
3a8f760d8f
7 changed files with 828 additions and 28 deletions
|
|
@ -2,25 +2,25 @@ package fiber
|
|||
|
||||
import "fmt"
|
||||
|
||||
func FiberTypeName(code int) string {
|
||||
func FiberTypeName(code string) string {
|
||||
switch code {
|
||||
case 652:
|
||||
case "G.652":
|
||||
return "G.652 (Standard Singlemode)"
|
||||
case 653:
|
||||
case "G.653":
|
||||
return "G.653 (Dispersion-Shifted Singlemode)"
|
||||
case 654:
|
||||
case "G.654":
|
||||
return "G.654 (Cut-off Shifted Singlemode)"
|
||||
case 655:
|
||||
case "G.655":
|
||||
return "G.655 (Non-Zero Dispersion-Shifted Singlemode)"
|
||||
case 656:
|
||||
case "G.656":
|
||||
return "G.656 (Wideband Non-Zero Dispersion-Shifted)"
|
||||
case 657:
|
||||
case "G.657":
|
||||
return "G.657 (Bend-Insensitive Singlemode)"
|
||||
case 850:
|
||||
case "G.850":
|
||||
return "Multimode (850nm optimized)"
|
||||
case 1300:
|
||||
case "G.1300":
|
||||
return "Multimode (1300nm optimized)"
|
||||
default:
|
||||
return fmt.Sprintf("Reserved/Other ( %d )", code)
|
||||
return fmt.Sprintf("Reserved/Other ( %s )", code)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
13
go.mod
13
go.mod
|
|
@ -4,12 +4,18 @@ go 1.24.6
|
|||
|
||||
require (
|
||||
fyne.io/fyne/v2 v2.6.3
|
||||
github.com/dBiTech/go-sor v0.0.0-20250818024124-1077d26a0294
|
||||
gonum.org/v1/plot v0.16.0
|
||||
)
|
||||
|
||||
require (
|
||||
codeberg.org/go-fonts/liberation v0.5.0 // indirect
|
||||
codeberg.org/go-latex/latex v0.1.0 // indirect
|
||||
codeberg.org/go-pdf/fpdf v0.10.0 // indirect
|
||||
fyne.io/systray v1.11.0 // indirect
|
||||
git.sr.ht/~sbinet/gg v0.6.0 // indirect
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect
|
||||
github.com/campoy/embedmd v1.0.0 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/fredbi/uri v1.1.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
|
|
@ -22,6 +28,7 @@ require (
|
|||
github.com/go-text/render v0.2.0 // indirect
|
||||
github.com/go-text/typesetting v0.2.1 // indirect
|
||||
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/hack-pad/go-indexeddb v0.3.2 // indirect
|
||||
github.com/hack-pad/safejs v0.1.0 // indirect
|
||||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade // indirect
|
||||
|
|
@ -35,9 +42,9 @@ require (
|
|||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
|
||||
github.com/stretchr/testify v1.10.0 // indirect
|
||||
github.com/yuin/goldmark v1.7.8 // indirect
|
||||
golang.org/x/image v0.24.0 // indirect
|
||||
golang.org/x/image v0.25.0 // indirect
|
||||
golang.org/x/net v0.35.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
golang.org/x/text v0.23.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
|
|||
63
go.sum
63
go.sum
|
|
@ -1,12 +1,31 @@
|
|||
codeberg.org/go-fonts/dejavu v0.4.0 h1:2yn58Vkh4CFK3ipacWUAIE3XVBGNa0y1bc95Bmfx91I=
|
||||
codeberg.org/go-fonts/dejavu v0.4.0/go.mod h1:abni088lmhQJvso2Lsb7azCKzwkfcnttl6tL1UTWKzg=
|
||||
codeberg.org/go-fonts/latin-modern v0.4.0 h1:vkRCc1y3whKA7iL9Ep0fSGVuJfqjix0ica9UflHORO8=
|
||||
codeberg.org/go-fonts/latin-modern v0.4.0/go.mod h1:BF68mZznJ9QHn+hic9ks2DaFl4sR5YhfM6xTYaP9vNw=
|
||||
codeberg.org/go-fonts/liberation v0.5.0 h1:SsKoMO1v1OZmzkG2DY+7ZkCL9U+rrWI09niOLfQ5Bo0=
|
||||
codeberg.org/go-fonts/liberation v0.5.0/go.mod h1:zS/2e1354/mJ4pGzIIaEtm/59VFCFnYC7YV6YdGl5GU=
|
||||
codeberg.org/go-latex/latex v0.1.0 h1:hoGO86rIbWVyjtlDLzCqZPjNykpWQ9YuTZqAzPcfL3c=
|
||||
codeberg.org/go-latex/latex v0.1.0/go.mod h1:LA0q/AyWIYrqVd+A9Upkgsb+IqPcmSTKc9Dny04MHMw=
|
||||
codeberg.org/go-pdf/fpdf v0.10.0 h1:u+w669foDDx5Ds43mpiiayp40Ov6sZalgcPMDBcZRd4=
|
||||
codeberg.org/go-pdf/fpdf v0.10.0/go.mod h1:Y0DGRAdZ0OmnZPvjbMp/1bYxmIPxm0ws4tfoPOc4LjU=
|
||||
fyne.io/fyne/v2 v2.6.3 h1:cvtM2KHeRuH+WhtHiA63z5wJVBkQ9+Ay0UMl9PxFHyA=
|
||||
fyne.io/fyne/v2 v2.6.3/go.mod h1:NGSurpRElVoI1G3h+ab2df3O5KLGh1CGbsMMcX0bPIs=
|
||||
fyne.io/systray v1.11.0 h1:D9HISlxSkx+jHSniMBR6fCFOUjk1x/OOOJLa9lJYAKg=
|
||||
fyne.io/systray v1.11.0/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
|
||||
git.sr.ht/~sbinet/cmpimg v0.1.0 h1:E0zPRk2muWuCqSKSVZIWsgtU9pjsw3eKHi8VmQeScxo=
|
||||
git.sr.ht/~sbinet/cmpimg v0.1.0/go.mod h1:FU12psLbF4TfNXkKH2ZZQ29crIqoiqTZmeQ7dkp/pxE=
|
||||
git.sr.ht/~sbinet/gg v0.6.0 h1:RIzgkizAk+9r7uPzf/VfbJHBMKUr0F5hRFxTUGMnt38=
|
||||
git.sr.ht/~sbinet/gg v0.6.0/go.mod h1:uucygbfC9wVPQIfrmwM2et0imr8L7KQWywX0xpFMm94=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
|
||||
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b h1:slYM766cy2nI3BwyRiyQj/Ud48djTMtMebDqepE95rw=
|
||||
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b/go.mod h1:1KcenG0jGWcpt8ov532z81sp/kMMUG485J2InIOyADM=
|
||||
github.com/campoy/embedmd v1.0.0 h1:V4kI2qTJJLf4J29RzI/MAt2c3Bl4dQSYPuflzwFH2hY=
|
||||
github.com/campoy/embedmd v1.0.0/go.mod h1:oxyr9RCiSXg0M3VJ3ks0UGfp98BpSSGr0kpiX3MzVl8=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/dBiTech/go-sor v0.0.0-20250818024124-1077d26a0294 h1:q/3h0qlus1n/5ItP81RDYOboHBstX2HW2nrJAINcBok=
|
||||
github.com/dBiTech/go-sor v0.0.0-20250818024124-1077d26a0294/go.mod h1:NsIXF7nGpa6FFQEIh8Bkr5pKnc/EF732PGSlU2qDSwI=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g=
|
||||
|
|
@ -35,6 +54,8 @@ github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC
|
|||
github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o=
|
||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y=
|
||||
github.com/google/pprof v0.0.0-20211214055906-6f57359322fd/go.mod h1:KgnwoLYCZ8IQu3XUZ8Nc/bM9CCZFOyjUNOSygVozoDg=
|
||||
github.com/hack-pad/go-indexeddb v0.3.2 h1:DTqeJJYc1usa45Q5r52t01KhvlSN02+Oq+tQbSBI91A=
|
||||
|
|
@ -45,6 +66,7 @@ github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade h1:FmusiCI1wH
|
|||
github.com/jeandeaual/go-locale v0.0.0-20250612000132-0ef82f21eade/go.mod h1:ZDXo8KHryOWSIqnsb/CiDq7hQUYryCgdVnxbj8tDG7o=
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 h1:YLvr1eE6cdCqjOe972w/cYF+FjW34v27+9Vo5106B4M=
|
||||
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25/go.mod h1:kLgvv7o6UM+0QSf0QjAse3wReFDsb9qbZJdfexWlrQw=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
|
|
@ -65,18 +87,47 @@ github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqd
|
|||
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
|
||||
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
|
||||
golang.org/x/image v0.24.0 h1:AN7zRgVsbvmTfNyqIbbOraYL8mSwcKncEj8ofjgzcMQ=
|
||||
golang.org/x/image v0.24.0/go.mod h1:4b/ITuLfqYq1hqZcjofwctIhi7sZh2WaCjvsBNjjya8=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
|
||||
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
|
||||
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk=
|
||||
gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E=
|
||||
gonum.org/v1/plot v0.16.0 h1:dK28Qx/Ky4VmPUN/2zeW0ELyM6ucDnBAj5yun7M9n1g=
|
||||
gonum.org/v1/plot v0.16.0/go.mod h1:Xz6U1yDMi6Ni6aaXILqmVIb6Vro8E+K7Q/GeeH+Pn0c=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
|
||||
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
|
|
|
|||
571
gotdr/gotdr.go
Normal file
571
gotdr/gotdr.go
Normal file
|
|
@ -0,0 +1,571 @@
|
|||
package gotdr
|
||||
|
||||
/*
|
||||
Author: Naseredin Aramnejad naseredin.aramnejad@gmail.com
|
||||
This script is designed to extract all the possible information from the
|
||||
given sor file.
|
||||
each sor file (Provided by OTDR Equipment) contains multiple data blocks.
|
||||
Formulas and blueprint of this script are inspired by the information provided by:
|
||||
Sidney Li
|
||||
http://morethanfootnotes.blogspot.com/2015/07/
|
||||
*/
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const lightSpeed = 299.79181901 // m/µsec
|
||||
|
||||
func nukeIfErr(err error) {
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func mod(a, b float64) float64 {
|
||||
return a - b*math.Floor(a/b)
|
||||
}
|
||||
|
||||
// Reverse will reverse the hex string in every 2 bytes. Example: 0ABCD123 => 23D1BC0A.
|
||||
func Reverse(s string) string {
|
||||
str := ""
|
||||
for ind := 0; ind < len(s); ind += 2 {
|
||||
str = s[ind:ind+2] + str
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func dB(point int64) float64 {
|
||||
return float64(point*-1000) * math.Pow(10, -6)
|
||||
}
|
||||
|
||||
func ReadSorFile(filename string) OtdrRawData {
|
||||
|
||||
r := OtdrRawData{
|
||||
Filename: filename,
|
||||
}
|
||||
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
nukeIfErr(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Get the file size
|
||||
stat, err := f.Stat()
|
||||
if err != nil {
|
||||
nukeIfErr(err)
|
||||
}
|
||||
|
||||
// Read the entire file at once
|
||||
buffer := make([]byte, stat.Size())
|
||||
_, err = io.ReadFull(f, buffer)
|
||||
if err != nil {
|
||||
nukeIfErr(err)
|
||||
}
|
||||
|
||||
//Converting the byte array into a hex String
|
||||
r.HexData = hex.EncodeToString(buffer)
|
||||
|
||||
//Converting the HexData to a text string
|
||||
chars, err := hex.DecodeString(r.HexData)
|
||||
nukeIfErr(err)
|
||||
|
||||
r.Decodedfile = string(chars)
|
||||
|
||||
r.GetOrder()
|
||||
r.getBellCoreVersion()
|
||||
r.getTotalLoss()
|
||||
r.getSupParams()
|
||||
r.getGenParams()
|
||||
r.getFixedParams()
|
||||
r.getDataPoints()
|
||||
r.getKeyEvents()
|
||||
r.getFiberLength()
|
||||
r.getSetupParams()
|
||||
r.getMiscParams()
|
||||
r.getViewParams()
|
||||
r.getSystemParams()
|
||||
r.getAnalysisParams()
|
||||
r.getAcqParam()
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// parsHexValue calls the Reverse() funcition to reverse the order of the provided HexString and then converts it's value to int64.
|
||||
func parsHexValue(hexData string) int64 {
|
||||
output, err := strconv.ParseInt(Reverse(hexData), 16, 64)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return 0
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
func (d *OtdrRawData) ReturnIndex(loc float64) []float64 {
|
||||
closest := []float64{math.Inf(0), 0}
|
||||
|
||||
for ind, i := range d.DataPoints {
|
||||
if i[0] == loc {
|
||||
return []float64{float64(ind), i[1]}
|
||||
}
|
||||
|
||||
if math.Abs(loc-i[0]) < math.Abs(loc-closest[0]) && i[0] < loc {
|
||||
closest = []float64{float64(ind), i[1]}
|
||||
} else if i[0] > loc {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return []float64{closest[0], closest[1]}
|
||||
}
|
||||
|
||||
func (d *OtdrRawData) mapKeyEvents(events string) map[int][2]int {
|
||||
m := make(map[int][2]int)
|
||||
start := 4
|
||||
evnumbers := int(parsHexValue(events[:start]))
|
||||
|
||||
for i := 1; i <= evnumbers; i++ {
|
||||
if i == evnumbers {
|
||||
m[i] = [2]int{start, len(events) - 46}
|
||||
} else {
|
||||
end := strings.Index(events[start+84:], fmt.Sprintf("%02x00", i+1))
|
||||
if end == -1 {
|
||||
fmt.Println("pattern not found:", events)
|
||||
return nil
|
||||
}
|
||||
end += start + 84
|
||||
m[i] = [2]int{start, end}
|
||||
start = end
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (d *OtdrRawData) GetNext(key string) string {
|
||||
if _, exists := d.SecLocs[key]; !exists {
|
||||
log.Println(key, "not found")
|
||||
return ""
|
||||
}
|
||||
|
||||
index := d.SecLocs[key][1]
|
||||
var nextKey string
|
||||
nextIndex := math.Inf(1)
|
||||
|
||||
for k, v := range d.SecLocs {
|
||||
if k == key || len(v) < 2 {
|
||||
continue
|
||||
}
|
||||
if float64(index) < float64(v[1]) && float64(v[1]) < nextIndex {
|
||||
nextIndex = float64(v[1])
|
||||
nextKey = k
|
||||
}
|
||||
}
|
||||
|
||||
return nextKey
|
||||
}
|
||||
|
||||
func (d *OtdrRawData) GetOrder() {
|
||||
sections := []string{
|
||||
"SupParams",
|
||||
"ExfoNewProprietaryBlock",
|
||||
"Map",
|
||||
"FxdParams",
|
||||
"YokogawaSpecial",
|
||||
"SetupParams",
|
||||
"DataPts",
|
||||
"NokiaParams",
|
||||
"KeyEvents",
|
||||
"GenParams",
|
||||
"WaveMTSParams",
|
||||
"WavetekTwoMTS",
|
||||
"WavetekThreeMTS",
|
||||
"BlocOtdrPrivate",
|
||||
"ActernaConfig",
|
||||
"ActernaMiniCurve",
|
||||
"AcqParam",
|
||||
"ViewParams",
|
||||
"SystemParams",
|
||||
"AnalysisParams",
|
||||
"MiscParams",
|
||||
"JDSUEvenementsMTS",
|
||||
"Cksum",
|
||||
}
|
||||
|
||||
sectionLocations := make(map[string][]int)
|
||||
|
||||
for _, word := range sections {
|
||||
re := regexp.MustCompile(regexp.QuoteMeta(word))
|
||||
matches := re.FindAllStringIndex(d.Decodedfile, -1)
|
||||
locations := make([]int, len(matches))
|
||||
for i, match := range matches {
|
||||
locations[i] = match[0]
|
||||
}
|
||||
sectionLocations[word] = locations
|
||||
}
|
||||
|
||||
if len(sectionLocations["Cksum"]) < 2 {
|
||||
fmt.Printf("%s file has no checksum\n", d.Filename)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
d.SecLocs = sectionLocations
|
||||
}
|
||||
|
||||
// Under construction
|
||||
func (d *OtdrRawData) getSetupParams() {
|
||||
// s := SetupParams{}
|
||||
|
||||
if len(d.SecLocs["SetupParams"]) == 0 {
|
||||
// log.Println("SetupParams section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
setupparams := d.HexData[(d.SecLocs["SetupParams"][1]+10)*2 : (d.SecLocs[d.GetNext("SetupParams")][1] * 2)]
|
||||
|
||||
log.Println("setupParams", setupparams)
|
||||
}
|
||||
|
||||
// Under construction
|
||||
func (d *OtdrRawData) getMiscParams() {
|
||||
m := MiscParams{}
|
||||
|
||||
if len(d.SecLocs["MiscParams"]) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
slicedMiscParams := strings.Split(d.Decodedfile[d.SecLocs["MiscParams"][1]+10:d.SecLocs[d.GetNext("MiscParams")][1]], "\x00")[1:]
|
||||
|
||||
m.Mode = d.extractData(slicedMiscParams, 0)
|
||||
m.FiberType = d.extractData(slicedMiscParams, 1)
|
||||
|
||||
d.MiscParams = m
|
||||
}
|
||||
|
||||
// Under construction
|
||||
func (d *OtdrRawData) getAcqParam() {
|
||||
// a :=AcqParam{}
|
||||
|
||||
if len(d.SecLocs["AcqParam"]) == 0 {
|
||||
// log.Println("AcqParam section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
acqparam := d.HexData[(d.SecLocs["AcqParam"][1]+10)*2 : (d.SecLocs[d.GetNext("AcqParam")][1] * 2)]
|
||||
|
||||
log.Println("AcqParams", acqparam)
|
||||
}
|
||||
|
||||
// Under construction
|
||||
func (d *OtdrRawData) getViewParams() {
|
||||
// v :=ViewParams{}
|
||||
|
||||
if len(d.SecLocs["ViewParams"]) == 0 {
|
||||
// log.Println("ViewParams section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
viewparams := d.HexData[(d.SecLocs["ViewParams"][1]+10)*2 : (d.SecLocs[d.GetNext("ViewParams")][1] * 2)]
|
||||
|
||||
log.Println("viewParams", viewparams)
|
||||
}
|
||||
|
||||
// Under construction
|
||||
func (d *OtdrRawData) getAnalysisParams() {
|
||||
// a :=AnalysisParams{}
|
||||
|
||||
if len(d.SecLocs["AnalysisParams"]) == 0 {
|
||||
// log.Println("AnalysisParams section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
analyticsparams := d.HexData[(d.SecLocs["AnalysisParams"][1]+10)*2 : (d.SecLocs[d.GetNext("AnalysisParams")][1] * 2)]
|
||||
|
||||
log.Println("AnalyticsParams", analyticsparams)
|
||||
}
|
||||
|
||||
// Under construction
|
||||
func (d *OtdrRawData) getSystemParams() {
|
||||
// s :=SystemParams{}
|
||||
|
||||
if len(d.SecLocs["SystemParams"]) == 0 {
|
||||
// log.Println("SystemParams section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
systemparams := d.HexData[(d.SecLocs["SystemParams"][1]+10)*2 : (d.SecLocs[d.GetNext("SystemParams")][1] * 2)]
|
||||
|
||||
log.Println("SystemParams", systemparams)
|
||||
}
|
||||
|
||||
// getFixedParams function extracts the Fixed Parameters from the sor file and stores it in FixInfos struct.
|
||||
func (d *OtdrRawData) getFixedParams() {
|
||||
|
||||
f := FixInfo{}
|
||||
|
||||
if len(d.SecLocs["FxdParams"]) == 0 {
|
||||
log.Println("FxdParams section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
fixInfo := d.HexData[(d.SecLocs["FxdParams"][1]+10)*2 : (d.SecLocs[d.GetNext("FxdParams")][1] * 2)]
|
||||
p := 8
|
||||
|
||||
f.DateTime = time.Unix(parsHexValue(fixInfo[:p]), 0)
|
||||
|
||||
unit, err := hex.DecodeString(fixInfo[p : p+4])
|
||||
nukeIfErr(err)
|
||||
p += 4
|
||||
|
||||
f.ActualWL = float64(parsHexValue(fixInfo[p:p+4])) / 10.0
|
||||
p += 4
|
||||
|
||||
f.AO = float64(parsHexValue(fixInfo[p : p+8]))
|
||||
p += 8
|
||||
|
||||
f.AOD = float64(parsHexValue(fixInfo[p : p+8]))
|
||||
p += 8
|
||||
|
||||
f.PulseWidthNo = parsHexValue(fixInfo[p : p+4])
|
||||
p += 4
|
||||
|
||||
for i := 0; i < int(f.PulseWidthNo); i++ {
|
||||
f.PulseWidth = append(f.PulseWidth, parsHexValue(fixInfo[p:p+4]))
|
||||
p += 4
|
||||
}
|
||||
|
||||
resolution_m_p1 := []float64{}
|
||||
for i := 0; i < int(f.PulseWidthNo); i++ {
|
||||
resolution_m_p1 = append(resolution_m_p1, float64(parsHexValue(fixInfo[p:p+8]))*math.Pow(10, -8))
|
||||
p += 8
|
||||
}
|
||||
|
||||
for i := 0; i < int(f.PulseWidthNo); i++ {
|
||||
f.SampleQTY = append(f.SampleQTY, parsHexValue(fixInfo[p:p+8]))
|
||||
p += 8
|
||||
}
|
||||
|
||||
f.IOR = float64(parsHexValue(fixInfo[p : p+8]))
|
||||
p += 8
|
||||
|
||||
f.RefIndex = f.IOR * math.Pow(10, -5)
|
||||
|
||||
f.FiberSpeed = lightSpeed / f.RefIndex
|
||||
|
||||
for i := 0; i < int(f.PulseWidthNo); i++ {
|
||||
f.Resolution = append(f.Resolution, resolution_m_p1[i]*f.FiberSpeed)
|
||||
}
|
||||
|
||||
f.Backscattering = float64(parsHexValue(fixInfo[p:p+4])) * -0.1
|
||||
p += 4
|
||||
|
||||
f.Averaging = parsHexValue(fixInfo[p : p+8])
|
||||
p += 8
|
||||
|
||||
f.AveragingTime = float64(parsHexValue(fixInfo[p:p+4])) / 600
|
||||
p += 4
|
||||
|
||||
for i := 0; i < int(f.PulseWidthNo); i++ {
|
||||
f.Range = append(f.Range, float64(f.SampleQTY[i])*f.Resolution[i])
|
||||
}
|
||||
|
||||
f.Unit = string(unit)
|
||||
|
||||
d.FixedParams = f
|
||||
}
|
||||
|
||||
func (d *OtdrRawData) getDataPoints() {
|
||||
|
||||
if len(d.SecLocs["DataPts"]) == 0 {
|
||||
log.Println("DataPts section is missing")
|
||||
return
|
||||
}
|
||||
dtpoints := d.HexData[d.SecLocs["DataPts"][1]*2 : d.SecLocs[d.GetNext("DataPts")][1]*2][40:]
|
||||
var start int64 = 0
|
||||
var cumulative_length float64 = 0
|
||||
|
||||
for i := range d.FixedParams.SampleQTY {
|
||||
|
||||
qty := int64(d.FixedParams.SampleQTY[i])
|
||||
resolution := d.FixedParams.Resolution[i]
|
||||
|
||||
var j int64
|
||||
for j = 0; j < qty; j++ {
|
||||
index := start + j
|
||||
if index < int64(len(dtpoints)) {
|
||||
hex_value := dtpoints[index*4 : index*4+4]
|
||||
db_value := math.Round(dB(parsHexValue(hex_value))*1000) / 1000
|
||||
passedlen := math.Round(float64(cumulative_length*1000)) / 1000
|
||||
dataPoint := []float64{passedlen, db_value}
|
||||
d.DataPoints = append(d.DataPoints, dataPoint)
|
||||
cumulative_length += resolution
|
||||
}
|
||||
}
|
||||
start += qty
|
||||
}
|
||||
}
|
||||
|
||||
// SupParams function extracts the Supplier Parameters from the sor file and stores it in SupParam struct.
|
||||
func (d *OtdrRawData) getSupParams() {
|
||||
|
||||
if len(d.SecLocs["SupParams"]) == 0 {
|
||||
log.Println("SupParams section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
supString := strings.Split(d.Decodedfile[d.SecLocs["SupParams"][1]+10:d.SecLocs[d.GetNext("SupParams")][1]], "\x00")
|
||||
slicedParams := supString[:len(supString)-1]
|
||||
|
||||
supInfo := SupParam{
|
||||
OTDRSupplier: strings.TrimSpace(slicedParams[0]),
|
||||
OTDRName: strings.TrimSpace(slicedParams[1]),
|
||||
OTDRsn: strings.TrimSpace(slicedParams[2]),
|
||||
OTDRModuleName: strings.TrimSpace(slicedParams[3]),
|
||||
OTDRModuleSN: strings.TrimSpace(slicedParams[4]),
|
||||
OTDRswVersion: strings.TrimSpace(slicedParams[5]),
|
||||
OTDROtherInfo: strings.TrimSpace(slicedParams[6]),
|
||||
}
|
||||
|
||||
d.Supplier = supInfo
|
||||
}
|
||||
|
||||
func (d *OtdrRawData) extractData(data []string, item int) string {
|
||||
if len(data)-1 < item {
|
||||
return ""
|
||||
} else {
|
||||
return strings.TrimSpace(data[item])
|
||||
}
|
||||
}
|
||||
|
||||
// GenParams function extracts the General Parameters from the sor file and stores it in GenParam struct.
|
||||
func (d *OtdrRawData) getGenParams() {
|
||||
|
||||
if len(d.SecLocs["GenParams"]) == 0 {
|
||||
log.Println("GenParams section is missing")
|
||||
return
|
||||
}
|
||||
|
||||
genStringBeforeSplit := strings.Split(d.Decodedfile[d.SecLocs["GenParams"][1]+10:d.SecLocs[d.GetNext("GenParams")][1]], "\x00")
|
||||
genString := genStringBeforeSplit[:len(genStringBeforeSplit)-1]
|
||||
|
||||
genInfo := GenParam{
|
||||
CableID: d.extractData(genString, 0)[2:],
|
||||
Lang: d.extractData(genString, 0)[:2],
|
||||
FiberID: d.extractData(genString, 1),
|
||||
LocationA: d.extractData(genString, 2)[4:],
|
||||
LocationB: d.extractData(genString, 3),
|
||||
CableCode: d.extractData(genString, 4),
|
||||
BuildCondition: d.extractData(genString, 5),
|
||||
Operator: d.extractData(genString, 13),
|
||||
Comment: d.extractData(genString, 14),
|
||||
FiberType: "G." + strconv.FormatInt(parsHexValue(hex.EncodeToString([]byte(d.extractData(genString, 2)[:2]))), 10),
|
||||
OTDRWavelength: strconv.FormatInt(parsHexValue(hex.EncodeToString([]byte(d.extractData(genString, 2)[2:4]))), 10) + " nm",
|
||||
}
|
||||
|
||||
d.GenParams = genInfo
|
||||
}
|
||||
|
||||
// getFiberLength calculates the fiber length and returns it.
|
||||
func (d *OtdrRawData) getFiberLength() {
|
||||
for _, v := range d.Events {
|
||||
if strings.Contains(v.EventType, "EXX") || strings.Contains(v.EventType, "E99") {
|
||||
d.TotalLength = float64(v.EventLocM)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// getBellCoreVersion reads the bellcore version from the sor file and returns it.
|
||||
func (d *OtdrRawData) getBellCoreVersion() {
|
||||
|
||||
if len(d.SecLocs["Map"]) == 0 {
|
||||
log.Println("Map section is missing")
|
||||
return
|
||||
}
|
||||
d.BellCoreVersion = float64(parsHexValue(d.HexData[(d.SecLocs["Map"][0]+4)*2:(d.SecLocs["Map"][0]+5)*2])) / 100.0
|
||||
}
|
||||
|
||||
// getTotalLoss reads the total loss of the fiber from the sor file and returns it.
|
||||
func (d *OtdrRawData) getTotalLoss() {
|
||||
|
||||
if len(d.SecLocs["WaveMTSParams"]) > 0 {
|
||||
totallossinfo := d.HexData[(d.SecLocs["WaveMTSParams"][1]-22)*2 : (d.SecLocs["WaveMTSParams"][1]-18)*2]
|
||||
d.TotalLoss = float64(parsHexValue(totallossinfo)) * 0.001
|
||||
} else {
|
||||
d.TotalLoss = 0
|
||||
}
|
||||
}
|
||||
|
||||
// getKeyEvents function extracts the events information from the sor file and stores it in OTDREvent struct.
|
||||
func (d *OtdrRawData) getKeyEvents() {
|
||||
|
||||
d.Events = map[int]OTDREvent{}
|
||||
|
||||
if len(d.SecLocs["KeyEvents"]) == 0 {
|
||||
log.Println("KeyEvents section is missing")
|
||||
return
|
||||
}
|
||||
events := d.HexData[(d.SecLocs["KeyEvents"][1]+10)*2 : d.SecLocs[d.GetNext("KeyEvents")][1]*2]
|
||||
p := d.mapKeyEvents(events)
|
||||
|
||||
var eventhexlist []string
|
||||
for _, v := range p {
|
||||
eventhexlist = append(eventhexlist, events[v[0]:v[1]])
|
||||
}
|
||||
|
||||
for _, e := range eventhexlist {
|
||||
|
||||
event := OTDREvent{}
|
||||
eNum := int(parsHexValue(e[:4]))
|
||||
event.EventNumber = eNum
|
||||
|
||||
event.EventLocM = float64(parsHexValue(e[4:12])) * (math.Pow(10, -4)) * float64(d.FixedParams.FiberSpeed)
|
||||
|
||||
stValue := mod(event.EventLocM, d.FixedParams.Resolution[0])
|
||||
if stValue >= d.FixedParams.Resolution[0]/2 {
|
||||
event.EventLocM = event.EventLocM + (d.FixedParams.Resolution[0] - stValue)
|
||||
} else {
|
||||
event.EventLocM = event.EventLocM + -stValue
|
||||
}
|
||||
|
||||
event.EventLocM = math.Round(event.EventLocM*1000) / 1000
|
||||
|
||||
event.Slope = float64(parsHexValue(e[12:16])) * 0.001
|
||||
event.SpliceLoss = float64(parsHexValue(e[16:20])) * 0.001
|
||||
if parsHexValue(e[20:28]) > 0 {
|
||||
event.RefLoss = float64((float64(parsHexValue(e[20:28])) - math.Pow(2, 32)) * 0.001)
|
||||
} else {
|
||||
event.RefLoss = float64(parsHexValue(e[20:28]))
|
||||
}
|
||||
|
||||
eventType, err := hex.DecodeString(e[28:44])
|
||||
nukeIfErr(err)
|
||||
event.EventType = string(eventType)
|
||||
event.EndOfPreviousEvent = int(parsHexValue(e[44:52]))
|
||||
event.BegOfCurrentEvent = int(parsHexValue(e[52:60]))
|
||||
event.EndOfCurrentEvent = int(parsHexValue(e[60:68]))
|
||||
event.BegOfNextEvent = int(parsHexValue(e[68:76]))
|
||||
event.PeakCurrentEvent = int(parsHexValue(e[76:84]))
|
||||
if len(e) > 88 {
|
||||
if len(e) < 102 {
|
||||
comment, err := hex.DecodeString(e[84:])
|
||||
nukeIfErr(err)
|
||||
event.Comment = string(comment)
|
||||
} else {
|
||||
comment, err := hex.DecodeString(e[84:102])
|
||||
nukeIfErr(err)
|
||||
event.Comment = string(comment)
|
||||
}
|
||||
}
|
||||
d.Events[eNum] = event
|
||||
}
|
||||
}
|
||||
98
gotdr/structs.go
Normal file
98
gotdr/structs.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package gotdr
|
||||
|
||||
import "time"
|
||||
|
||||
type csvFile struct {
|
||||
Filename string `json:"File Name"`
|
||||
EOF float64 `json:"Fiber Length(km)"`
|
||||
}
|
||||
|
||||
type csvFiles struct {
|
||||
Csvs []csvFile
|
||||
}
|
||||
|
||||
type OtdrRawData struct {
|
||||
Filename string `json:"File Name"`
|
||||
Decodedfile string
|
||||
HexData string
|
||||
SecLocs map[string][]int
|
||||
FixedParams FixInfo `json:"Fixed Parameters"`
|
||||
TotalLoss float64 `json:"Total Fiber Loss(dB)"`
|
||||
TotalLength float64 `json:"Fiber Length(km)"`
|
||||
GenParams GenParam `json:"General Information"`
|
||||
Supplier SupParam `json:"Supplier Information"`
|
||||
Events map[int]OTDREvent `json:"Key Events"`
|
||||
BellCoreVersion float64 `json:"Bellcore Version"`
|
||||
DataPoints [][]float64
|
||||
Distance []float64
|
||||
Power []float64
|
||||
MiscParams MiscParams
|
||||
}
|
||||
|
||||
type MiscParams struct {
|
||||
Mode string `json:"Scan Mode"`
|
||||
FiberType string `json:"Fiber Type"`
|
||||
}
|
||||
|
||||
// SupParam is the Supplier Parameters extracted from the sor file.
|
||||
type SupParam struct {
|
||||
OTDRSupplier string `json:"OTDR Supplier"`
|
||||
OTDRName string `json:"OTDR Name"`
|
||||
OTDRsn string `json:"OTDR SN"`
|
||||
OTDRModuleName string `json:"OTDR Module Name"`
|
||||
OTDRModuleSN string `json:"OTDR Module SN"`
|
||||
OTDRswVersion string `json:"OTDR SW Version"`
|
||||
OTDROtherInfo string `json:"OTDR Other Info"`
|
||||
}
|
||||
|
||||
// GenParams is the General Parameters extracted from the sor file.
|
||||
type GenParam struct {
|
||||
CableID string `json:"Cable Id"`
|
||||
Lang string `json:"Language"`
|
||||
FiberID string `json:"Fiber Id"`
|
||||
LocationA string `json:"Location A"`
|
||||
LocationB string `json:"Location B"`
|
||||
BuildCondition string `json:"Build Condition"`
|
||||
Comment string `json:"Comment"`
|
||||
CableCode string `json:"Cable Code"`
|
||||
Operator string `json:"Operator"`
|
||||
FiberType string `json:"Fiber Type"`
|
||||
OTDRWavelength string `json:"OTDR Wavelength"`
|
||||
}
|
||||
|
||||
// OTDREvent is the event information extracted from the sor file.
|
||||
type OTDREvent struct {
|
||||
EventType string `json:"Event Type"`
|
||||
EventLocM float64 `json:"Event Point(m)"`
|
||||
EventNumber int `json:"Event Number"`
|
||||
Slope float64 `json:"Slope(dB)"`
|
||||
SpliceLoss float64 `json:"Splice Loss(dB)"`
|
||||
RefLoss float64 `json:"Reflection Loss(dB)"`
|
||||
EndOfPreviousEvent int `json:"Previous Event-End"`
|
||||
BegOfCurrentEvent int `json:"Current Event-Start"`
|
||||
EndOfCurrentEvent int `json:"Current Event-End"`
|
||||
BegOfNextEvent int `json:"Next Event-Start"`
|
||||
PeakCurrentEvent int `json:"Peak point"`
|
||||
Comment string `json:"Comment"`
|
||||
Power float64 `json:"Power"`
|
||||
}
|
||||
|
||||
// FixInfos struct is the Fixed parameters extracted from the sor file.
|
||||
type FixInfo struct {
|
||||
DateTime time.Time
|
||||
Unit string
|
||||
ActualWL float64 `json:"Actual Wavelength"`
|
||||
PulseWidthNo int64 `json:"Pulse Width No"`
|
||||
PulseWidth []int64 `json:"Pulse Width(ns)"`
|
||||
SampleQTY []int64 `json:"Sample Quantity"`
|
||||
IOR float64 `json:"IOR"`
|
||||
RefIndex float64 `json:"Refraction Index"`
|
||||
FiberSpeed float64 `json:"Fiber Light Speed"`
|
||||
Resolution []float64 `json:"Scan Resolution"`
|
||||
Backscattering float64 `json:"Back-Scattering"`
|
||||
Averaging int64 `json:"Averaging"`
|
||||
AveragingTime float64 `json:"Averaging Time"`
|
||||
Range []float64 `json:"Scan Range"`
|
||||
AO float64 `json:"AO"`
|
||||
AOD float64 `json:"AOD"`
|
||||
}
|
||||
85
main.go
85
main.go
|
|
@ -1,20 +1,78 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"image/png"
|
||||
"strconv"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/app"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dBiTech/go-sor/sor"
|
||||
"jonasled.dev/jonasled/otdr-reporter/fiber"
|
||||
"jonasled.dev/jonasled/otdr-reporter/gotdr"
|
||||
|
||||
"gonum.org/v1/plot"
|
||||
"gonum.org/v1/plot/plotter"
|
||||
"gonum.org/v1/plot/plotutil"
|
||||
"gonum.org/v1/plot/vg"
|
||||
)
|
||||
|
||||
var SorFile *sor.SORFile
|
||||
func renderPlot(sor *gotdr.OtdrRawData, mainWindow *fyne.Window) []byte {
|
||||
p := plot.New()
|
||||
p.X.Label.Text = sor.FixedParams.Unit
|
||||
p.X.AutoRescale = true
|
||||
p.Y.Label.Text = "dB"
|
||||
p.Y.AutoRescale = true
|
||||
plotPoints := plotter.XYs{}
|
||||
|
||||
for _, point := range sor.DataPoints {
|
||||
plotPoints = append(plotPoints, plotter.XY{
|
||||
X: float64(point[0]),
|
||||
Y: float64(point[1]),
|
||||
})
|
||||
}
|
||||
plotutil.AddLines(p, "", plotPoints)
|
||||
|
||||
for _, ev := range sor.Events {
|
||||
eventID := ev.EventNumber
|
||||
fmt.Println(ev.EventLocM)
|
||||
|
||||
// vertical line spanning current Y range
|
||||
linePts := plotter.XYs{
|
||||
{X: ev.EventLocM, Y: p.Y.Min},
|
||||
{X: ev.EventLocM, Y: p.Y.Max},
|
||||
}
|
||||
vline, err := plotter.NewLine(linePts)
|
||||
if err == nil {
|
||||
vline.Color = color.RGBA{R: 200, G: 0, B: 0, A: 255} // red line
|
||||
vline.Dashes = []vg.Length{vg.Points(3), vg.Points(3)} // dashed
|
||||
p.Add(vline)
|
||||
}
|
||||
|
||||
// label near top
|
||||
lbl, err := plotter.NewLabels(plotter.XYLabels{
|
||||
XYs: []plotter.XY{{X: ev.EventLocM, Y: p.Y.Max}},
|
||||
Labels: []string{strconv.Itoa(int(eventID))},
|
||||
})
|
||||
if err == nil {
|
||||
p.Add(lbl)
|
||||
}
|
||||
}
|
||||
|
||||
plot, err := p.WriterTo(16*vg.Inch, 4*vg.Inch, "png")
|
||||
if err != nil {
|
||||
dialog.NewInformation("Failed rendering graph", err.Error(), *mainWindow)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
plot.WriteTo(&buf)
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func main() {
|
||||
application := app.New()
|
||||
|
|
@ -87,6 +145,10 @@ func main() {
|
|||
title,
|
||||
)
|
||||
|
||||
plotCanvas := &canvas.Image{}
|
||||
plotCanvas.ScaleMode = canvas.ImageScalePixels
|
||||
plotCanvas.Resize(fyne.NewSize(1920, 782))
|
||||
|
||||
buttonReadFile := widget.NewButton("Open .sor file", func() {
|
||||
onChosen := func(f fyne.URIReadCloser, err error) {
|
||||
if err != nil {
|
||||
|
|
@ -96,16 +158,20 @@ func main() {
|
|||
if f == nil {
|
||||
return
|
||||
}
|
||||
sorFile, err := sor.ParseFile(f.URI().Path())
|
||||
SorFile = sorFile
|
||||
sor := gotdr.ReadSorFile(f.URI().Path())
|
||||
if err != nil {
|
||||
dialog.NewInformation("Failed reading files", err.Error(), mainWindow)
|
||||
}
|
||||
wavelengthInput.SetText(strconv.Itoa(int(sorFile.GeneralParams.NominalWavelength)))
|
||||
pulsewidthInput.SetText(strconv.Itoa(int(sorFile.FixedParams.PulseWidthsUsed[0])))
|
||||
fibertypeInput.SetText(fiber.FiberTypeName(int(sorFile.GeneralParams.FiberType)))
|
||||
locationaInput.SetText(sorFile.GeneralParams.OriginatingLocation)
|
||||
locationbInput.SetText(sorFile.GeneralParams.TerminatingLocation)
|
||||
|
||||
wavelengthInput.SetText(sor.GenParams.OTDRWavelength)
|
||||
pulsewidthInput.SetText(strconv.Itoa(int(sor.FixedParams.PulseWidth[0])))
|
||||
fibertypeInput.SetText(fiber.FiberTypeName(sor.GenParams.FiberType))
|
||||
locationaInput.SetText(sor.GenParams.LocationA)
|
||||
locationbInput.SetText(sor.GenParams.LocationB)
|
||||
plot := renderPlot(&sor, &mainWindow)
|
||||
image, _ := png.Decode(bytes.NewReader(plot))
|
||||
plotCanvas.Image = image
|
||||
plotCanvas.Resize(fyne.NewSize(float32(image.Bounds().Dx()), float32(image.Bounds().Dy())))
|
||||
|
||||
tabs.SelectIndex(1)
|
||||
|
||||
|
|
@ -117,6 +183,7 @@ func main() {
|
|||
|
||||
tabs.Append(container.NewTabItem("File", fileLayout))
|
||||
tabs.Append(container.NewTabItem("Parameters", parametersLayout))
|
||||
tabs.Append(container.NewTabItem("Plot", plotCanvas))
|
||||
|
||||
mainContainer := container.New(layout.NewVBoxLayout(), tabs)
|
||||
mainWindow.SetContent(mainContainer)
|
||||
|
|
|
|||
6
renovate.json
Normal file
6
renovate.json
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue