已重命名1个文件
已修改19个文件
已添加9个文件
| | |
| | | <!-- </dependency> --> |
| | | |
| | | |
| | | <!-- å¼å
¥IOå
--> |
| | | <dependency> |
| | | <groupId>com.ld.base.io</groupId> |
| | | <artifactId>base-io-netty</artifactId> |
| | | <version>1.0.0-SNAPSHOT</version> |
| | | </dependency> |
| | | |
| | | |
| | | <!-- mysqlè¿æ¥ --> |
| | | <dependency> |
| | | <groupId>mysql</groupId> |
| | |
| | | package com.fzzy.api.data; |
| | | |
| | | |
| | | import com.fzzy.api.entity.ApiTrigger; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ç½å
³ä¸è®¾å¤ç´æ¥çé讯åè®® |
| | | */ |
| | |
| | | DEVICE_IDCARD_HTTP("DEVICE_IDCARD_HTTP", "身份è¯-HTTPåè®®"), |
| | | DEVICE_LED_HTTP("DEVICE_LED_HTTP", "LED-HTTPåè®®"), |
| | | DEVICE_LPR_SDK_HK("DEVICE_LPR_SDK_HK", "车çè¯å«-SDK海康"), |
| | | DEVICE_TEST("DEVICE_TEST", "æµè¯åè®®"); |
| | | DEVICE_TEST("DEVICE_TEST", "空åè®®"); |
| | | |
| | | |
| | | private String code; |
| | | private String name; |
| | | |
| | | public static List<ApiTrigger> listTrigger() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(GRAIN_FZZY_ZH_2023.getCode(), GRAIN_FZZY_ZH_2023.getName())); |
| | | list.add(new ApiTrigger(DEVICE_WEIGHT_HTTP.getCode(), DEVICE_WEIGHT_HTTP.getName())); |
| | | list.add(new ApiTrigger(DEVICE_WEIGHT_TCP_YH.getCode(), DEVICE_WEIGHT_TCP_YH.getName())); |
| | | list.add(new ApiTrigger(DEVICE_IDCARD_HTTP.getCode(), DEVICE_IDCARD_HTTP.getName())); |
| | | list.add(new ApiTrigger(DEVICE_LED_HTTP.getCode(), DEVICE_LED_HTTP.getName())); |
| | | list.add(new ApiTrigger(DEVICE_LPR_SDK_HK.getCode(), DEVICE_LPR_SDK_HK.getName())); |
| | | list.add(new ApiTrigger(DEVICE_TEST.getCode(), DEVICE_TEST.getName())); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public String getCode() { |
| | | return code; |
| | |
| | | package com.fzzy.api.data; |
| | | |
| | | |
| | | import com.fzzy.api.entity.ApiTrigger; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ç½å
³è®¾å¤ç±»å |
| | | */ |
| | | public enum GatewayDeviceType { |
| | | |
| | | GRAIN_FZZY_ZH_2023("GRAIN_FZZY_ZH_2023", "ç²®æ
-飿£è´è¿æ§å¶æåè®®2023"), |
| | | DEVICE_WEIGHT_HTTP("DEVICE_WEIGHT_HTTP", "å°ç£
-HTTPåè®®"), |
| | | DEVICE_WEIGHT_TCP_YH("DEVICE_WEIGHT_TCP_YH", "å°ç£
-èåTCPåè®®"), |
| | | DEVICE_IDCARD_HTTP("DEVICE_IDCARD_HTTP", "身份è¯-HTTPåè®®"), |
| | | DEVICE_LED_HTTP("DEVICE_LED_HTTP", "LED-HTTPåè®®"), |
| | | DEVICE_LPR_SDK_HK("DEVICE_LPR_SDK_HK", "车çè¯å«-SDK海康"), |
| | | DEVICE_TEST("DEVICE_TEST", "æµè¯åè®®"); |
| | | TYPE_01("TYPE_01", "å°ç£
"), |
| | | TYPE_02("TYPE_02", "车çè¯å«"), |
| | | TYPE_03("TYPE_03", "éé¸"), |
| | | TYPE_04("TYPE_04", "LED"), |
| | | TYPE_05("TYPE_05", "æ¦æ ·æº"), |
| | | TYPE_06("TYPE_06", "æå头"), |
| | | TYPE_07("TYPE_07", "ç²®æ
åæº"), |
| | | TYPE_99("TYPE_99", "ç¬ç«IOT"); |
| | | |
| | | |
| | | private String code; |
| | | private String name; |
| | | |
| | | |
| | | public static List<ApiTrigger> listTrigger() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(TYPE_01.getCode(), TYPE_01.getName())); |
| | | list.add(new ApiTrigger(TYPE_02.getCode(), TYPE_02.getName())); |
| | | list.add(new ApiTrigger(TYPE_03.getCode(), TYPE_03.getName())); |
| | | list.add(new ApiTrigger(TYPE_04.getCode(), TYPE_04.getName())); |
| | | list.add(new ApiTrigger(TYPE_05.getCode(), TYPE_05.getName())); |
| | | list.add(new ApiTrigger(TYPE_06.getCode(), TYPE_06.getName())); |
| | | list.add(new ApiTrigger(TYPE_07.getCode(), TYPE_07.getName())); |
| | | list.add(new ApiTrigger(TYPE_99.getCode(), TYPE_99.getName())); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | |
| | | package com.fzzy.api.data; |
| | | |
| | | |
| | | import com.fzzy.api.entity.ApiTrigger; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ç³»ç»ä¸ç½å
³ä¹é´çé讯åè®® |
| | | */ |
| | |
| | | private String code; |
| | | private String name; |
| | | |
| | | public static List<ApiTrigger> listTrigger() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(GATE_WEBSOCKET.getCode(), GATE_WEBSOCKET.getName())); |
| | | list.add(new ApiTrigger(GATE_MQTT.getCode(), GATE_MQTT.getName())); |
| | | list.add(new ApiTrigger(GATE_HTTP.getCode(), GATE_HTTP.getName())); |
| | | list.add(new ApiTrigger(GATE_TEST.getCode(), GATE_TEST.getName())); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public String getCode() { |
| | | return code; |
| | |
| | | package com.fzzy.api.data; |
| | | |
| | | |
| | | import com.fzzy.api.entity.ApiTrigger; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Desc: ç³»ç»æ¯æå·²ç»å®ç°çåè®® |
| | | * @author: andy.jia |
| | |
| | | private String name; |
| | | |
| | | |
| | | public static List<ApiTrigger> listTrigger() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(GB_DEFAULT.getCode(), GB_DEFAULT.getName())); |
| | | list.add(new ApiTrigger(GB_2022.getCode(), GB_2022.getName())); |
| | | list.add(new ApiTrigger(SB_SH_2021.getCode(), SB_SH_2021.getName())); |
| | | list.add(new ApiTrigger(SB_GD_2022.getCode(), SB_GD_2022.getName())); |
| | | list.add(new ApiTrigger(SB_GD_2020.getCode(), SB_GD_2020.getName())); |
| | | list.add(new ApiTrigger(SB_HN_2022.getCode(), SB_HN_2022.getName())); |
| | | list.add(new ApiTrigger(SB_WHJL_2023.getCode(), SB_WHJL_2023.getName())); |
| | | list.add(new ApiTrigger(HB_FZZY_JG_2022.getCode(), HB_FZZY_JG_2022.getName())); |
| | | list.add(new ApiTrigger(SB_SHJdJW_2023.getCode(), SB_SHJdJW_2023.getName())); |
| | | list.add(new ApiTrigger(SB_SH_2023.getCode(), SB_SH_2023.getName())); |
| | | list.add(new ApiTrigger(GATEWAY_SC_2023.getCode(), GATEWAY_SC_2023.getName())); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | |
| | | package com.fzzy.api.data; |
| | | |
| | | |
| | | import com.fzzy.api.entity.ApiTrigger; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @Desc: ç³»ç»æ¯æç忥åè®® |
| | | * @author: andy.jia |
| | |
| | | private String name; |
| | | |
| | | |
| | | public static List<ApiTrigger> listTrigger() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(GB_DEFAULT.getCode(), GB_DEFAULT.getName())); |
| | | list.add(new ApiTrigger(FZZY_V30_GB.getCode(), FZZY_V30_GB.getName())); |
| | | list.add(new ApiTrigger(FZZY_V35_GB.getCode(), FZZY_V35_GB.getName())); |
| | | list.add(new ApiTrigger(FZZY_V40_GB.getCode(), FZZY_V40_GB.getName())); |
| | | list.add(new ApiTrigger(FZZY_V40_WHJL.getCode(), FZZY_V40_WHJL.getName())); |
| | | list.add(new ApiTrigger(FZZY_V35_SHYZ.getCode(), FZZY_V35_SHYZ.getName())); |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | |
| | | import com.bstek.dorado.annotation.DataProvider; |
| | | import com.bstek.dorado.annotation.Expose; |
| | | import com.fzzy.api.Constant; |
| | | import com.fzzy.api.data.GatewayDeviceProtocol; |
| | | import com.fzzy.api.data.GatewayProtocol; |
| | | import com.fzzy.api.data.PushProtocol; |
| | | import com.fzzy.api.data.SyncProtocol; |
| | | import com.fzzy.api.data.*; |
| | | import com.fzzy.api.entity.ApiTrigger; |
| | | import com.fzzy.api.utils.RedisConst; |
| | | import com.fzzy.api.utils.RedisUtil; |
| | |
| | | */ |
| | | @DataProvider |
| | | public List<ApiTrigger> triggerPushProtocol() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(PushProtocol.GB_DEFAULT.getCode(), PushProtocol.GB_DEFAULT.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.GB_2022.getCode(), PushProtocol.GB_2022.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_SH_2021.getCode(), PushProtocol.SB_SH_2021.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_SC_2021.getCode(), PushProtocol.SB_SC_2021.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_GD_2022.getCode(), PushProtocol.SB_GD_2022.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_GD_2020.getCode(), PushProtocol.SB_GD_2020.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_HN_2022.getCode(), PushProtocol.SB_HN_2022.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_WHJL_2023.getCode(), PushProtocol.SB_WHJL_2023.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.HB_FZZY_JG_2022.getCode(), PushProtocol.HB_FZZY_JG_2022.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_SHJdJW_2023.getCode(), PushProtocol.SB_SHJdJW_2023.getName())); |
| | | list.add(new ApiTrigger(PushProtocol.SB_SH_2023.getCode(), PushProtocol.SB_SH_2023.getName())); |
| | | |
| | | list.add(new ApiTrigger(PushProtocol.GATEWAY_SC_2023.getCode(), PushProtocol.GATEWAY_SC_2023.getName())); |
| | | return list; |
| | | return PushProtocol.listTrigger(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @DataProvider |
| | | public List<ApiTrigger> triggerSyncProtocol() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(SyncProtocol.GB_DEFAULT.getCode(), SyncProtocol.GB_DEFAULT.getName())); |
| | | list.add(new ApiTrigger(SyncProtocol.FZZY_V30_GB.getCode(), SyncProtocol.FZZY_V30_GB.getName())); |
| | | list.add(new ApiTrigger(SyncProtocol.FZZY_V35_GB.getCode(), SyncProtocol.FZZY_V35_GB.getName())); |
| | | list.add(new ApiTrigger(SyncProtocol.FZZY_V40_GB.getCode(), SyncProtocol.FZZY_V40_GB.getName())); |
| | | list.add(new ApiTrigger(SyncProtocol.FZZY_V40_WHJL.getCode(), SyncProtocol.FZZY_V40_WHJL.getName())); |
| | | list.add(new ApiTrigger(SyncProtocol.FZZY_V35_SHYZ.getCode(), SyncProtocol.FZZY_V35_SHYZ.getName())); |
| | | return list; |
| | | return SyncProtocol.listTrigger(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @DataProvider |
| | | public List<ApiTrigger> triggerGatewayProtocol() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(GatewayProtocol.GATE_HTTP.getCode(), GatewayProtocol.GATE_HTTP.getName())); |
| | | list.add(new ApiTrigger(GatewayProtocol.GATE_MQTT.getCode(), GatewayProtocol.GATE_MQTT.getName())); |
| | | list.add(new ApiTrigger(GatewayProtocol.GATE_WEBSOCKET.getCode(), GatewayProtocol.GATE_WEBSOCKET.getName())); |
| | | list.add(new ApiTrigger(GatewayProtocol.GATE_TEST.getName(), GatewayProtocol.GATE_TEST.getName())); |
| | | return list; |
| | | return GatewayProtocol.listTrigger(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @DataProvider |
| | | public List<ApiTrigger> triggerGatewayDeviceProtocol() { |
| | | List<ApiTrigger> list = new ArrayList<>(); |
| | | list.add(new ApiTrigger(GatewayDeviceProtocol.GRAIN_FZZY_ZH_2023.getCode(), GatewayDeviceProtocol.GRAIN_FZZY_ZH_2023.getName())); |
| | | return GatewayDeviceProtocol.listTrigger(); |
| | | } |
| | | |
| | | list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_WEIGHT_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_WEIGHT_HTTP.getName())); |
| | | list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_IDCARD_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_IDCARD_HTTP.getName())); |
| | | list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_LED_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_LED_HTTP.getName())); |
| | | list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_LPR_HTTP.getCode(), GatewayDeviceProtocol.DEVICE_LPR_HTTP.getName())); |
| | | list.add(new ApiTrigger(GatewayDeviceProtocol.DEVICE_TEST.getCode(), GatewayDeviceProtocol.DEVICE_TEST.getName())); |
| | | |
| | | return list; |
| | | /** |
| | | * ${dorado.getDataProvider("apiTriggerService#triggerGatewayDeviceType").getResult()} |
| | | * ç³»ç»ä¸ç½å
³ç´æ¥çé讯åè®® |
| | | * |
| | | * @return |
| | | */ |
| | | @DataProvider |
| | | public List<ApiTrigger> triggerGatewayDeviceType() { |
| | | return GatewayDeviceType.listTrigger(); |
| | | } |
| | | |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.api.utils; |
| | | |
| | | import java.math.BigInteger; |
| | | |
| | | public class BytesUtil { |
| | | |
| | | /** |
| | | * bytesè¾åºåè¿å¶ |
| | | * |
| | | * @param bytes |
| | | * @return |
| | | */ |
| | | public static Integer bytesToInt(byte[] bytes) { |
| | | String str = ""; |
| | | int i = 0; |
| | | boolean flag = true && bytes.length > 0; |
| | | while (flag) { |
| | | Byte b = bytes[i]; |
| | | i++; |
| | | Integer bi = Byte.toUnsignedInt(b); |
| | | str += toHexString(bi); |
| | | if (i >= bytes.length || str.endsWith("EEEE")) |
| | | flag = false; |
| | | } |
| | | return Integer.parseInt(str, 16); |
| | | } |
| | | |
| | | /** |
| | | * bytesè¾åºåå
è¿å¶å符串 |
| | | * |
| | | * @param bytes |
| | | * @return |
| | | */ |
| | | public static String bytesToString(byte[] bytes) { |
| | | String str = ""; |
| | | int i = 0; |
| | | boolean flag = true && bytes.length > 0; |
| | | while (flag) { |
| | | Byte b = bytes[i]; |
| | | i++; |
| | | Integer bi = Byte.toUnsignedInt(b); |
| | | str += toHexString(bi); |
| | | if (i >= bytes.length) |
| | | flag = false; |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | /** |
| | | * åå
è¿å¶è½¬åè |
| | | * |
| | | * @param hex |
| | | * @return |
| | | */ |
| | | public static byte hexToByte(Integer hex) { |
| | | return hex.byteValue(); |
| | | } |
| | | |
| | | /** |
| | | * short转2åè å·²è°æ´é«ä½ä½ |
| | | * |
| | | * @param number |
| | | * @return |
| | | */ |
| | | public static byte[] shortToByte(short number) { |
| | | int temp = number; |
| | | byte[] b = new byte[2]; |
| | | for (int i = 0; i < b.length; i++) { |
| | | b[i] = new Integer(temp & 0xff).byteValue();// å°æä½ä½ä¿å卿ä½ä½ |
| | | temp = temp >> 8; // åå³ç§»8ä½ |
| | | } |
| | | return b; |
| | | } |
| | | |
| | | /** |
| | | * äºè¿å¶å串转16è¿å¶å串 |
| | | * |
| | | * @param bin |
| | | * @return |
| | | */ |
| | | public static String binToHex(String bin) { |
| | | String hexStr = ""; |
| | | int size = bin.length() / 8; |
| | | for (int i = 0; i < size; i++) { |
| | | String value = bin.substring(i * 8, (i + 1) * 8); |
| | | int temp = Integer.parseInt(value, 2); |
| | | String tempHex = Integer.toHexString(temp); |
| | | hexStr += tempHex; |
| | | } |
| | | return hexStr; |
| | | } |
| | | |
| | | /** |
| | | * äºè¿å¶è½¬16è¿å¶ï¼ä¸è¶³2ä½è¡¥ä½ |
| | | * |
| | | * @param bin |
| | | * @return |
| | | */ |
| | | public static String bin2Hex(String bin) { |
| | | String hexStr = ""; |
| | | int size = bin.length() / 8; |
| | | for (int i = 0; i < size; i++) { |
| | | String value = bin.substring(i * 8, (i + 1) * 8); |
| | | int temp = Integer.parseInt(value, 2); |
| | | String tempHex = Integer.toHexString(temp); |
| | | if (tempHex.length() < 2) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | hexStr += tempHex; |
| | | } |
| | | |
| | | return hexStr; |
| | | } |
| | | |
| | | /** |
| | | * 转为åå
è¿å¶ä¸²ï¼ä¸è¶³2ä½è¡¥0 |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static String toHexString(int value) { |
| | | String tempHex = Integer.toHexString(value); |
| | | if (tempHex.length() < 2) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | return tempHex.toUpperCase(); |
| | | } |
| | | |
| | | public static String getTargetId(String value, boolean isTwo) { |
| | | String tempHex = Integer.toHexString(Integer.valueOf(value)); |
| | | if (tempHex.length() < 2) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | if (isTwo) { |
| | | if (tempHex.length() < 4) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | if (tempHex.length() < 4) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | } |
| | | return tempHex.toUpperCase(); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®æ°å¼è·åå°é¿åº¦ä¸º2åèç16è¿å¶å符 |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static String getHex2LenStr(int value) { |
| | | String tempHex = Integer.toHexString(value); |
| | | if (tempHex.length() < 2) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | if (tempHex.length() < 4) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | if (tempHex.length() < 4) { |
| | | tempHex = "0" + tempHex; |
| | | } |
| | | return tempHex.toUpperCase(); |
| | | } |
| | | |
| | | public static String getOrderId(int value) { |
| | | return getHex2LenStr(value); |
| | | } |
| | | |
| | | /** |
| | | * å°value转为same个ç¸å满8ä½çäºè¿å¶å串 |
| | | * |
| | | * @param value |
| | | * @param same |
| | | * @return |
| | | */ |
| | | public static String toBinary8StringSame(int value, int same) { |
| | | String tempBinStr = toBinary8String(value); |
| | | String rsBinStr = ""; |
| | | for (int i = 0; i < same; i++) { |
| | | rsBinStr += tempBinStr; |
| | | } |
| | | return rsBinStr; |
| | | } |
| | | |
| | | /** |
| | | * ä¸è¶³width个åè宽度æ¶ï¼åé¢è¡¥0è³width*8 |
| | | * |
| | | * @param value |
| | | * @param width |
| | | * @return |
| | | */ |
| | | public static String toBinary8String(int value, int width) { |
| | | String tempBinStr = toBinary8String(value); |
| | | int size = tempBinStr.length(); |
| | | for (int i = 0; i < width; i++) { |
| | | int temp = (i + 1) * 8; |
| | | if (temp > size) { |
| | | tempBinStr = "00000000" + tempBinStr; |
| | | size = tempBinStr.length(); |
| | | } |
| | | } |
| | | return tempBinStr; |
| | | } |
| | | |
| | | /** |
| | | * 补足8ä½ |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static String toBinary8String(int value) { |
| | | String temp = Integer.toBinaryString(value); |
| | | if (value == 0) { |
| | | temp = "00000000"; |
| | | } |
| | | int length = temp.length(); |
| | | while (length < 8) { |
| | | temp = "0" + temp; |
| | | length = temp.length(); |
| | | } |
| | | return temp; |
| | | } |
| | | |
| | | public static String toEmptyBinaryWidthString(int width) { |
| | | String str = ""; |
| | | for (int i = 0; i < width; i++) { |
| | | str += "00000000"; |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | public static byte[] emptyBytes(int bytes) { |
| | | byte[] bys = new byte[bytes]; |
| | | for (int i = 0; i < bytes; i++) { |
| | | bys[i] = emptyByte(); |
| | | } |
| | | return bys; |
| | | } |
| | | |
| | | public static byte emptyByte() { |
| | | Integer b0 = 0x00; |
| | | return b0.byteValue(); |
| | | } |
| | | |
| | | public static byte binToBytes(String bin) { |
| | | return Integer.valueOf(bin, 2).byteValue(); |
| | | } |
| | | |
| | | public static byte[] binaryStrToBytes(String binStr) { |
| | | int size = binStr.length() / 8; |
| | | byte[] bs = new byte[size]; |
| | | for (int i = 0; i < size; i++) { |
| | | String temp = binStr.substring(i * 8, (i + 1) * 8); |
| | | bs[i] = Integer.valueOf(temp, 2).byteValue(); |
| | | } |
| | | return bs; |
| | | } |
| | | |
| | | /** |
| | | * åå
è¿å¶ä¸²è½¬åèæ°ç» |
| | | * |
| | | * @param hexStr |
| | | * @return |
| | | */ |
| | | public static byte[] hexStrToBytes(String hexStr) { |
| | | int size = hexStr.length() / 2; |
| | | byte[] bytes = new byte[size]; |
| | | for (int i = 0; i < size; i++) { |
| | | String tmp = hexStr.substring(i * 2, (i + 1) * 2); |
| | | Integer tmpHex = Integer.parseInt(tmp, 16); |
| | | bytes[i] = tmpHex.byteValue(); |
| | | } |
| | | return bytes; |
| | | } |
| | | |
| | | /** |
| | | * 两åèé«ä½ä½è£
æ¢ |
| | | * |
| | | * @param b |
| | | * @return |
| | | */ |
| | | public static byte[] hexHeightLow(byte[] b) { |
| | | byte[] b2 = new byte[2]; |
| | | // 转æ¢é«ä½ä½ |
| | | b2[0] = b[1]; |
| | | b2[1] = b[0]; |
| | | return b2; |
| | | } |
| | | |
| | | /** |
| | | * 16è¿å¶è½¬æ¢ä¸º10è¿å¶ |
| | | * |
| | | * @param strHex |
| | | * @return |
| | | */ |
| | | public static int hexToInt(String strHex) { |
| | | short s = (short) (Integer.valueOf(strHex, 16) & 0xffff); |
| | | return s; |
| | | } |
| | | |
| | | /** |
| | | * 16è¿å¶è½¬æ¢ä¸º10è¿å¶ |
| | | * |
| | | * @param strHex |
| | | * @return |
| | | */ |
| | | public static int hexToBigInt(String strHex) { |
| | | BigInteger bigint = new BigInteger(strHex, 16); |
| | | return bigint.intValue(); |
| | | } |
| | | |
| | | /** |
| | | * int转16è¿å¶å符串 2ä½ 00 00 |
| | | * |
| | | * @param num |
| | | * @return |
| | | */ |
| | | public static String intToHexStr(int num) { |
| | | // éè¦ä½¿ç¨2åè表示b |
| | | return String.format("%04x", num).toUpperCase(); |
| | | } |
| | | |
| | | // 计ç®16è¿å¶å¯¹åºçæ°å¼ |
| | | public static int GetHex(char ch) throws Exception { |
| | | if (ch >= '0' && ch <= '9') |
| | | return (int) (ch - '0'); |
| | | if (ch >= 'a' && ch <= 'f') |
| | | return (int) (ch - 'a' + 10); |
| | | if (ch >= 'A' && ch <= 'F') |
| | | return (int) (ch - 'A' + 10); |
| | | throw new Exception("error param"); |
| | | } |
| | | |
| | | // 计ç®å¹ |
| | | public static int GetPower(int nValue, int nCount) throws Exception { |
| | | if (nCount < 0) |
| | | throw new Exception("nCount can't small than 1!"); |
| | | if (nCount == 0) |
| | | return 1; |
| | | int nSum = 1; |
| | | for (int i = 0; i < nCount; ++i) { |
| | | nSum = nSum * nValue; |
| | | } |
| | | return nSum; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | |
| | | double d1 = hexToBigInt("000906EB")/100.0; |
| | | double d2 = hexToBigInt("0004F6E6")/100.0; |
| | | |
| | | System.out.println(d1); |
| | | System.out.println(d2); |
| | | |
| | | System.out.println(d1 + d2); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 16è¿å¶å符串 é«ä½æ¢ä½ |
| | | * |
| | | * @param info |
| | | * @return |
| | | */ |
| | | public static String tran_LH(String info) { |
| | | return info.substring(2) + info.substring(0, 2); |
| | | } |
| | | |
| | | /** |
| | | * 16è¿å¶å符串 é«ä½æ¢ä½ 8个å符 |
| | | * |
| | | * @param info |
| | | * @return |
| | | */ |
| | | public static String tran_LH8(String info) { |
| | | return tran_LH(info.substring(4)) + tran_LH(info.substring(0, 4)); |
| | | } |
| | | |
| | | /** |
| | | * å° 4åèç16è¿å¶å符串ï¼è½¬æ¢ä¸º32ä½å¸¦ç¬¦å·çåè¿å¶æµ®ç¹å |
| | | * |
| | | * 42c60000 -> 99.00 |
| | | * |
| | | * @param str |
| | | * 4åè 16è¿å¶å符 |
| | | * @return |
| | | */ |
| | | public static float hexToFloat(String str) { |
| | | return Float.intBitsToFloat(new BigInteger(str, 16).intValue()); |
| | | } |
| | | |
| | | /** |
| | | * å°å¸¦ç¬¦å·ç32使µ®ç¹æ°è£
æ¢ä¸º16è¿å¶ |
| | | * |
| | | * 99.00 -> 42c60000 |
| | | * |
| | | * |
| | | * @param value |
| | | * @return |
| | | */ |
| | | public static String folatToHexString(Float value) { |
| | | return Integer.toHexString(Float.floatToIntBits(value)); |
| | | } |
| | | } |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * çæTCPè¿æ¥çKEY |
| | | * |
| | | * @param ip |
| | | * @param port |
| | | * @return |
| | | */ |
| | | public static String getServerKey(String ip, Integer port) { |
| | | return ip + ":" + port; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.api.utils; |
| | | |
| | | import org.springframework.beans.BeansException; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ApplicationContextAware; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component |
| | | public class SpringUtil implements ApplicationContextAware { |
| | | |
| | | private static ApplicationContext applicationContext; |
| | | |
| | | @Override |
| | | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
| | | if (SpringUtil.applicationContext == null) { |
| | | SpringUtil.applicationContext = applicationContext; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·åapplicationContext |
| | | * @return |
| | | */ |
| | | public static ApplicationContext getApplicationContext() { |
| | | return applicationContext; |
| | | } |
| | | |
| | | /** |
| | | * éè¿nameè·å Bean. |
| | | * @param name |
| | | * @return |
| | | */ |
| | | public static Object getBean(String name) { |
| | | return getApplicationContext().getBean(name); |
| | | } |
| | | |
| | | /** |
| | | * éè¿classè·åBean. |
| | | * @param clazz |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | public static <T> T getBean(Class<T> clazz) { |
| | | return getApplicationContext().getBean(clazz); |
| | | } |
| | | |
| | | /** |
| | | * éè¿name,以åClazzè¿åæå®çBean |
| | | * @param name |
| | | * @param clazz |
| | | * @param <T> |
| | | * @return |
| | | */ |
| | | public static <T> T getBean(String name, Class<T> clazz) { |
| | | return getApplicationContext().getBean(name, clazz); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | //åå·ç½å
³æ¥å£ï¼å¯å¨é»è®¤è·åé´æä¿¡æ¯ï¼é¿æææ |
| | | apiInitService.init(); |
| | | |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.gateway; |
| | | |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 常é |
| | | */ |
| | | public class GatewayUtils { |
| | | |
| | | |
| | | |
| | | /** |
| | | * 设å¤å¨çº¿æ è®°ï¼é对WEBSocket请æ±ï¼æ§å¶è®¾å¤æ¯å¦å¨çº¿ï¼key = deviceIdï¼Value=Y/N |
| | | */ |
| | | public static Map<String, String> contextOnlineMap = new HashMap<>(); |
| | | |
| | | |
| | | /** |
| | | * 设å¤ç¼å |
| | | */ |
| | | public static Map<String, GatewayDevice> cacheMapDeviceId = new HashMap<>(); |
| | | |
| | | /** |
| | | * 设å¤ç¼å |
| | | */ |
| | | public static Map<String, GatewayDevice> cacheMapDeviceSn = new HashMap<>(); |
| | | |
| | | |
| | | public static void add2Cache(GatewayDevice device) { |
| | | cacheMapDeviceId.put(device.getDeviceId(), device); |
| | | cacheMapDeviceSn.put(device.getDeviceSn(), device); |
| | | } |
| | | |
| | | public static GatewayDevice getCacheByDeviceId(String deviceId) { |
| | | return cacheMapDeviceId.get(deviceId); |
| | | } |
| | | |
| | | public static GatewayDevice getCacheByDeviceSn(String deviceSn) { |
| | | return cacheMapDeviceSn.get(deviceSn); |
| | | } |
| | | |
| | | |
| | | public static void removeCache(GatewayDevice data) { |
| | | cacheMapDeviceId.remove(data.getDeviceId()); |
| | | cacheMapDeviceSn.remove(data.getDeviceSn()); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void updateOnline(String deviceId) { |
| | | contextOnlineMap.put(deviceId, "Y"); |
| | | } |
| | | |
| | | public static void updateOffOnline(String deviceId) { |
| | | contextOnlineMap.put(deviceId, "N"); |
| | | } |
| | | |
| | | public static boolean isOnline(String deviceId) { |
| | | String value = contextOnlineMap.get(deviceId); |
| | | if (null == value || "N".equals(value)) return false; |
| | | return true; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.gateway.api; |
| | | |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | |
| | | |
| | | public interface DeviceReportService { |
| | | |
| | | /** |
| | | * åè®®å®ä¹ |
| | | * |
| | | * @return |
| | | */ |
| | | String getProvinceProtocol(); |
| | | |
| | | |
| | | /** |
| | | * éè¿è®¾å¤åºåå·è¿åç»æä¿¡æ¯ |
| | | * |
| | | * @param weigh |
| | | * @param device 设å¤åºåå· |
| | | */ |
| | | String report2GatewayBySn(double weigh, GatewayDevice device); |
| | | |
| | | } |
| | |
| | | |
| | | public static Map<String, GatewayRemoteService> remoteMap = new HashMap<>(); |
| | | |
| | | public static Map<String, DeviceReportService> reportMap = new HashMap<>(); |
| | | |
| | | public static Map<String, GatewaySyncGranService> syncGrain = new HashMap<>(); |
| | | |
| | | public static Map<String, GatewaySyncIdCardService> syncIdCard = new HashMap<>(); |
| | |
| | | Map<String, GatewaySyncWeightService> serviceMap6 = applicationContext.getBeansOfType(GatewaySyncWeightService.class); |
| | | for (String key : serviceMap6.keySet()) { |
| | | syncWeight.put(serviceMap6.get(key).getWeightProtocol(), serviceMap6.get(key)); |
| | | } |
| | | |
| | | Map<String, DeviceReportService> serviceMap7 = applicationContext.getBeansOfType(DeviceReportService.class); |
| | | for (String key : serviceMap7.keySet()) { |
| | | reportMap.put(serviceMap7.get(key).getProvinceProtocol(), serviceMap7.get(key)); |
| | | } |
| | | } |
| | | |
| | |
| | | return syncWeight.get(protocol); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®å®ç°åè®®è·åå½åå®ç°æ¹æ³ |
| | | * |
| | | * @param protocol |
| | | * @return |
| | | */ |
| | | public DeviceReportService getDeviceReportService(String protocol) { |
| | | return reportMap.get(protocol); |
| | | } |
| | | |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | public WeightInfo syncWeightInfo(SyncReqData reqData); |
| | | |
| | | } |
| | |
| | | package com.fzzy.gateway.entity; |
| | | |
| | | import com.bstek.dorado.annotation.PropertyDef; |
| | | |
| | | import lombok.Data; |
| | | |
| | | import javax.persistence.*; |
| | | |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | |
| | | @PropertyDef(label = "设å¤åºåå·") |
| | | private String deviceSn; |
| | | |
| | | @Column(name = "DEVICE_ID_", length = 100) |
| | | @Column(name = "DEVICE_ID_", length = 50) |
| | | @PropertyDef(label = "设å¤ID") |
| | | private String deviceId; |
| | | |
| | |
| | | @PropertyDef(label = "é讯端å£") |
| | | private Integer port; |
| | | |
| | | @PropertyDef(label = "设å¤ç¨æ·å") |
| | | @Column(name = "username", length = 50) |
| | | private String userName; |
| | | |
| | | @PropertyDef(label = "设å¤å¯ç ") |
| | | @Column(name = "password", length = 50) |
| | | private String password; |
| | | |
| | | @Column(name = "RTSP_", length = 100) |
| | | @PropertyDef(label = "è§é¢RTSP", description = "ç¨äºå±åç½å
ææé
ç½®") |
| | | private String rtsp; |
| | |
| | | @Column(name = "PUSH_PROTOCOL_", length = 20) |
| | | private String pushProtocol; |
| | | |
| | | @PropertyDef(label = "çå¹³å°åè®®") |
| | | @Column(name = "PROVINCE_PROTOCOL_", length = 20) |
| | | private String provinceProtocol; |
| | | |
| | | @PropertyDef(label = "忥åè®®") |
| | | @Column(name = "SYNC_PROTOCOL_", length = 20) |
| | | private String syncProtocol; |
| | |
| | | package com.fzzy.gateway.hx2023; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 常é |
| | | */ |
| | |
| | | |
| | | public static String API_URL_AUTH = "${auth}/authorize/login"; |
| | | |
| | | |
| | | /** |
| | | * 设å¤å¨çº¿æ è®°ï¼é对WEBSocket请æ±ï¼æ§å¶è®¾å¤æ¯å¦å¨çº¿ï¼key = deviceIdï¼Value=Y/N |
| | | */ |
| | | public static Map<String, String> contextOnlineMap = new HashMap<>(); |
| | | |
| | | |
| | | public static void updateOnline(String deviceId) { |
| | | contextOnlineMap.put(deviceId, "Y"); |
| | | } |
| | | |
| | | public static void updateOffOnline(String deviceId) { |
| | | contextOnlineMap.put(deviceId, "N"); |
| | | } |
| | | |
| | | public static boolean isOnline(String deviceId) { |
| | | String value = contextOnlineMap.get(deviceId); |
| | | if (null == value || "N".equals(value)) return false; |
| | | return true; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | private String productId; |
| | | |
| | | private String keepOnlineTimeoutSeconds; |
| | | private int keepOnlineTimeoutSeconds = 600 ; |
| | | |
| | | private String keepOnline; |
| | | private boolean keepOnline = true; |
| | | |
| | | private String deviceName; |
| | | |
| | | private String orgId; |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.gateway.hx2023.service; |
| | | |
| | | import com.fzzy.api.data.GatewayProtocol; |
| | | import com.fzzy.api.data.PushProtocol; |
| | | import com.fzzy.gateway.api.DeviceReportService; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.data.WebSocketPacket; |
| | | import com.fzzy.gateway.hx2023.data.WebSocketPacketHeader; |
| | | import com.fzzy.gateway.hx2023.websocket.WebSocketDeviceReport; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class DeviceReportServiceImpl implements DeviceReportService { |
| | | |
| | | |
| | | @Resource |
| | | private WebSocketDeviceReport webSocketDeviceReport; |
| | | |
| | | @Override |
| | | public String getProvinceProtocol() { |
| | | return PushProtocol.GATEWAY_SC_2023.getCode(); |
| | | } |
| | | |
| | | @Override |
| | | public String report2GatewayBySn(double weigh, GatewayDevice device) { |
| | | |
| | | if (null == device) { |
| | | log.error("-----------没æè·åå°è®¾å¤é
置信æ¯-----"); |
| | | return "ERROR:没æè·åå°è®¾å¤é
置信æ¯"; |
| | | } |
| | | |
| | | //使ç¨WEBSOCKETè¿å |
| | | if (GatewayProtocol.GATE_WEBSOCKET.equals(device.getPushProtocol())) { |
| | | |
| | | WebSocketPacket packet = new WebSocketPacket(); |
| | | |
| | | WebSocketPacketHeader header = new WebSocketPacketHeader(); |
| | | header.setDeviceName(device.getDeviceName()); |
| | | packet.setHeaders(header); |
| | | packet.setMessageType(""); |
| | | packet.setDeviceId(device.getDeviceId()); |
| | | packet.setProperties(null); |
| | | packet.setTimestamp(System.currentTimeMillis()); |
| | | |
| | | |
| | | webSocketDeviceReport.sendByPacket(packet); |
| | | |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | } |
| | |
| | | package com.fzzy.gateway.hx2023.service; |
| | | |
| | | import com.fzzy.api.data.GatewayDeviceProtocol; |
| | | import com.fzzy.gateway.api.GatewaySyncLprService; |
| | | import com.fzzy.api.data.GatewayProtocol; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.gateway.api.GatewaySyncWeightService; |
| | | import com.fzzy.gateway.hx2023.data.LprData; |
| | | import com.fzzy.gateway.hx2023.data.SyncReqData; |
| | | import com.fzzy.gateway.hx2023.data.WeightInfo; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.data.*; |
| | | import com.fzzy.gateway.hx2023.websocket.WebSocketDeviceReport; |
| | | import com.fzzy.gateway.service.GatewayDeviceService; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * ç½å
³ä¸è®¾å¤ä¹é´çé讯 |
| | |
| | | public class HxGatewaySyncWeightImpl1 implements GatewaySyncWeightService { |
| | | |
| | | |
| | | @Resource |
| | | private GatewayDeviceService deviceService; |
| | | @Resource |
| | | private WebSocketDeviceReport webSocketDeviceReport; |
| | | |
| | | |
| | | @Override |
| | | public String getWeightProtocol() { |
| | | return GatewayDeviceProtocol.DEVICE_WEIGHT_TCP_YH.getCode(); |
| | |
| | | @Override |
| | | public WeightInfo syncWeightInfo(SyncReqData reqData) { |
| | | |
| | | //doNothing |
| | | return null; |
| | | } |
| | | |
| | |
| | | package com.fzzy.gateway.hx2023.websocket; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.hx2023.data.WebSocketPacket; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang.StringUtils; |
| | |
| | | sessionPool.put(key, session); |
| | | sessionIds.put(session.getId(), key); |
| | | |
| | | ScConstant.updateOnline(deviceId); |
| | | GatewayUtils.updateOnline(deviceId); |
| | | |
| | | log.info("new webSocket,clientId={}", key); |
| | | } |
| | |
| | | |
| | | String deviceId = key.substring(0, key.indexOf("-")); |
| | | |
| | | ScConstant.updateOffOnline(deviceId); |
| | | GatewayUtils.updateOffOnline(deviceId); |
| | | |
| | | log.info("WebSocketè¿æ¥å
³é={}", key); |
| | | |
| | |
| | | |
| | | String deviceId = key.substring(0, key.indexOf("-")); |
| | | |
| | | ScConstant.updateOffOnline(deviceId); |
| | | GatewayUtils.updateOffOnline(deviceId); |
| | | |
| | | sessionPool.remove(key); |
| | | sessionIds.remove(session.getId()); |
ÎļþÃû´Ó src/main/java/com/fzzy/gateway/hx2023/websocket/WebSocketDevice.java ÐÞ¸Ä |
| | |
| | | package com.fzzy.gateway.hx2023.websocket; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.WebSocketPacket; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @Slf4j |
| | | @Component |
| | | @ServerEndpoint(value = "/device/{productId}/{deviceId}/message/property/report") |
| | | public class WebSocketDevice { |
| | | public class WebSocketDeviceReport { |
| | | |
| | | private static Map<String, Session> sessionPool = new ConcurrentHashMap<>(); |
| | | private static Map<String, String> sessionIds = new ConcurrentHashMap<>(); |
| | |
| | | sessionPool.put(key, session); |
| | | sessionIds.put(session.getId(), key); |
| | | |
| | | ScConstant.updateOnline(deviceId); |
| | | GatewayUtils.updateOnline(deviceId); |
| | | |
| | | log.info("new webSocket,clientId={}", key); |
| | | } |
| | |
| | | |
| | | String key = sessionIds.get(session.getId()); |
| | | |
| | | String deviceId = key.substring(0, key.indexOf("-")); |
| | | String deviceId = key.substring(key.indexOf("-")); |
| | | |
| | | ScConstant.updateOffOnline(deviceId); |
| | | GatewayUtils.updateOffOnline(deviceId); |
| | | |
| | | sessionPool.remove(key); |
| | | sessionIds.remove(session.getId()); |
| | |
| | | |
| | | String key = sessionIds.get(session.getId()); |
| | | |
| | | String deviceId = key.substring(0, key.indexOf("-")); |
| | | String deviceId = key.substring(key.indexOf("-")); |
| | | |
| | | ScConstant.updateOffOnline(deviceId); |
| | | GatewayUtils.updateOffOnline(deviceId); |
| | | |
| | | sessionPool.remove(key); |
| | | sessionIds.remove(session.getId()); |
| | |
| | | * |
| | | * @param packet |
| | | */ |
| | | public static void sendByPacket(WebSocketPacket packet) { |
| | | public void sendByPacket(WebSocketPacket packet) { |
| | | if (StringUtils.isEmpty(packet.getDeviceId())) { |
| | | log.error("WebSocketä¿¡æ¯æ¨é失败ï¼è®¾å¤ç¼ç 为空ã"); |
| | | return; |
| | | } |
| | | |
| | | |
| | | String tag = packet.getDeviceId(); |
| | | |
| | | // é忍é |
| | | Session session; |
| | | String productId; |
| | | for (String key : sessionPool.keySet()) { |
| | | |
| | | productId = key.substring(0, key.indexOf("-")); |
| | | |
| | | packet.getHeaders().setProductId(productId); |
| | | |
| | | if (key.indexOf(tag) != -1) { |
| | | session = sessionPool.get(key); |
| | | session.getAsyncRemote().sendText( |
| | |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.api.utils.RedisConst; |
| | | import com.fzzy.api.utils.RedisUtil; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.service.repository.GatewayDeviceRep; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class GatewayDeviceService { |
| | | |
| | | @Resource |
| | | private GatewayDeviceRep gatewayDeviceRep; |
| | | @Resource |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | /** |
| | | * gatewayDeviceService#listAll |
| | |
| | | */ |
| | | @DataProvider |
| | | public List<GatewayDevice> listAll() { |
| | | |
| | | List<GatewayDevice> list = gatewayDeviceRep.findAll(); |
| | | |
| | | return list; |
| | | return gatewayDeviceRep.findAll(); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | if (null == data.getId()) { |
| | | data.setId(ContextUtil.getUUID()); |
| | | } |
| | | |
| | | |
| | | if (null == data.getDeviceSn()) { |
| | | if (null != entity.getIp()) { |
| | | data.setDeviceSn(entity.getIp()); |
| | | } else { |
| | | data.setDeviceSn(data.getDeviceId()); |
| | | } |
| | | } |
| | | |
| | | gatewayDeviceRep.save(data); |
| | |
| | | BeanUtils.copyProperties(data, data2); |
| | | gatewayDeviceRep.delete(data2); |
| | | |
| | | GatewayUtils.removeCache(data2); |
| | | |
| | | flushCache(); |
| | | return null; |
| | | } |
| | |
| | | public void flushCache() { |
| | | List<GatewayDevice> list = listAll(); |
| | | if (null == list || list.isEmpty()) return; |
| | | String key; |
| | | for (GatewayDevice device : list) { |
| | | key = RedisConst.buildKey(RedisConst.KYE_GATE_DEVICE, device.getDeviceId()); |
| | | redisUtil.set(key, device); |
| | | GatewayUtils.add2Cache(device); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç¼åè·å设å¤ä¿¡æ¯ |
| | | * |
| | | * @param deviceId |
| | | * @return |
| | | */ |
| | | public GatewayDevice getCacheDevice(String deviceId) { |
| | | String key = RedisConst.buildKey(RedisConst.KYE_GATE_DEVICE, deviceId); |
| | | return (GatewayDevice) redisUtil.get(key); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | <Property name="required">true</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="appId"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">appId</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayId"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">ç½å
³ID</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayIp"> |
| | | <PropertyDef name="gatewayUsername"> |
| | | <Property/> |
| | | <Property name="label">ç½å
³ç¨æ·å</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayPassword"> |
| | | <Property/> |
| | | <Property name="label">ç½å
³å¯ç </Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayIp"> |
| | | <Property></Property> |
| | | <Property name="label">ç½å
³IP</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayMac"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">ç½å
³Mac</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayCPU"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">ç½å
³CPU</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayMem"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">ç½å
³å
å</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="gatewayHardDisk"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">ç½å
³ç¡¬ç</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="userName"> |
| | |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">gatewayUsername</Property> |
| | | <Property name="property">gatewayUsername</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">gatewayPassword</Property> |
| | | <Property name="property">gatewayPassword</Property> |
| | | <Property name="editorType">PasswordEditor</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">gatewayIp</Property> |
| | | <Property name="property">gatewayIp</Property> |
| | | <Editor/> |
| | |
| | | <PropertyDef name="type"> |
| | | <Property></Property> |
| | | <Property name="label">设å¤ç±»å</Property> |
| | | <Property name="mapping"> |
| | | <Property name="keyProperty">code</Property> |
| | | <Property name="valueProperty">name</Property> |
| | | <Property name="mapValues">${dorado.getDataProvider("apiTriggerService#triggerGatewayDeviceType").getResult()}</Property> |
| | | </Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="depotId"> |
| | | <Property></Property> |
| | | <Property name="label">æå±ä»åº</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="depotName"> |
| | | <Property></Property> |
| | | <Property name="label">æå±ä»åº</Property> |
| | | <Property name="label">æå±ä»åºç¼ç </Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="ip"> |
| | | <Property></Property> |
| | |
| | | <Property></Property> |
| | | <Property name="label">è§é¢RTSP</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="provinceProtocol"> |
| | | <Property/> |
| | | <Property name="label">çå¹³å°åè®®</Property> |
| | | <Property name="mapping"> |
| | | <Property name="mapValues">${dorado.getDataProvider("apiTriggerService#triggerPushProtocol").getResult()}</Property> |
| | | <Property name="keyProperty">code</Property> |
| | | <Property name="valueProperty">name</Property> |
| | | </Property> |
| | | <Property name="required">true</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="pushProtocol"> |
| | | <Property></Property> |
| | | <Property name="label">ç³»ç»ç½å
³é讯åè®®</Property> |
| | |
| | | </PropertyDef> |
| | | <PropertyDef name="syncProtocol"> |
| | | <Property></Property> |
| | | <Property name="label">ç½å
³ä¸è®¾å¤é讯åè®®</Property> |
| | | <Property name="label">ç½å
³è®¾å¤é讯åè®®</Property> |
| | | <Property name="mapping"> |
| | | <Property name="keyProperty">code</Property> |
| | | <Property name="valueProperty">name</Property> |
| | |
| | | <Property name="label">HTTPå°å</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="deviceSn"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">设å¤åºåå·</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="serPort"> |
| | | <Property name="dataType">int</Property> |
| | | <Property name="label">TCPæå¡ç«¯å£</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="userName"> |
| | | <Property/> |
| | | <Property name="label">设å¤ç¨æ·å</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="password"> |
| | | <Property/> |
| | | <Property name="label">设å¤å¯ç </Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="depotName"> |
| | | <Property/> |
| | | <Property name="label">æå±ä»åº</Property> |
| | | </PropertyDef> |
| | | </DataType> |
| | | </Model> |
| | |
| | | <DataColumn name="type"> |
| | | <Property name="property">type</Property> |
| | | </DataColumn> |
| | | <DataColumn name="depotName"> |
| | | <Property name="property">depotName</Property> |
| | | </DataColumn> |
| | | <DataColumn name="syncProtocol"> |
| | | <Property name="property">syncProtocol</Property> |
| | | </DataColumn> |
| | |
| | | <AutoForm> |
| | | <Property name="dataSet">dsMain</Property> |
| | | <Property name="cols">*,*,*</Property> |
| | | <Property name="labelWidth">100</Property> |
| | | <Property name="labelWidth">125</Property> |
| | | <Property name="labelAlign">right</Property> |
| | | <Property name="labelSeparator">ï¼</Property> |
| | | <Property name="labelPosition">left</Property> |
| | | <AutoFormElement> |
| | | <AutoFormElement layoutConstraint="colSpan:2"> |
| | | <Property name="name">deviceId</Property> |
| | | <Property name="property">deviceId</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">deviceSn</Property> |
| | | <Property name="property">deviceSn</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | |
| | | <AutoFormElement> |
| | | <Property name="name">type</Property> |
| | | <Property name="property">type</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">orgId</Property> |
| | | <Property name="property">orgId</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">userName</Property> |
| | | <Property name="property">userName</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">password</Property> |
| | | <Property name="property">password</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <Control/> |
| | | <AutoFormElement> |
| | | <Property name="name">pushProtocol</Property> |
| | | <Property name="property">pushProtocol</Property> |
| | | <Property name="labelWidth">150</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">syncProtocol</Property> |
| | | <Property name="property">syncProtocol</Property> |
| | | <Property name="labelWidth">150</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement> |
| | | <Property name="name">orgId</Property> |
| | | <Property name="property">orgId</Property> |
| | | <Property name="name">serPort</Property> |
| | | <Property name="property">serPort</Property> |
| | | <Property name="labelWidth">150</Property> |
| | | <Editor/> |
| | | </AutoFormElement> |
| | | <AutoFormElement layoutConstraint="colSpan:2"> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | /** |
| | | * ç³»ç»ç¸å
³åè®® |
| | | */ |
| | | package com.fzzy.protocol; |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.weightyh; |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.fzzy.api.utils.SpringUtil; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.DeviceReportService; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.service.HxGatewaySyncWeightImpl1; |
| | | import com.ld.io.api.IoMsgConsumer; |
| | | import com.ld.io.api.IoSession; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * å°ç£
ä¿¡æ¯æ¨é |
| | | * |
| | | * @author: andy.jia |
| | | * @description: |
| | | * @version: |
| | | * @data:2020å¹´3æ19æ¥ |
| | | */ |
| | | @Slf4j |
| | | public class MessageConsumer implements IoMsgConsumer { |
| | | |
| | | private long timeTag = 0; |
| | | |
| | | private GatewayRemoteManager reportService; |
| | | |
| | | @Override |
| | | public void consume(IoSession session, byte[] bytes) { |
| | | analysisInfo(session.getAddress(), session.getPort(), bytes); |
| | | } |
| | | |
| | | /** |
| | | * 02 2B 30 30 31 31 38 30 30 31 33 03 02å¼å§ 03 ç»æ |
| | | */ |
| | | public void analysisInfo(String ip, Integer port, byte[] bytes) { |
| | | String strMsg = BytesUtil.bytesToString(bytes); |
| | | //log.debug("å¼å§è§£æå°ç£
è¿åä¿¡æ¯=" + strMsg); |
| | | if (strMsg.length() < 22) { |
| | | return; |
| | | } |
| | | |
| | | // æ¯é´é2.5æ§è¡ä¸æ¬¡ |
| | | if (System.currentTimeMillis() - timeTag <= 2500) { |
| | | return; |
| | | } |
| | | timeTag = System.currentTimeMillis(); |
| | | |
| | | String temp = strMsg.substring(2, 4); |
| | | String symbol = HexASCIIToConvert(temp); |
| | | temp = strMsg.substring(4, 16); |
| | | String w = HexASCIIToConvert(temp); |
| | | temp = strMsg.substring(16, 18); |
| | | int d = getProduct(Integer.parseInt(HexASCIIToConvert(temp))); |
| | | |
| | | //æç»ééç»æ |
| | | double weigh = Double.valueOf(w) / d; |
| | | |
| | | |
| | | log.debug("----------å°ç£
ç§°éæ°å¼è§£æ------{}", weigh); |
| | | |
| | | //å½åå°ç£
åè®®ä¸æ¯æä¼ éSNï¼ä½¿ç¨å±åç½IPä½ä¸ºSN |
| | | String sn = ip; |
| | | |
| | | |
| | | //æ ¹æ®ä¿¡æ¯è·åè®¾å¤ |
| | | GatewayDevice device = GatewayUtils.getCacheByDeviceSn(sn); |
| | | |
| | | if (null == device) { |
| | | log.error("----------没æè·åå°è®¾å¤ä¿¡æ¯--------{}", sn); |
| | | return; |
| | | } |
| | | |
| | | //ç´æ¥è°ç¨å®ç°ç±»ï¼æ´å¤å®ç°ç±»åç¬è°ç¨ |
| | | if (null == reportService) { |
| | | reportService = SpringUtil.getBean(GatewayRemoteManager.class); |
| | | } |
| | | |
| | | reportService.getDeviceReportService(device.getProvinceProtocol()).report2GatewayBySn(weigh, device); |
| | | } |
| | | |
| | | /** |
| | | * æ ¹æ®å°æ°ç¹ä½æ°è®¡ç®åæ°åéè¦é¤ä»¥å¤å° |
| | | * |
| | | * @param i |
| | | */ |
| | | private int getProduct(int i) { |
| | | if (i == 0) |
| | | return 1; |
| | | int num = 1; |
| | | for (int a = 0; a < i; a++) { |
| | | num = num * 10; |
| | | } |
| | | return num; |
| | | } |
| | | |
| | | private String HexASCIIToConvert(String value) { |
| | | // String value = "30 30 31 31 38 30 30"; |
| | | StringBuffer sbu = new StringBuffer(); |
| | | char t = 0; |
| | | int size = value.length() / 2; |
| | | for (int i = 0; i < size; i++) { |
| | | String tmp = value.substring(i * 2, (i + 1) * 2); |
| | | t = (char) Integer.parseInt("" |
| | | + BytesUtil.bytesToInt(BytesUtil.hexStrToBytes(tmp))); |
| | | sbu.append(t); |
| | | } |
| | | |
| | | return sbu.toString(); |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.weightyh; |
| | | |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.ld.io.api.IoSession; |
| | | import com.ld.io.api.IoSessionListener; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * @author: andy.jia |
| | | * @description: |
| | | * @version: |
| | | */ |
| | | @Slf4j |
| | | public class SessionListener implements IoSessionListener { |
| | | |
| | | public static final String BEAN_ID = "yh.sessionListener"; |
| | | |
| | | @Override |
| | | public void onCreate(IoSession session) { |
| | | // æ·»å èªå®ä¹ä¸å¡ID |
| | | session.setBusinessKey(ContextUtil.getServerKey(session.getAddress(), session.getPort())); |
| | | |
| | | log.info("å°ç£
æåè¿æ¥ï¼IP={},port={}", session.getAddress(), session.getPort()); |
| | | } |
| | | |
| | | @Override |
| | | public void onDestroy(IoSession session) { |
| | | log.info("å°ç£
æå¼è¿æ¥ï¼IP={},port={}", session.getAddress(), session.getPort()); |
| | | |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.fzzy.protocol.weightyh; |
| | | |
| | | import com.fzzy.api.utils.BytesUtil; |
| | | import com.ld.io.api.IoServerOption; |
| | | import com.ld.io.netty.NettyServer; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | /** |
| | | * å°ç£
æå¡å¯å¨ |
| | | * |
| | | * @author: andy.jia |
| | | * @description: |
| | | * @version: |
| | | */ |
| | | @Slf4j |
| | | public class YhScaleServerEngine { |
| | | |
| | | public static final int port = 19090; |
| | | |
| | | public static NettyServer ioServer = null; |
| | | // é
ç½®æ¶æ¯æ¥æ¶ç±» |
| | | private static MessageConsumer messageConsume = new MessageConsumer(); |
| | | // çå¬ä¼è¯çå建ä¸éæ¯ |
| | | private static SessionListener ioSessionListener = new SessionListener(); |
| | | |
| | | public static void start() throws InterruptedException { |
| | | // é
ç½®Serverçé
ç½® |
| | | IoServerOption ioServerOption = new IoServerOption(port); |
| | | // æå
å¨é
ç½® |
| | | //ioServerOption.setSplitDecoderType(SplitByteDecoderType.DELIMITER_SYMBOL); |
| | | ioServerOption.setDelimiter(BytesUtil.hexStrToBytes("03")); |
| | | |
| | | ioServer = new NettyServer(ioServerOption, messageConsume, ioSessionListener); |
| | | ioServer.startup(); |
| | | |
| | | log.info("* ========================"); |
| | | log.info("* "); |
| | | log.info("* å°ç£
-èååçæå¡å¯å¨ï¼ç«¯å£å·={}", YhScaleServerEngine.port); |
| | | log.info("* "); |
| | | log.info("* ========================"); |
| | | } |
| | | |
| | | } |