Esempio n. 1
0
func (p Parser) Parse(indices []int) (msgs []parse.Message) {
	seen := make(map[string]bool)

	for _, pkt := range p.Decoder.Slice(indices) {
		s := string(pkt)
		if seen[s] {
			continue
		}
		seen[s] = true

		data := parse.NewDataFromBytes(pkt)

		// If the packet is too short, bail.
		if l := len(data.Bytes); l != 12 {
			continue
		}

		// If the checksum fails, bail.
		if p.Checksum(data.Bytes[2:12]) != 0 {
			continue
		}

		scm := NewSCM(data)

		// If the meter id is 0, bail.
		if scm.ID == 0 {
			continue
		}

		msgs = append(msgs, scm)
	}

	return
}
Esempio n. 2
0
func (p Parser) Parse(indices []int) (msgs []parse.Message) {
	seen := make(map[string]bool)

	for _, pkt := range p.Decoder.Slice(indices) {
		s := string(pkt)
		if seen[s] {
			continue
		}
		seen[s] = true

		data := parse.NewDataFromBytes(pkt)

		// If the packet is too short, bail.
		if l := len(data.Bytes); l != 92 {
			continue
		}

		// If the checksum fails, bail.
		if residue := p.Checksum(data.Bytes[4:92]); residue != p.Residue {
			continue
		}

		idm := NewIDM(data)

		// If the meter id is 0, bail.
		if idm.ERTSerialNumber == 0 {
			continue
		}

		msgs = append(msgs, idm)
	}

	return
}
Esempio n. 3
0
func (p Parser) Parse(indices []int) (msgs []parse.Message) {
	seen := make(map[string]bool)

	for _, pkt := range p.Decoder.Slice(indices) {
		s := string(pkt)
		if seen[s] {
			continue
		}
		seen[s] = true

		data := parse.NewDataFromBytes(pkt)

		// If the checksum fails, bail.
		if residue := p.Checksum(data.Bytes[2:]); residue != p.Residue {
			continue
		}

		scm := NewSCM(data)

		// If the meter id is 0, bail.
		if scm.EndpointID == 0 {
			continue
		}

		msgs = append(msgs, scm)
	}

	return
}
Esempio n. 4
0
func (p Parser) Parse(indices []int) (msgs []parse.Message) {
	seen := make(map[string]bool)

	for _, pkt := range p.Decoder.Slice(indices) {
		s := string(pkt)
		if seen[s] {
			continue
		}
		seen[s] = true

		data := parse.NewDataFromBytes(pkt)

		// If the checksum fails, bail.
		if residue := p.Checksum(data.Bytes[4:92]); residue != p.Residue {
			continue
		}

		var idm IDM
		idm.Preamble = binary.BigEndian.Uint32(data.Bytes[0:4])
		idm.PacketTypeID = data.Bytes[4]
		idm.PacketLength = data.Bytes[5]
		idm.HammingCode = data.Bytes[6]
		idm.ApplicationVersion = data.Bytes[7]
		idm.ERTType = data.Bytes[8] & 0x0F
		idm.ERTSerialNumber = binary.BigEndian.Uint32(data.Bytes[9:13])
		idm.ConsumptionIntervalCount = data.Bytes[13]
		idm.ModuleProgrammingState = data.Bytes[14]
		idm.TamperCounters = data.Bytes[15:21]
		idm.AsynchronousCounters = binary.BigEndian.Uint16(data.Bytes[21:23])
		idm.PowerOutageFlags = data.Bytes[23:29]
		idm.LastConsumptionCount = binary.BigEndian.Uint32(data.Bytes[29:33])

		offset := 264
		for idx := range idm.DifferentialConsumptionIntervals {
			interval, _ := strconv.ParseUint(data.Bits[offset:offset+9], 2, 9)
			idm.DifferentialConsumptionIntervals[idx] = uint16(interval)
			offset += 9
		}

		idm.TransmitTimeOffset = binary.BigEndian.Uint16(data.Bytes[86:88])
		idm.SerialNumberCRC = binary.BigEndian.Uint16(data.Bytes[88:90])
		idm.PacketCRC = binary.BigEndian.Uint16(data.Bytes[90:92])

		// If the meter id is 0, bail.
		if idm.ERTSerialNumber == 0 {
			continue
		}

		msgs = append(msgs, idm)
	}

	return
}
Esempio n. 5
0
func (p Parser) Parse(indices []int) (msgs []parse.Message) {
	seen := make(map[string]bool)

	for _, pkt := range p.Decoder.Slice(indices) {
		s := string(pkt)
		if seen[s] {
			continue
		}
		seen[s] = true

		data := parse.NewDataFromBytes(pkt)

		// If the packet is too short, bail.
		if l := len(data.Bytes); l < 12 {
			continue
		}

		// If the checksum fails, bail.
		if p.Checksum(data.Bytes[2:12]) != 0 {
			continue
		}

		ertid, _ := strconv.ParseUint(data.Bits[21:23]+data.Bits[56:80], 2, 26)
		erttype, _ := strconv.ParseUint(data.Bits[26:30], 2, 4)
		tamperphy, _ := strconv.ParseUint(data.Bits[24:26], 2, 2)
		tamperenc, _ := strconv.ParseUint(data.Bits[30:32], 2, 2)
		consumption, _ := strconv.ParseUint(data.Bits[32:56], 2, 24)
		checksum, _ := strconv.ParseUint(data.Bits[80:96], 2, 16)

		var scm SCM

		scm.ID = uint32(ertid)
		scm.Type = uint8(erttype)
		scm.TamperPhy = uint8(tamperphy)
		scm.TamperEnc = uint8(tamperenc)
		scm.Consumption = uint32(consumption)
		scm.Checksum = uint16(checksum)

		// If the meter id is 0, bail.
		if scm.ID == 0 {
			continue
		}

		msgs = append(msgs, scm)
	}

	return
}