correctly handle faulty sor file
This commit is contained in:
parent
0363b8f39e
commit
a0fdd3d443
2 changed files with 11 additions and 7 deletions
|
|
@ -49,7 +49,7 @@ func dB(point int64) float64 {
|
|||
return float64(point*-1000) * math.Pow(10, -6)
|
||||
}
|
||||
|
||||
func ReadSorFile(filename string) OtdrRawData {
|
||||
func ReadSorFile(filename string) (OtdrRawData, error) {
|
||||
|
||||
r := OtdrRawData{
|
||||
Filename: filename,
|
||||
|
|
@ -83,7 +83,10 @@ func ReadSorFile(filename string) OtdrRawData {
|
|||
|
||||
r.Decodedfile = string(chars)
|
||||
|
||||
r.GetOrder()
|
||||
err = r.GetOrder()
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
r.getBellCoreVersion()
|
||||
r.getTotalLoss()
|
||||
r.getSupParams()
|
||||
|
|
@ -99,7 +102,7 @@ func ReadSorFile(filename string) OtdrRawData {
|
|||
r.getAnalysisParams()
|
||||
r.getAcqParam()
|
||||
|
||||
return r
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// parsHexValue calls the Reverse() funcition to reverse the order of the provided HexString and then converts it's value to int64.
|
||||
|
|
@ -182,7 +185,7 @@ func (d *OtdrRawData) GetNext(key string) string {
|
|||
return nextKey
|
||||
}
|
||||
|
||||
func (d *OtdrRawData) GetOrder() {
|
||||
func (d *OtdrRawData) GetOrder() error {
|
||||
sections := []string{
|
||||
"SupParams",
|
||||
"ExfoNewProprietaryBlock",
|
||||
|
|
@ -222,11 +225,11 @@ func (d *OtdrRawData) GetOrder() {
|
|||
}
|
||||
|
||||
if len(sectionLocations["Cksum"]) < 2 {
|
||||
fmt.Printf("%s file has no checksum\n", d.Filename)
|
||||
os.Exit(1)
|
||||
return fmt.Errorf("%s file has no checksum\n", d.Filename)
|
||||
}
|
||||
|
||||
d.SecLocs = sectionLocations
|
||||
return nil
|
||||
}
|
||||
|
||||
// Under construction
|
||||
|
|
|
|||
3
main.go
3
main.go
|
|
@ -285,9 +285,10 @@ func main() {
|
|||
if f == nil {
|
||||
return
|
||||
}
|
||||
sor := gotdr.ReadSorFile(f.URI().Path())
|
||||
sor, err := gotdr.ReadSorFile(f.URI().Path())
|
||||
if err != nil {
|
||||
dialog.NewInformation("Failed reading files", err.Error(), mainWindow).Show()
|
||||
return
|
||||
}
|
||||
|
||||
wavelengthInput.SetText(sor.GenParams.OTDRWavelength)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue