using Newtonsoft.Json; using Newtonsoft.Json.Converters; namespace AmrControl.Common { [JsonObject] public class MessagePacket { static int msgID = 1; /** * 消息ID,建议使用雪花或者uuid之类的唯一id * 若没有手动设置,消息发送端自动生成,大家想用string传值 */ //[JsonProperty(PropertyName = "newName")] //[JsonConverter(typeof(IntStringConverter))] public string id; /** * 终端id,连接时自定义,设备端建议同设备id,若工控机为主要控制端,即为工控机id */ public string clientId; /** * 设备id */ public string deviceId; /** * 消息体摘要,防止消息篡改 */ public string md5; /** * 加密算法,可为空,默认不加密 * 所有加密类型必须为软件维护的具体参见EncryptAlgEnum */ [JsonConverter(typeof(StringEnumConverter))] public EncryptAlgEnum encryptType; /** * 客户端类型 * 不作为传输使用 */ public byte clientType; /** * 源消息id,用于响应请求 */ public string sourceId; /** * 附带消息 */ public Dictionary attachments; /** * 发送时间 */ public DateTime sendTime; public MessagePacket() { id = msgID.ToString(); msgID = (msgID + 1) % int.MaxValue; clientId = "AmrManager"; attachments = new Dictionary(); sendTime = DateTime.Now; encryptType = EncryptAlgEnum.NOT; } } public enum EncryptAlgEnum : byte { /** * 不加密 */ NOT = 1, /** * aes对称加密算法 */ AES128 = 2, } //车辆控制相关 public class CallCarCmd : MessagePacket { /** * 小车id */ public string carId; /** * 小车类型;0-agv;1-amr */ public CarType type; /** * 目标位置 */ public Position destPos; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#msgType() */ public MessageType msgType; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#md5Str() */ public string md5Str; } public class StopCarCmd : MessagePacket { /** * 小车id */ public string carId; /** * 小车类型;0-agv;1-amr */ public CarType type; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#msgType() */ public MessageType msgType; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#md5Str() */ public string md5Str; } public class EnableCarCmd : MessagePacket { /** * 小车id */ public string carId; /** * 小车类型;0-agv;1-amr */ public CarType type; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#msgType() */ public MessageType msgType; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#md5Str() */ public string md5Str; } public class DisableCarCmd : MessagePacket { /** * 小车id */ public string carId; /** * 小车类型;0-agv;1-amr */ public CarType type; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#msgType() */ public MessageType msgType; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#md5Str() */ public string md5Str; } public class CarShowCmd : MessagePacket { /** * 小车id */ public string carId; /** * 小车类型;0-agv;1-amr */ public CarType type; /** * 通道id集合,2个字节,车上有两块屏 */ public byte[] channelIds; /** * 图片代码集合,二者长度必须一致,2个字节,车上有两块屏 */ public byte[] picCodes; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#msgType() */ public MessageType msgType; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#md5Str() */ public string md5Str; } [JsonObject] public class CarStateCmd : MessagePacket { //内部使用的一个id号,也算是车的地址,以0xfe01,0xfe02,0xfe03,0xfe04等地址 [JsonIgnore] internal int iCarID; /** * 小车id */ public string carId; /** * 小车类型;0-agv;1-amr */ public CarType type; /** * 电量 */ public string powerLevel; /** * 车辆状态; * 1-运动状态 * 2-停止状态 * 3-中断状态 * 4-故障状态 * 5-到位状态 */ public CarState state; /** * 当前是否载货, 默认false */ public bool loading; /** * 当前是否使能, 默认false */ public bool isEnable; /** * 速度;m/s */ public string speed; /** * 当前位置 */ public Position curPos; /** * 目标位置 */ public Position destPos; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#msgType() */ public MessageType msgType; /* (non-Javadoc) * @see com.jg.network.common.requests.ICmd#md5Str() */ public string md5Str; } public enum CarType : byte { AMR = 0, AGV = 1, } public enum MessageType : int { /** * ping 消息 */ MSG_TYPE_PING = 1, /** * pong 消息 */ MSG_TYPE_PONG = 10001, /** * 请求授权消息 */ MSG_TYPE_LOGIN = 2, /** * 小车上报状态信息 */ MSG_TYPE_CAR_REPORT = 3, /** * 呼叫小车 */ MSG_TYPE_CALL_CAR = 4, /** * 停止小车命令 */ MSG_TYPE_STOP_CAR = 5, /** * 小车使能 */ MSG_TYPE_ENABLE_CAR = 6, /** * 小车停止使能 */ MSG_TYPE_DISABLE_CAR = 7, /** * 机械臂状态上报 */ MSG_TYPE_ROBOT_STATE_REPORT = 8, /** * 通知小车展示图片 */ MSG_TYPE_CAR_SHOW = 9, //车上线 MSG_TYPE_CAR_Connected = 10, //车下线 MSG_TYPE_CAR_Disconnected = 11, //车到达 MSG_TYPE_CAR_Arrived = 12, /** * 登录返回消息类型 * 此处规定所有返回消息均为原请求消息的类型前面+1,消息保留4位防止正常消息不足 */ MSG_TYPE_LOGIN_RESULT = 10002, /** * 错误响应消息类型 */ MSG_TYPE_ERR_RESULT = -1, /** * 通用消息回执类型 */ MSG_TYPE_RETURN_RESULT = 0, /** * 停止小车后的回执消息 */ MSG_TYPE_CAR_STOP_RESULT = 10005, } public class Position { public int x; public int y; public int z; public string yaw; public Position(int x, int y, int z, string yaw) { this.x = x; this.y = y; this.z = z; this.yaw = yaw; } } public enum CarState : byte { //1-运动状态 Moving = 1, // * 2-停止状态 Stoped = 2, // * 3-中断状态,运行过程中被打断 Interrupt = 3, // * 4-故障状态 Error = 4, // * 5-到达状态 Arrived, } }