game_sync/machine/machinedoll/command.go

435 lines
11 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
instruction = []byte{0xAA, 0x04, 0x01, 0x50, 0x09, 0x5c, 0xdd}
_, err = conn.Write(instruction)
if err != nil {
fmt.Println("Failed to read response from server:", err)
return
}*/
}
// 必中抓
func Grab2(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)
//instruction[1] = byte(len(instruction) - 3)
_, 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] = 0x01
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)*/
}
// 基础设置
func SetBaseParam(conn net.Conn) {
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)
if buf[4] == 1 {
fmt.Println("设置成功!")
} else {
fmt.Println("设置失败!")
}
}
var data = []byte{
0x65, //0 几币几玩
0x00, //1 几币几玩占用位
0x2D, //2 游戏时间
0x00, //3 出奖模式0 无概率 1 随机模式 2 固定模式 3 冠兴模式
0x14, //4 出奖概率
0x00, //5 出奖概率占用位
0x00, //6 空中抓物 0关闭 1开启
0x00, //7 连续投币赠送 范围0~100
0x00, //8 保夹次数 范围06 6为无限次
0x01, //9 保夹赠送模式 0送游戏 1送中奖 2送游戏和中奖
0x80, //10 强抓力电压
0x01, //11 强抓力电压占用位
0x80, //12 中抓力电压
0x01, //13 中抓力电压占用位
0x78, //14 弱抓力电压
0x00, //15 弱抓力电压占用位
0xE0, //16 中奖电压
0x01, //17 中奖电压占用位
0xC8, //18 强抓力时间
0x00, //19 强抓力时间占用位
0x14, //20 放抓时间
0x32, //21 前后速度
0x32, //22 左右速度
0x50, //23 上下速度
0x9A, //24 放线长度
0x06, //25 放线长度占用位
0x00, //26 礼品下放高度
0x00, //27 礼品下放高度占用位
0x00, //28 甩抓长度
0x00, //29 甩抓保护
0x78, //30 甩抓电压
0x00, //31 甩抓电压占用位
0x32, //32 上拉保护
0x02, //33 天车自救时间
0x00, //34 下抓延时
0x00, //35 下抓延时占用位
0xC8, //36 抓物延时
0x00, //37 抓物延时占用位
0x96, //38 上停延时
0x00, //39 上停延时占用位
0x00, //40 摇杆延时
0x00, //41 摇杆延时占用位
0x00, //42 抓物二收
0x00, //43 待机音乐开关
0x00, //44 音量大小调整
0x07, //45 待机音乐选择
0x08, //46 游戏音乐选择
0x00, //47 概率队列自动
}