|
|
@@ -1,9 +1,11 @@
|
|
|
package org.jetlinks.community.bridge.core;
|
|
|
|
|
|
+import cn.hutool.core.util.HashUtil;
|
|
|
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;
|
|
|
import com.aliyun.iot.as.bridge.core.model.PopClientConfiguration;
|
|
|
+import io.netty.util.internal.MacAddressUtil;
|
|
|
import lombok.Getter;
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
@@ -16,6 +18,11 @@ import java.util.Map;
|
|
|
@NoArgsConstructor
|
|
|
public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
|
|
|
+ /**
|
|
|
+ * 网桥产品id,代替mac地址作为网桥的唯一标识
|
|
|
+ */
|
|
|
+ private String originalProductId;
|
|
|
+
|
|
|
/**
|
|
|
* 网桥设备所属产品的ProductKey。
|
|
|
*/
|
|
|
@@ -47,11 +54,12 @@ 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 originalProductId,String bridgeProductKey, String bridgeDeviceName, String bridgeDeviceSecret, String http2Endpoint,String authEndpoint, Map<String, Object> configMaps,PopClientConfiguration popConfiguration) {
|
|
|
+ return new DefaultBridgeConfigManager(originalProductId,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 originalProductId,String bridgeProductKey, String bridgeDeviceName, String bridgeDeviceSecret, String http2Endpoint,String authEndpoint,Map<String, Object> configMaps, PopClientConfiguration popConfiguration) {
|
|
|
+ this.originalProductId=originalProductId;
|
|
|
this.bridgeProductKey = bridgeProductKey;
|
|
|
this.bridgeDeviceName = bridgeDeviceName;
|
|
|
this.bridgeDeviceSecret = bridgeDeviceSecret;
|
|
|
@@ -117,7 +125,9 @@ public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
}
|
|
|
@Override
|
|
|
public String getMacAddress() {
|
|
|
- return getMac(getInetAddress());
|
|
|
+// return String.valueOf(HashUtil.rsHash(originalProductId));
|
|
|
+// return getMac(getInetAddress());
|
|
|
+ return "31-32-33-34-35-36";
|
|
|
}
|
|
|
@Override
|
|
|
public void updateBridgeDeviceSecret(String deviceSecret) {
|
|
|
@@ -129,6 +139,7 @@ public class DefaultBridgeConfigManager implements BridgeConfigManager {
|
|
|
this.bridgeDeviceName=deviceName;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private String getMac(InetAddress addr) {
|
|
|
try {
|
|
|
NetworkInterface net = NetworkInterface.getByInetAddress(addr);
|
|
|
@@ -150,6 +161,21 @@ 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();
|