// ReadPacket reads one Packet from the monitor.
// An error will be returned on an I/O error or if a message could not be read or decoded.
ReadPacket reads one Packet from the monitor.
An error will be returned on an I/O error or if a message could not be read or decoded.
// ReadPacket reads one Packet from the monitor . // An error will be returned on an I / O error or if a message could not be read or decoded .
func (d *Device) ReadPacket() (*Packet, error) {
	var pack *Packet
	for !pack.isValid() {
		buf := make([]byte, 8)
		_, err := d.file.Read(buf)
		if err != nil {
			return nil, fmt.Errorf("file.Read(): %w", err)
		}
		var data [8]byte
		copy(data[:], buf)
		if data[4] != 0x0d && !d.opts.withoutDecrypt {
			data = Decrypt(data, d.opts.key)
		}
		err = validate(data)
		if err != nil {
			return nil, fmt.Errorf("validation failed: %w", err)
		}
		pack = newPacket(data)
	}
	return pack, nil
}
func ( d * Device ) ReadPacket ( ) ( * Packet , error ) { var pack * Packet for ! pack . isValid ( ) { buf := make ( [ ] byte , 8 ) _ , err := d . file . Read ( buf ) if err != nil { return nil , fmt . Errorf ( " " , err ) } var data [ 8 ] byte copy ( data [ : ] , buf ) if data [ 4 ] != 0x0d && ! d . opts . withoutDecrypt { data = Decrypt ( data , d . opts . key ) } err = validate ( data ) if err != nil { return nil , fmt . Errorf ( " " , err ) } pack = newPacket ( data ) } return pack , nil }
ReadPacket reads one Packet from the monitor.
ReadPacket reads one Packet from the monitor .
// If the "magic byte" is present no decryption is necessary. // This is the case for AIRCO2NTROL COACH and newer AIRCO2NTROL MINIs in general.