Browse Source

323232

调味吧台(白底)
fyf 1 year ago
parent
commit
1a52540afd
4 changed files with 67 additions and 8 deletions
  1. +15
    -0
      app/src/main/java/com/example/bpa/Model/BPA_HeartPackage.java
  2. +7
    -0
      app/src/main/java/com/example/bpa/Model/Message_HeartModel.java
  3. +3
    -0
      app/src/main/java/com/example/bpa/config/ConfigName.java
  4. +42
    -8
      app/src/main/java/com/example/bpa/service/OrderServer.java

+ 15
- 0
app/src/main/java/com/example/bpa/Model/BPA_HeartPackage.java View File

@@ -0,0 +1,15 @@
package com.example.bpa.Model;

public class BPA_HeartPackage {
public int MessageId;

public byte MessageVersion;

public int ClientId;

public int ClientType;//9 是MORKT

public String Timestamp;

public Message_HeartModel Message;
}

+ 7
- 0
app/src/main/java/com/example/bpa/Model/Message_HeartModel.java View File

@@ -0,0 +1,7 @@
package com.example.bpa.Model;

public class Message_HeartModel {
public int Healthy;

public int DeviceType;//9 是MORKT
}

+ 3
- 0
app/src/main/java/com/example/bpa/config/ConfigName.java View File

@@ -52,6 +52,8 @@ public class ConfigName {
* 店铺设备号 * 店铺设备号
*/ */
public String AutKey="152.146"; public String AutKey="152.146";
public String ClientId="152";
public String DevId="146";
/** /**
* 店铺设备号 * 店铺设备号
*/ */
@@ -79,6 +81,7 @@ public class ConfigName {
* 订阅主题 * 订阅主题
*/ */
public String mqtt_topic="DOWN/MORKT/BUSINESS/"; public String mqtt_topic="DOWN/MORKT/BUSINESS/";
public String mqtt_hearttopic="UP/MORKT/HEARTBEAT";
//endregion //endregion


//region 环境配置 //region 环境配置


+ 42
- 8
app/src/main/java/com/example/bpa/service/OrderServer.java View File

@@ -4,12 +4,14 @@ import android.util.Log;


import com.example.bpa.Model.BPAPackage; import com.example.bpa.Model.BPAPackage;
import com.example.bpa.Model.BPA_GoodsInfo; 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.BatchingsInfo;
import com.example.bpa.Model.Batchingstechnology; import com.example.bpa.Model.Batchingstechnology;
import com.example.bpa.Model.GoodsBom; import com.example.bpa.Model.GoodsBom;
import com.example.bpa.Model.IMessage; import com.example.bpa.Model.IMessage;
import com.example.bpa.Model.IRun; import com.example.bpa.Model.IRun;
import com.example.bpa.Model.IThread; import com.example.bpa.Model.IThread;
import com.example.bpa.Model.Message_HeartModel;
import com.example.bpa.Model.PushDeviceGoods; import com.example.bpa.Model.PushDeviceGoods;
import com.example.bpa.config.ConfigName; import com.example.bpa.config.ConfigName;
import com.example.bpa.db.QueryDB; import com.example.bpa.db.QueryDB;
@@ -88,17 +90,16 @@ public class OrderServer {
*/ */
public void MqttInit() 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(".")) if(ConfigName.getInstance().AutKey.contains("."))
{ {
String[] str= ConfigName.getInstance().AutKey.split("[.]"); 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() { MQTT.get().callback=new IMessage() {
@Override @Override
public void MessageRecive(String topic, String Message) { public void MessageRecive(String topic, String Message) {
@@ -110,7 +111,7 @@ public class OrderServer {
if(!msg.isEmpty()) if(!msg.isEmpty())
{ {
BPAPackage model=new Json<BPAPackage>().jsonToobject(BPAPackage.class,((String)msg)); 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("收到远程更新数据通知!"); MessageLog.ShowInfo("收到远程更新数据通知!");
RefreshTheData(model.Message); RefreshTheData(model.Message);
@@ -123,12 +124,11 @@ public class OrderServer {
} }
}; };
//连接成功标志 //连接成功标志
String finalDdid = ddid;
MQTT.get().ConnectOk=new IRun() { MQTT.get().ConnectOk=new IRun() {
@Override @Override
public void Run() { public void Run() {


String[] Str={ConfigName.getInstance().mqtt_topic+ finalDdid};
String[] Str={ConfigName.getInstance().mqtt_topic+ ConfigName.getInstance().ClientId};
MQTT.get().Subscrib(Str); MQTT.get().Subscrib(Str);
} }
}; };
@@ -164,9 +164,43 @@ public class OrderServer {
public void RunComplete() throws InterruptedException { 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 * @param data


Loading…
Cancel
Save