Browse Source

Initial commit

master
Christopher Ramey 5 years ago
committed by Christopher Ramey
commit
4e785a0377
  1. 76
      sdb.go

76
sdb.go

@ -0,0 +1,76 @@
package main
import (
"os"
"fmt"
"bytes"
"encoding/binary"
"io/ioutil"
)
type IridiumSDB struct {
ProtocolRevision byte
MessageLength uint16
Message MOMessage
}
type MOMessage struct {
HeaderIEI byte
HeaderLength uint16
CDRReference uint32
IMEI [15]byte
Status byte
MOMSN uint16
MTMSN uint16
SessionTime uint32
}
var SessionStatusString = []string{
"The SBD session completed successfully.",
"The MO message transfer, if any, was successful. The MT message queued at the Iridium Gateway is too large to be transferred within a single SBD session.",
"The MO message transfer, if any, was successful. The reported location was determined to be of unacceptable quality. This value is only applicable to IMEIs using SBD protocol revision 1.",
"", // 3
"", // 4
"", // 5
"", // 6
"", // 7
"", // 8
"", // 9
"The SBD session timed out before session completion.",
"", // 11
"The MO message being transferred by the IMEI is too large to be transferred within a single SBD session.",
"An RF link loss occurred during the SBD session.",
"An IMEI protocol anomaly occurred during SBD session.",
"The IMEI is prohibited from accessing the Iridium Gateway."}
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "required argument missing\n")
os.Exit(1)
}
rdt, err := ioutil.ReadFile(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "error reading %s: %s\n", os.Args[1], err.Error())
os.Exit(1)
}
header := IridiumSDB{}
buf := bytes.NewBuffer(rdt)
err = binary.Read(buf, binary.BigEndian, &header)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing %s: %s\n", os.Args[1], err.Error())
os.Exit(1)
}
fmt.Fprintf(os.Stdout, "Protocol Revision: %d\n", header.ProtocolRevision)
fmt.Fprintf(os.Stdout, "Message Length: %d\n", header.MessageLength)
fmt.Fprintf(os.Stdout, "MO Header IEI: %x\n", header.Message.HeaderIEI)
fmt.Fprintf(os.Stdout, "MO Header Length: %d\n", header.Message.HeaderLength)
fmt.Fprintf(os.Stdout, "CDR Reference: %d\n", header.Message.CDRReference)
fmt.Fprintf(os.Stdout, "IMEI: %s\n", string(header.Message.IMEI[:]))
fmt.Fprintf(os.Stdout, "Status: %s (%d)\n", SessionStatusString[header.Message.Status], header.Message.Status)
fmt.Fprintf(os.Stdout, "MOMSN: %d\n", header.Message.MOMSN)
fmt.Fprintf(os.Stdout, "MTMSN: %d\n", header.Message.MTMSN)
fmt.Fprintf(os.Stdout, "Session Time: %d\n", header.Message.SessionTime)
}
Loading…
Cancel
Save