using System.Net.Sockets; using HybirdFrameworkCore.Utils; using log4net; namespace Service.Led; public class LedClient { #region msg public static Dictionary Dictionary = new Dictionary() { {"欢迎光临换电站!(正在营业)",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x22,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB9,0xE2,0xC1,0xD9,0xBB,0xBB,0xB5,0xE7,0xD5,0xBE,0xA3,0xA1,0x28,0xD5,0xFD,0xD4,0xDA,0xD3,0xAA,0xD2,0xB5,0x29,0x00,0x00,0x0D,0x0A,}}, {"标签读写失败",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB1,0xEA,0xC7,0xA9,0xB6,0xC1,0xD0,0xB4,0xCA,0xA7,0xB0,0xDC,0x00,0x00,0x0D,0x0A,}}, {"车辆连接失败",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB3,0xB5,0xC1,0xBE,0xC1,0xAC,0xBD,0xD3,0xCA,0xA7,0xB0,0xDC,0x00,0x00,0x0D,0x0A,}}, {"云端校验失败",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xD4,0xC6,0xB6,0xCB,0xD0,0xA3,0xD1,0xE9,0xCA,0xA7,0xB0,0xDC,0x00,0x00,0x0D,0x0A,}}, {"车辆已到位",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x12,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB3,0xB5,0xC1,0xBE,0xD2,0xD1,0xB5,0xBD,0xCE,0xBB,0x00,0x00,0x0D,0x0A,}}, {"请熄火挂空挡拉手刹",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xC7,0xEB,0xCF,0xA8,0xBB,0xF0,0xB9,0xD2,0xBF,0xD5,0xB5,0xB2,0xC0,0xAD,0xCA,0xD6,0xC9,0xB2,0x00,0x00,0x0D,0x0A,}}, {"云平台下发换电失败",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xD4,0xC6,0xC6,0xBD,0xCC,0xA8,0xCF,0xC2,0xB7,0xA2,0xBB,0xBB,0xB5,0xE7,0xCA,0xA7,0xB0,0xDC,0x00,0x00,0x0D,0x0A,}}, {"解锁车辆失败",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBD,0xE2,0xCB,0xF8,0xB3,0xB5,0xC1,0xBE,0xCA,0xA7,0xB0,0xDC,0x00,0x00,0x0D,0x0A,}}, {"选包失败,请驶离",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xD1,0xA1,0xB0,0xFC,0xCA,0xA7,0xB0,0xDC,0xA3,0xAC,0xC7,0xEB,0xCA,0xBB,0xC0,0xEB,0x00,0x00,0x0D,0x0A,}}, {"雷达定位失败,请在三分钟内重新调整车辆位置",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x32,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xC0,0xD7,0xB4,0xEF,0xB6,0xA8,0xCE,0xBB,0xCA,0xA7,0xB0,0xDC,0xA3,0xAC,0xC7,0xEB,0xD4,0xDA,0xC8,0xFD,0xB7,0xD6,0xD6,0xD3,0xC4,0xDA,0xD6,0xD8,0xD0,0xC1,0xBE,0xCE,0xBB,0xD6,0xC3,0x00,0x00,0x0D,0x0A,}}, {"电池拆卸中,请稍后",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB5,0xE7,0xB3,0xD8,0xB2,0xF0,0xD0,0xB6,0xD6,0xD0,0xA3,0xAC,0xC7,0xEB,0xC9,0xD4,0xBA,0xF3,0x00,0x00,0x0D,0x0A,}}, {"电池安装中,请稍后",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB5,0xE7,0xB3,0xD8,0xB0,0xB2,0xD7,0xB0,0xD6,0xD0,0xA3,0xAC,0xC7,0xEB,0xC9,0xD4,0xBA,0xF3,0x00,0x00,0x0D,0x0A,}}, {"电池包已安装完成",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB5,0xE7,0xB3,0xD8,0xB0,0xFC,0xD2,0xD1,0xB0,0xB2,0xD7,0xB0,0xCD,0xEA,0xB3,0xC9,0x00,0x00,0x0D,0x0A,}}, {"航车已回归安全位置",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBA,0xBD,0xB3,0xB5,0xD2,0xD1,0xBB,0xD8,0xB9,0xE9,0xB0,0xB2,0xC8,0xAB,0xCE,0xBB,0xD6,0xC3,0x00,0x00,0x0D,0x0A,}}, {"换电已完成,请驶离",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBB,0xBB,0xB5,0xE7,0xD2,0xD1,0xCD,0xEA,0xB3,0xC9,0xA3,0xAC,0xC7,0xEB,0xCA,0xBB,0xC0,0xEB,0x00,0x00,0x0D,0x0A,}}, {"换电失败,请驶离",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x18,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBB,0xBB,0xB5,0xE7,0xCA,0xA7,0xB0,0xDC,0xA3,0xAC,0xC7,0xEB,0xCA,0xBB,0xC0,0xEB,0x00,0x00,0x0D,0x0A,}}, {"电池入仓中,请稍后",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB5,0xE7,0xB3,0xD8,0xC8,0xEB,0xB2,0xD6,0xD6,0xD0,0xA3,0xAC,0xC7,0xEB,0xC9,0xD4,0xBA,0xF3,0x00,0x00,0x0D,0x0A,}}, {"电池出仓中,请稍后",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB5,0xE7,0xB3,0xD8,0xB3,0xF6,0xB2,0xD6,0xD6,0xD0,0xA3,0xAC,0xC7,0xEB,0xC9,0xD4,0xBA,0xF3,0x00,0x00,0x0D,0x0A,}}, {"车辆上锁失败",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB3,0xB5,0xC1,0xBE,0xC9,0xCF,0xCB,0xF8,0xCA,0xA7,0xB0,0xDC,0x00,0x00,0x0D,0x0A,}}, {"通道的电池仓无可用换电电池",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x22,0x00,0x00,0x00,0x22,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xCD,0xA8,0xB5,0xC0,0xB5,0xC4,0xB5,0xE7,0xB3,0xD8,0xB2,0xD6,0xCE,0xDE,0xBF,0xC9,0xD3,0xC3,0xBB,0xBB,0xB5,0xE7,0xB5,0xE7,0xB3,0xD8,0x00,0x00,0x0D,0x0A,}}, {"结束充电电池数量不足",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x00,0x1C,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBD,0xE1,0xCA,0xF8,0xB3,0xE4,0xB5,0xE7,0xB5,0xE7,0xB3,0xD8,0xCA,0xFD,0xC1,0xBF,0xB2,0xBB,0xD7,0xE3,0x00,0x00,0x0D,0x0A,}}, {"空仓数量不足",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBF,0xD5,0xB2,0xD6,0xCA,0xFD,0xC1,0xBF,0xB2,0xBB,0xD7,0xE3,0x00,0x00,0x0D,0x0A,}}, {"符合soc限制数量不足",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x00,0x00,0x00,0x1B,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB7,0xFB,0xBA,0xCF,0x73,0x6F,0x63,0xCF,0xDE,0xD6,0xC6,0xCA,0xFD,0xC1,0xBF,0xB2,0xBB,0xD7,0xE3,0x00,0x00,0x0D,0x0A,}}, {"结束充电大于3分钟的数量不足",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x23,0x00,0x00,0x00,0x23,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBD,0xE1,0xCA,0xF8,0xB3,0xE4,0xB5,0xE7,0xB4,0xF3,0xD3,0xDA,0x33,0xB7,0xD6,0xD6,0xD3,0xB5,0xC4,0xCA,0xFD,0xC1,0xBF,0xB2,0xBB,0xD7,0xE3,0x00,0x00,0x0D,0x0A,}}, {"换电站处于手动模式,不能自动换电",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x28,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBB,0xBB,0xB5,0xE7,0xD5,0xBE,0xB4,0xA6,0xD3,0xDA,0xCA,0xD6,0xB6,0xAF,0xC4,0xA3,0xCA,0xBD,0xA3,0xAC,0xB2,0xBB,0xC4,0xDC,0xD7,0xD4,0xB6,0xAF,0xBB,0xBB,0xB5,0xE7,0x00,0x00,0x0D,0x0A,}}, {"换电站处于本地模式,不能远程换电",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x28,0x00,0x00,0x00,0x28,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBB,0xBB,0xB5,0xE7,0xD5,0xBE,0xB4,0xA6,0xD3,0xDA,0xCA,0xD6,0xB6,0xAF,0xC4,0xA3,0xCA,0xBD,0xA3,0xAC,0xB2,0xBB,0xC4,0xDC,0xD7,0xD4,0xB6,0xAF,0xBB,0xBB,0xB5,0xE7,0x00,0x00,0x0D,0x0A,}}, {"车辆驶入",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB3,0xB5,0xC1,0xBE,0xCA,0xBB,0xC8,0xEB,0x00,0x00,0x0D,0x0A,}}, {"换电任务启动",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x14,0x00,0x00,0x00,0x14,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBB,0xBB,0xB5,0xE7,0xC8,0xCE,0xCE,0xF1,0xC6,0xF4,0xB6,0xAF,0x00,0x00,0x0D,0x0A,}}, {"雷达定位中,请稍后",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x1A,0x00,0x00,0x00,0x1A,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xC0,0xD7,0xB4,0xEF,0xB6,0xA8,0xCE,0xBB,0xD6,0xD0,0xA3,0xAC,0xC7,0xEB,0xC9,0xD4,0xBA,0xF3,0x00,0x00,0x0D,0x0A,}}, {"启动换电失败,请联系站务人员",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x24,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xC6,0xF4,0xB6,0xAF,0xBB,0xBB,0xB5,0xE7,0xCA,0xA7,0xB0,0xDC,0xA3,0xAC,0xC7,0xEB,0xC1,0xAA,0xCF,0xB5,0xD5,0xBE,0xCE,0xF1,0xC8,0xCB,0xD4,0xB1,0x00,0x00,0x0D,0x0A,}}, {"即将进行消防移仓,请车辆驶离",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x00,0x00,0x00,0x24,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xBC,0xB4,0xBD,0xAB,0xBD,0xF8,0xD0,0xD0,0xCF,0xFB,0xB7,0xC0,0xD2,0xC6,0xB2,0xD6,0xA3,0xAC,0xC7,0xEB,0xB3,0xB5,0xC1,0xBE,0xCA,0xBB,0xC0,0xEB,0x00,0x00,0x0D,0x0A,}}, {"电池移仓中",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x12,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xB5,0xE7,0xB3,0xD8,0xD2,0xC6,0xB2,0xD6,0xD6,0xD0,0x00,0x00,0x0D,0x0A,}}, {"消防移仓中",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x12,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xCF,0xFB,0xB7,0xC0,0xD2,0xC6,0xB2,0xD6,0xD6,0xD0,0x00,0x00,0x0D,0x0A,}}, {"雷达扫描失败,请在三分钟内挪车",new byte[]{0x55,0xAA,0x00,0x00,0x01,0x01,0x00,0xD9,0x00,0x00,0x00,0x00,0x00,0x00,0x26,0x00,0x00,0x00,0x26,0x00,0x25,0x64,0x69,0x73,0x70,0x30,0x3A,0x31,0xC0,0xD7,0xB4,0xEF,0xC9,0xA8,0xC3,0xE8,0xCA,0xA7,0xB0,0xDC,0xA3,0xAC,0xC7,0xEB,0xD4,0xDA,0xC8,0xFD,0xB7,0xD6,0xD6,0xD3,0xC4,0xDA,0xC5,0xB2,0xB3,0xB5,0x00,0x00,0x0D,0x0A,}}, }; #endregion private static readonly ILog Log = LogManager.GetLogger(typeof(LedClient)); private static Socket? _socket; private static string _ip; private static int _port; public static bool Init(string ip, int port) { _ip = ip; _port = port; Connect(); return _socket.Connected; } private static void Connect() { /*Log.Info($"begin connect {_ip}:{_port}"); _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _socket.NoDelay = true; _socket.Connect(_ip, _port); Log.Info($"end connect {_ip}:{_port} {_socket.Connected}");*/ } public static bool InnerSend(byte[] bytes) { Connect(); if (_socket?.Connected ?? true) { _socket?.Send(bytes); Log.Info($"send {BitUtls.BytesToHexStr(bytes)}"); _socket?.Close(); return true; } return false; } public static bool SendMsgByKey(string key) { Log.Info($"send by {key}"); if (Dictionary.TryGetValue(key, out var bytes)) { return InnerSend(bytes); } return false; } }