func NewPacketPipe(deviceID uint32, seq uint16, subtype uint8, data []byte) *Packet {
	if len(data) > 0xff {
		panic("payload is too long")
	}
	var buf bytes.Buffer
	binary.Write(&buf, binary.BigEndian, deviceID)
	binary.Write(&buf, binary.BigEndian, seq)
	buf.WriteByte(0)
	binary.Write(&buf, binary.BigEndian, uint16(0x7e00))  
	buf.Write([]byte{1, 0, 0, 0xf8})                      
	buf.WriteByte(subtype)
	buf.WriteByte(uint8(len(data)))
	buf.Write(data)
	buf.Write([]byte{0, 0, 0})
	return &Packet{
		Type: PacketTypePipe,
		Data: buf.Bytes(),
	}
}
NewPacketPipe creates a "pipe buffer" packet with a given subtype.
package cbyge
import (
	"bytes"
	"encoding/binary"
	"fmt"
	"strings"
	"github.com/pkg/errors"
)
const (
	PacketTypeAuth     uint8 = 1
	PacketTypeSync           = 4
	PacketTypePipe           = 7
	PacketTypePipeSync       = 8
)
const (
	PacketPipeTypeSetStatus          uint8 = 0xd0
	PacketPipeTypeSetLum                   = 0xd2
	PacketPipeTypeSetCT                    = 0xe2
	PacketPipeTypeGetStatus                = 0xdb
	PacketPipeTypeGetStatusPaginated       = 0x52
)
type Packet struct {
	Type       uint8
	IsResponse bool
	Data       []byte
}
func (p *Packet) Seq() (uint16, error) {
	if p.Type != PacketTypePipe || len(p.Data) < 6 {
		return 0, errors.New("packet has no seq number")
	}
	return binary.BigEndian.Uint16(p.Data[4:6]), nil
}