// -------------------------------
// sends a message over TCP
sends a message over TCP
// ------------------------------- // sends a message over TCP
func tcpSend(cnx net.Conn, cmd int, data []byte) error {
	now := time.Now()
	cnx.SetWriteDeadline(now.Add(10 * time.Second))
	b := make([]byte, 0, 16)
	b = append(b, ui2b(uint(0x55aa), 4)...)
	b = append(b, ui2b(uint(cmd), 8)...)
	b = append(b, ui2b(uint(len(data)+8), 4)...)
	b = append(b, data...)
	b = append(b, ui2b(uint(crc32.ChecksumIEEE(b)), 4)...)
	b = append(b, ui2b(uint(0xaa55), 4)...)
	if _, err := cnx.Write(b); err != nil {
		log.Println(err)
		return err
	}
	return nil
}
func tcpSend ( cnx net . Conn , cmd int , data [ ] byte ) error { now := time . Now ( ) cnx . SetWriteDeadline ( now . Add ( 10 * time . Second ) ) b := make ( [ ] byte , 0 , 16 ) b = append ( b , ui2b ( uint ( 0x55aa ) , 4 ) ... ) b = append ( b , ui2b ( uint ( cmd ) , 8 ) ... ) b = append ( b , ui2b ( uint ( len ( data ) + 8 ) , 4 ) ... ) b = append ( b , data ... ) b = append ( b , ui2b ( uint ( crc32 . ChecksumIEEE ( b ) ) , 4 ) ... ) b = append ( b , ui2b ( uint ( 0xaa55 ) , 4 ) ... ) if _ , err := cnx . Write ( b ) ; err != nil { log . Println ( err ) return err } return nil }
sends a message over TCP
sends a message over TCP
// simple appliances are expected to reply quickly // tuya appliances cannot handle multiple read!! // => fill a buffer and write it