Better separation between library and command
This commit is contained in:
parent
f1becfdb83
commit
3c843cbdcc
73
cmd/sdb/main.go
Normal file
73
cmd/sdb/main.go
Normal file
@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"git.binarythought.com/cdramey/sdb"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"required argument missing\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
raw, err := ioutil.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"error reading \"%s\": %s\n",
|
||||
os.Args[1], err.Error())
|
||||
}
|
||||
|
||||
data, err := sdb.ParseSDB(raw)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"%s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Protocol Revision: %d\n",
|
||||
data.ProtocolRevision)
|
||||
fmt.Printf("Message Length: %d\n",
|
||||
data.Length)
|
||||
for c, i := range data.Elements {
|
||||
if c > 0 {
|
||||
fmt.Println()
|
||||
}
|
||||
switch v := i.(type) {
|
||||
case sdb.MOHeader:
|
||||
fmt.Printf("\tMO Header IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Header Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Header CDR Reference: %d\n",
|
||||
v.CDRReference)
|
||||
fmt.Printf("\tMO Header IMEI: %s\n",
|
||||
v.IMEI)
|
||||
fmt.Printf("\tMO Header Status: %s (%d)\n",
|
||||
v.StatusString(), v.Status)
|
||||
fmt.Printf("\tMO Header MOMSN: %d\n",
|
||||
v.MOMSN)
|
||||
fmt.Printf("\tMO Header MTMSN: %d\n",
|
||||
v.MTMSN)
|
||||
fmt.Printf("\tMO Header Session Time: %s\n",
|
||||
v.SessionTime().String())
|
||||
|
||||
case sdb.MOPayload:
|
||||
fmt.Printf("\tMO Payload IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Payload Length: %d\n",
|
||||
v.Length)
|
||||
|
||||
case sdb.MOConfirmation:
|
||||
fmt.Printf("\tMO Confirmation IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Confirmation Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Confirmation Status: %d\n",
|
||||
v.Status)
|
||||
}
|
||||
}
|
||||
}
|
67
sdb.go
67
sdb.go
@ -4,76 +4,9 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"required argument missing\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
raw, err := ioutil.ReadFile(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"error reading \"%s\": %s\n",
|
||||
os.Args[1], err.Error())
|
||||
}
|
||||
|
||||
sdb, err := ParseSDB(raw)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr,
|
||||
"%s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("Protocol Revision: %d\n",
|
||||
sdb.ProtocolRevision)
|
||||
fmt.Printf("Message Length: %d\n",
|
||||
sdb.Length)
|
||||
for c, i := range sdb.Elements {
|
||||
if c > 0 {
|
||||
fmt.Println()
|
||||
}
|
||||
switch v := i.(type) {
|
||||
case MOHeader:
|
||||
fmt.Printf("\tMO Header IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Header Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Header CDR Reference: %d\n",
|
||||
v.CDRReference)
|
||||
fmt.Printf("\tMO Header IMEI: %s\n",
|
||||
v.IMEI)
|
||||
fmt.Printf("\tMO Header Status: %s (%d)\n",
|
||||
v.StatusString(), v.Status)
|
||||
fmt.Printf("\tMO Header MOMSN: %d\n",
|
||||
v.MOMSN)
|
||||
fmt.Printf("\tMO Header MTMSN: %d\n",
|
||||
v.MTMSN)
|
||||
fmt.Printf("\tMO Header Session Time: %s\n",
|
||||
v.SessionTime().String())
|
||||
|
||||
case MOPayload:
|
||||
fmt.Printf("\tMO Payload IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Payload Length: %d\n",
|
||||
v.Length)
|
||||
|
||||
case MOConfirmation:
|
||||
fmt.Printf("\tMO Confirmation IEI: %d\n",
|
||||
v.IEI)
|
||||
fmt.Printf("\tMO Confirmation Length: %d\n",
|
||||
v.Length)
|
||||
fmt.Printf("\tMO Confirmation Status: %d\n",
|
||||
v.Status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type IridiumSDB struct {
|
||||
ProtocolRevision byte
|
||||
Length uint16
|
||||
|
Loading…
Reference in New Issue
Block a user