123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- 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<string, string> attachments;
- /**
- * 发送时间
- */
- public DateTime sendTime;
- public MessagePacket()
- {
- id = msgID.ToString();
- msgID = (msgID + 1) % int.MaxValue;
- clientId = "AmrManager";
- attachments = new Dictionary<string, string>();
- 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,
- }
- }
|