|
|
@@ -1,6 +1,7 @@
|
|
|
package org.jetlinks.community.bridge.core;
|
|
|
|
|
|
import cn.hutool.core.util.HashUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.aliyun.iot.as.bridge.core.config.BridgeConfigConsts;
|
|
|
import com.aliyun.iot.as.bridge.core.config.BridgeConfigManager;
|
|
|
import com.aliyun.iot.as.bridge.core.exception.BootException;
|
|
|
@@ -9,14 +10,22 @@ import lombok.Getter;
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
import java.net.*;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Enumeration;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Getter
|
|
|
-@NoArgsConstructor
|
|
|
public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
|
|
|
+ /**
|
|
|
+ * 网桥id,以数据库中存储的主键字段id为准
|
|
|
+ * @see org.jetlinks.community.bridge.entity.AliIotBridgeEntity
|
|
|
+ */
|
|
|
+ private String bridgeId;
|
|
|
+
|
|
|
+ private final String macId;
|
|
|
+
|
|
|
/**
|
|
|
* 网桥设备所属产品的ProductKey。
|
|
|
*/
|
|
|
@@ -48,11 +57,13 @@ public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
|
|
|
private PopClientConfiguration popConfiguration;
|
|
|
|
|
|
- public static DefaultBridgeConfigManager of(String bridgeProductKey, String bridgeDeviceName, String bridgeDeviceSecret, String http2Endpoint,String authEndpoint, Map<String, Object> configMaps,PopClientConfiguration popConfiguration) {
|
|
|
- return new DefaultBridgeConfigManager(bridgeProductKey,bridgeDeviceName,bridgeDeviceSecret,http2Endpoint,authEndpoint,configMaps,popConfiguration);
|
|
|
+ public static DefaultBridgeConfigManager of(String bridgeId,String bridgeProductKey, String bridgeDeviceName, String bridgeDeviceSecret, String http2Endpoint,String authEndpoint, Map<String, Object> configMaps,PopClientConfiguration popConfiguration) {
|
|
|
+ return new DefaultBridgeConfigManager(bridgeId,bridgeProductKey,bridgeDeviceName,bridgeDeviceSecret,http2Endpoint,authEndpoint,configMaps,popConfiguration);
|
|
|
}
|
|
|
|
|
|
- private DefaultBridgeConfigManager(String bridgeProductKey, String bridgeDeviceName, String bridgeDeviceSecret, String http2Endpoint,String authEndpoint,Map<String, Object> configMaps, PopClientConfiguration popConfiguration) {
|
|
|
+ private DefaultBridgeConfigManager(String bridgeId,String bridgeProductKey, String bridgeDeviceName, String bridgeDeviceSecret, String http2Endpoint,String authEndpoint,Map<String, Object> configMaps, PopClientConfiguration popConfiguration) {
|
|
|
+ this.bridgeId=bridgeId;
|
|
|
+ this.macId="";
|
|
|
this.bridgeProductKey = bridgeProductKey;
|
|
|
this.bridgeDeviceName = bridgeDeviceName;
|
|
|
this.bridgeDeviceSecret = bridgeDeviceSecret;
|
|
|
@@ -62,6 +73,26 @@ public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
this.popConfiguration = popConfiguration;
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) throws UnknownHostException {
|
|
|
+ System.out.println(createMacId("123"));
|
|
|
+ System.out.println(createMacId("123456789420"));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String createMacId(String id){
|
|
|
+ String result="%s%s-%s%s-%s%s-%s%s-%s%s-%s%s";
|
|
|
+ String[] params=new String[12];
|
|
|
+ Arrays.fill(params,"0");
|
|
|
+ String reverse = StrUtil.reverse(id);
|
|
|
+ for (int i = 0; i < reverse.length(); i++) {
|
|
|
+ if(i>=12){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ params[i]=String.valueOf(reverse.charAt(i));
|
|
|
+ }
|
|
|
+ result=String.format(result,params);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public String getBridgeInstanceId() {
|
|
|
return (String) configMaps.get(BridgeConfigConsts.BRIDGE_INSTANCEID_KEY);
|
|
|
@@ -119,7 +150,8 @@ public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
@Override
|
|
|
public String getMacAddress() {
|
|
|
// return String.valueOf(HashUtil.rsHash(originalProductId));
|
|
|
- return getMac(getInetAddress());
|
|
|
+// return getMac(getInetAddress());
|
|
|
+ return macId;
|
|
|
}
|
|
|
@Override
|
|
|
public void updateBridgeDeviceSecret(String deviceSecret) {
|
|
|
@@ -153,21 +185,6 @@ public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) throws UnknownHostException {
|
|
|
- byte[] macBytes ="123456".getBytes();
|
|
|
- StringBuffer buffer = new StringBuffer();
|
|
|
- for(int i = 0; i < macBytes.length; i++){
|
|
|
- if(i != 0) { buffer.append("-"); }
|
|
|
- int intMac = macBytes[i]&0xff;
|
|
|
- String str = Integer.toHexString(intMac);
|
|
|
- if(str.length() == 0){
|
|
|
- buffer.append("0");
|
|
|
- }
|
|
|
- buffer.append(str);
|
|
|
- }
|
|
|
- System.out.println(buffer.toString().toUpperCase());
|
|
|
-
|
|
|
- }
|
|
|
private InetAddress getInetAddress() {
|
|
|
try {
|
|
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|