revid: cleaned and added commenting

This commit is contained in:
saxon 2018-12-14 16:46:36 +10:30
parent 239b52ad84
commit fbdce669e7
5 changed files with 18 additions and 5 deletions

View File

@ -156,6 +156,8 @@ func (s *httpSender) send() error {
return s.extractMeta(reply) return s.extractMeta(reply)
} }
// extractMeta looks at a reply at extracts any time or location data - then used
// to update time and location information in the mpegts encoder.
func (s *httpSender) extractMeta(r string) error { func (s *httpSender) extractMeta(r string) error {
dec, err := netsender.NewJsonDecoder(r) dec, err := netsender.NewJsonDecoder(r)
if err != nil { if err != nil {

View File

@ -169,6 +169,8 @@ func (e *Encoder) Encode(nalu []byte) error {
return nil return nil
} }
// writePSI creates mpegts with pat and pmt tables - with pmt table having updated
// location and time data.
func (e *Encoder) writePSI() error { func (e *Encoder) writePSI() error {
// Write PAT // Write PAT
patPkt := Packet{ patPkt := Packet{
@ -209,6 +211,8 @@ func (e *Encoder) writePSI() error {
return nil return nil
} }
// addPadding adds an appropriate amount of padding to a pat or pmt table for
// addition to an mpegts packet
func addPadding(d []byte) []byte { func addPadding(d []byte) []byte {
for len(d) < psiPacketSize { for len(d) < psiPacketSize {
d = append(d, 0xff) d = append(d, 0xff)

View File

@ -35,7 +35,7 @@ import (
"math/bits" "math/bits"
) )
// timeBytes takes a timestamp as an uint64 and converts to an 8 byte slice - // TimeBytes takes a timestamp as an uint64 and converts to an 8 byte slice -
// allows for updating of timestamp in pmt time descriptor. // allows for updating of timestamp in pmt time descriptor.
func TimeBytes(t uint64) []byte { func TimeBytes(t uint64) []byte {
var s [timeDataSize]byte var s [timeDataSize]byte
@ -43,7 +43,7 @@ func TimeBytes(t uint64) []byte {
return s[:] return s[:]
} }
// ChkTime takes a psi as a byte slice and checks to see if it has a time descriptor // HasTime takes a psi as a byte slice and checks to see if it has a time descriptor
// - if so return nil, otherwise return error // - if so return nil, otherwise return error
func HasTime(p []byte) error { func HasTime(p []byte) error {
if p[timeTagIndx] != timeDescTag { if p[timeTagIndx] != timeDescTag {
@ -52,7 +52,7 @@ func HasTime(p []byte) error {
return nil return nil
} }
// ChkLocation takes a psi as a byte slice and checks to see if it has a location descriptor // HasLocation takes a psi as a byte slice and checks to see if it has a location descriptor
// - if so return nil, otherwise return error // - if so return nil, otherwise return error
func HasLocation(p []byte) error { func HasLocation(p []byte) error {
if p[locationTagIndx] != locationDescTag { if p[locationTagIndx] != locationDescTag {
@ -77,7 +77,7 @@ func UpdateTime(dst []byte, t uint64) error {
return nil return nil
} }
// TimeOf takes a byte slice representation of a psi-pmt and extracts it's // TimeFrom takes a byte slice representation of a psi-pmt and extracts it's
// timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil // timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil
// if it does not exist // if it does not exist
func TimeFrom(p []byte) (t uint64, err error) { func TimeFrom(p []byte) (t uint64, err error) {
@ -89,7 +89,7 @@ func TimeFrom(p []byte) (t uint64, err error) {
return t, nil return t, nil
} }
// TimeOf takes a byte slice representation of a psi-pmt and extracts it's // LocationFrom takes a byte slice representation of a psi-pmt and extracts it's
// timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil // timestamp, returning as a uint64 if it exists, otherwise returning 0 and nil
// if it does not exist // if it does not exist
func LocationFrom(p []byte) (g string, err error) { func LocationFrom(p []byte) (g string, err error) {
@ -130,12 +130,14 @@ func UpdateLocation(d []byte, s string) error {
return nil return nil
} }
// addCrc appends a crc table to a given psi table in bytes
func addCrc(out []byte) []byte { func addCrc(out []byte) []byte {
out = append(out, make([]byte, 4)...) out = append(out, make([]byte, 4)...)
out = updateCrc(out) out = updateCrc(out)
return out return out
} }
// updateCrc updates the crc of psi bytes slice that may have been modified
func updateCrc(out []byte) []byte { func updateCrc(out []byte) []byte {
crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), out[1:len(out)-4]) crc32 := crc32_Update(0xffffffff, crc32_MakeTable(bits.Reverse32(crc32.IEEE)), out[1:len(out)-4])
out[len(out)-4] = byte(crc32 >> 24) out[len(out)-4] = byte(crc32 >> 24)

View File

@ -160,6 +160,7 @@ func readTSS(data []byte, p *PSI) *TSS {
return &tss return &tss
} }
// readPAT creates a pat struct based on a bytes slice representing a pat
func readPAT(data []byte, p *TSS) *PAT { func readPAT(data []byte, p *TSS) *PAT {
pat := PAT{} pat := PAT{}
pos := 0 pos := 0
@ -169,6 +170,7 @@ func readPAT(data []byte, p *TSS) *PAT {
return &pat return &pat
} }
// readPMT creates a pmt struct based on a bytes slice that represents a pmt
func readPMT(data []byte, p *TSS) *PAT { func readPMT(data []byte, p *TSS) *PAT {
pmt := PMT{} pmt := PMT{}
pos := 0 pos := 0
@ -205,6 +207,7 @@ func readDescs(data []byte, descLen int) (o []Desc) {
return return
} }
// readEESD creates an ESSD struct based on a bytes slice that represents ESSD
func readEssd(data []byte) *ESSD { func readEssd(data []byte) *ESSD {
essd := ESSD{} essd := ESSD{}
pos := 0 pos := 0

View File

@ -38,6 +38,7 @@ const (
) )
// GPS string for testing // GPS string for testing
// TODO: make these realistic
const ( const (
locationTstStr1 = "$GPGGA,123519,4807.038,N,01131.0" locationTstStr1 = "$GPGGA,123519,4807.038,N,01131.0"
locationTstStr2 = "$GPGGA,183710,4902.048,N,02171.0" locationTstStr2 = "$GPGGA,183710,4902.048,N,02171.0"
@ -240,6 +241,7 @@ func TestTimeGet(t *testing.T) {
} }
} }
// TestLocationGet checks that we can correctly get location data from a pmt table
func TestLocationGet(t *testing.T) { func TestLocationGet(t *testing.T) {
pb := StdPmtTimeLocation.Bytes() pb := StdPmtTimeLocation.Bytes()
err := UpdateLocation(pb, locationTstStr1) err := UpdateLocation(pb, locationTstStr1)