Exemplo n.º 1
0
func n2kMessageReceived(msg []byte) (*can.RawMessage, error) {

	// Packet length from NGT1
	if msg[0] < 11 {
		return nil, errors.New(fmt.Sprintf("Ignore short msg", len(msg)))
	}

	raw := new(can.RawMessage)
	raw.Timestamp = time.Now()
	raw.Priority = msg[1]
	raw.Pgn = uint32(msg[2]) | uint32(msg[3])<<8 | uint32(msg[4])<<16
	raw.Destination = msg[5]
	raw.Source = msg[6]
	// Skip the timestamp (bytes 7-10)
	lth := msg[11]

	if lth > 223 {
		return nil, errors.New(fmt.Sprintf("Ignore long msg", lth))
	}

	raw.Length = lth
	lth += 12
	raw.Data = msg[12:lth]

	return raw, nil
}
Exemplo n.º 2
0
func ngtMessageReceived(msg []byte) (*can.RawMessage, error) {

	pLen := msg[0]

	if pLen < 12 {
		return nil, errors.New(fmt.Sprintf("Ignore short msg", len(msg)))
	}

	raw := new(can.RawMessage)
	raw.Timestamp = time.Now()
	raw.Priority = 0
	raw.Pgn = 0x40000 + uint32(msg[1])
	raw.Destination = 0
	raw.Source = 0
	raw.Length = pLen - 1
	pLen++
	raw.Data = msg[2:pLen]

	return raw, nil
}