|
|
@@ -4,12 +4,14 @@ import android.util.Log; |
|
|
|
|
|
|
|
import com.example.bpa.Model.BPAPackage; |
|
|
|
import com.example.bpa.Model.BPA_GoodsInfo; |
|
|
|
import com.example.bpa.Model.BPA_HeartPackage; |
|
|
|
import com.example.bpa.Model.BatchingsInfo; |
|
|
|
import com.example.bpa.Model.Batchingstechnology; |
|
|
|
import com.example.bpa.Model.GoodsBom; |
|
|
|
import com.example.bpa.Model.IMessage; |
|
|
|
import com.example.bpa.Model.IRun; |
|
|
|
import com.example.bpa.Model.IThread; |
|
|
|
import com.example.bpa.Model.Message_HeartModel; |
|
|
|
import com.example.bpa.Model.PushDeviceGoods; |
|
|
|
import com.example.bpa.config.ConfigName; |
|
|
|
import com.example.bpa.db.QueryDB; |
|
|
@@ -88,17 +90,16 @@ public class OrderServer { |
|
|
|
*/ |
|
|
|
public void MqttInit() |
|
|
|
{ |
|
|
|
String ddid=ConfigName.getInstance().AutKey; |
|
|
|
String devid=ConfigName.getInstance().AutKey; |
|
|
|
ConfigName.getInstance().ClientId=ConfigName.getInstance().AutKey; |
|
|
|
ConfigName.getInstance().DevId=ConfigName.getInstance().AutKey; |
|
|
|
|
|
|
|
if(ConfigName.getInstance().AutKey.contains(".")) |
|
|
|
{ |
|
|
|
String[] str= ConfigName.getInstance().AutKey.split("[.]"); |
|
|
|
ddid=str[0]; |
|
|
|
devid=str[1]; |
|
|
|
ConfigName.getInstance().ClientId=str[0]; |
|
|
|
ConfigName.getInstance().DevId=str[1]; |
|
|
|
} |
|
|
|
//消息回调 |
|
|
|
String finalDevid = devid; |
|
|
|
MQTT.get().callback=new IMessage() { |
|
|
|
@Override |
|
|
|
public void MessageRecive(String topic, String Message) { |
|
|
@@ -110,7 +111,7 @@ public class OrderServer { |
|
|
|
if(!msg.isEmpty()) |
|
|
|
{ |
|
|
|
BPAPackage model=new Json<BPAPackage>().jsonToobject(BPAPackage.class,((String)msg)); |
|
|
|
if((model.ClientId+"").equals(finalDevid) && model.ClientType==9) |
|
|
|
if((model.ClientId+"").equals(ConfigName.getInstance().DevId) && model.ClientType==9) |
|
|
|
{ |
|
|
|
MessageLog.ShowInfo("收到远程更新数据通知!"); |
|
|
|
RefreshTheData(model.Message); |
|
|
@@ -123,12 +124,11 @@ public class OrderServer { |
|
|
|
} |
|
|
|
}; |
|
|
|
//连接成功标志 |
|
|
|
String finalDdid = ddid; |
|
|
|
MQTT.get().ConnectOk=new IRun() { |
|
|
|
@Override |
|
|
|
public void Run() { |
|
|
|
|
|
|
|
String[] Str={ConfigName.getInstance().mqtt_topic+ finalDdid}; |
|
|
|
String[] Str={ConfigName.getInstance().mqtt_topic+ ConfigName.getInstance().ClientId}; |
|
|
|
MQTT.get().Subscrib(Str); |
|
|
|
} |
|
|
|
}; |
|
|
@@ -164,9 +164,43 @@ public class OrderServer { |
|
|
|
public void RunComplete() throws InterruptedException { |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
ThreadManager.Get().StartLong("心跳服务", true, new IThread() { |
|
|
|
@Override |
|
|
|
public void Run() throws InterruptedException { |
|
|
|
|
|
|
|
if(MQTT.get().IsConnect) |
|
|
|
{ |
|
|
|
try { |
|
|
|
PushHeart(); |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Thread.sleep(1000); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void RunComplete() throws InterruptedException { |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
public void PushHeart() throws Exception { |
|
|
|
BPA_HeartPackage heart=new BPA_HeartPackage(); |
|
|
|
heart.MessageId=16; |
|
|
|
heart.ClientId=Integer.parseInt(ConfigName.getInstance().DevId); |
|
|
|
heart.ClientType=9; |
|
|
|
Message_HeartModel mode=new Message_HeartModel(); |
|
|
|
mode.DeviceType=9; |
|
|
|
mode.Healthy=1; |
|
|
|
heart.Message=mode; |
|
|
|
heart.MessageVersion=0; |
|
|
|
heart.Timestamp=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); |
|
|
|
String Message= new Json<BPA_HeartPackage>().objectToJson(BPA_HeartPackage.class,heart); |
|
|
|
String msg= new AES().Encrypt(Message); |
|
|
|
|
|
|
|
MQTT.get().publish(ConfigName.getInstance().mqtt_hearttopic,msg); |
|
|
|
} |
|
|
|
/** |
|
|
|
* 刷新数据 |
|
|
|
* @param data |
|
|
|