From 836a169ab176c928bf98135fd125c9990c780d07 Mon Sep 17 00:00:00 2001 From: "Jesus F. Trujillo" Date: Wed, 22 Feb 2017 14:32:49 -0800 Subject: [PATCH] add parsing support for 7 bit character format --- lc/talkeralias.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lc/talkeralias.go b/lc/talkeralias.go index 4f244aa..11da688 100644 --- a/lc/talkeralias.go +++ b/lc/talkeralias.go @@ -35,18 +35,39 @@ type TalkerAliasBlockPDU struct { Data []byte } +func movebit(src []byte, srcByte int, srcBit int, dst []byte, dstByte int, dstBit int) { + bit := (src[srcByte] >> uint8(srcBit)) & dmr.B00000001 + if bit >= 1 { + dst[dstByte] |= 1 << uint8(dstBit) + } else { + dst[dstByte] &= 0 << uint8(dstBit) + } +} + // ParseTalkerAliasHeaderPDU parses TalkerAliasHeader PDU from bytes func ParseTalkerAliasHeaderPDU(data []byte) (*TalkerAliasHeaderPDU, error) { if len(data) != 7 { return nil, fmt.Errorf("dmr/lc/talkeralias: expected 7 bytes, got %d", len(data)) } - // TODO parse bit 49 + dataFormat := (data[0] & dmr.B11000000) >> 6 + + var out []byte + if dataFormat == Format7Bit { + // it will reorganize the bits in the array and return []byte with 7bit chars + // in each position + out = make([]byte, 7) + for i := 7; i < 56; i++ { + movebit(data, i/8, (7 - (i % 8)), out, (i-7)/7, 6-(i%7)) + } + } else { + out = data[1:6] + } return &TalkerAliasHeaderPDU{ - DataFormat: (data[0] & dmr.B11000000) >> 6, + DataFormat: dataFormat, Length: (data[0] & dmr.B00111110) >> 1, - Data: data[1:6], + Data: out, }, nil }