package machinedoll import ( "fmt" "net" ) // 向前aa 05 01 50 01 01 54 dd func Forward(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x01, 0x01} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 向前停止aa 05 01 50 01 00 55 dd func ForwardStop(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x01, 0x00} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 向后 // aa 05 01 50 02 01 57 dd func Backward(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x02, 0x01} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 向后停止aa 05 01 50 02 00 56 dd func BackwardStop(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x02, 0x00} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 向左aa 05 01 50 03 01 56 dd func Left(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x03, 0x01} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 向左停止aa 05 01 50 03 00 57 dd func LeftStop(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x03, 0x00} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 向右 func Right(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x04, 0x01} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 向右停止aa 05 01 50 04 00 50 dd func RightStop(conn net.Conn) { instruction := []byte{0xaa, 0x05, 0x01, 0x50, 0x04, 0x00} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 强抓下抓 func Grab(conn net.Conn) { instruction := []byte{0xAA, 0x05, 0x01, 0x50, 0x06, 0x01} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) _, err = conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } } // 弱抓aa 05 01 50 06 00 52 dd func WeakGrab(conn net.Conn) { instruction := []byte{0xAA, 0x05, 0x01, 0x50, 0x06, 0x00} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 投币 func Coin(conn net.Conn) { moveCommand := []byte{0xaa, 0x08, 0x01, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00} moveCommand = calculateChecksum(moveCommand) // 发送指令到服务端 _, err := conn.Write(moveCommand) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } if buf[4] == 1 { fmt.Println("上分成功!!!!n = ", n) } if buf[4] == 0 { fmt.Println("上分失败!!!") } } // 剩余局数清零 func ClearRemainingGames(conn net.Conn) { instruction := []byte{0xAA, 0x03, 0x01, 0x32} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } fmt.Println("n", n) } // 计算校验码 func calculateChecksum(data []byte) []byte { var value = byte(0) for i, datum := range data { if i > 0 { value ^= datum } } fmt.Println("校验码 value = ", value) data = append(data, value, 0xdd) return data } // 开启音乐 func OpenMusic(conn net.Conn) { data[43] = 0x01 instruction := []byte{0xAA, 0x33, 0x01, 0x06} instruction = append(instruction, data...) instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } fmt.Println("n", n) } // 关闭音乐 func CloseMusic(conn net.Conn) { data[43] = 0x00 instruction := []byte{0xAA, 0x33, 0x01, 0x06} instruction = append(instruction, data...) instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } fmt.Println("n", n) } // 恢复出厂设置 func RestoreFactorySettings(conn net.Conn) { instruction := []byte{0xAA, 0x03, 0x01, 0x38} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } fmt.Println("n", n) } // 重启主板 func Reboot(conn net.Conn) { instruction := []byte{0xAA, 0x03, 0x01, 0x39} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } fmt.Println("n", n) } // 暂停服务 func StopServer(conn net.Conn) { instruction := []byte{0xAA, 0x03, 0x01, 0x37} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 开启服务 func StartServer(conn net.Conn) { instruction := []byte{0xAA, 0x03, 0x01, 0x36} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } } // 查询基础参数 func queryBaseParam(conn net.Conn) { instruction := []byte{0xAA, 0x03, 0x01, 0x05} instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } fmt.Println("n", n) } // 设置强力 func SetPower(conn net.Conn) { data[3] = 0x00 data[16] = 0x01 data[17] = 0xE0 data[18] = 0x13 data[19] = 0x88 fmt.Println("data.len = ", len(data)) instruction := []byte{0xAA, 0x33, 0x01, 0x06} instruction = append(instruction, data...) instruction = calculateChecksum(instruction) _, err := conn.Write(instruction) if err != nil { fmt.Println("Failed to send command to server:", err) return } // 读取服务端的响应 buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Failed to read response from server:", err) return } fmt.Println("n", n) } var data = []byte{ 0x65, 0x00, 0x0F, 0x02, 0x0F, 0x00, 0x01, 0x00, 0x00, 0x01, 0xC8, 0x00, 0x7C, 0x01, 0x5A, 0x00, 0xE0, 0x01, 0xC8, 0x00, 0x14, 0x32, 0x32, 0x50, 0x34, 0x08, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x32, 0x02, 0x00, 0x00, 0xC8, 0x00, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x07, 0x08, 0x00, }