8 changed files with 132 additions and 2 deletions
@ -1,12 +1,22 @@ |
|||
package com.galaxis.rcs; |
|||
|
|||
import com.galaxis.rcs.communication.amrCommunication.MqttService; |
|||
import org.eclipse.paho.mqttv5.common.MqttException; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
@RestController |
|||
public class RcsRootController { |
|||
|
|||
@Autowired |
|||
private MqttService mqttService; |
|||
|
|||
@GetMapping("/ok") |
|||
public String ok() { |
|||
public String ok() throws MqttException { |
|||
mqttService.subscribe("/agv_robot/status"); |
|||
// mqttService.publish("rcs/root/ok", "OK");
|
|||
return "OK"; |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,43 @@ |
|||
package com.galaxis.rcs.communication.amrCommunication; |
|||
|
|||
import org.eclipse.paho.mqttv5.client.MqttClient; |
|||
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; |
|||
import org.eclipse.paho.mqttv5.common.MqttException; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
|
|||
@Configuration |
|||
public class MqttConfig { |
|||
@Value("${mqtt.broker-url}") |
|||
private String brokerUrl; |
|||
|
|||
@Value("${mqtt.client-id}") |
|||
private String clientId; |
|||
|
|||
@Value("${mqtt.username}") |
|||
private String username; |
|||
|
|||
@Value("${mqtt.password}") |
|||
private String password; |
|||
|
|||
@Bean |
|||
public MqttConnectionOptions mqttConnectOptions() { |
|||
MqttConnectionOptions options = new MqttConnectionOptions(); |
|||
options.setServerURIs(new String[]{brokerUrl}); |
|||
options.setAutomaticReconnect(true); // 启用自动重连
|
|||
options.setUserName(username); |
|||
options.setPassword(password.getBytes()); |
|||
return options; |
|||
} |
|||
|
|||
@Bean(destroyMethod = "disconnect") |
|||
public MqttClient mqttClient() throws MqttException { |
|||
MqttClient client = new MqttClient(brokerUrl, clientId); |
|||
client.connect(mqttConnectOptions()); |
|||
return client; |
|||
} |
|||
} |
|||
|
|||
|
|||
@ -0,0 +1,27 @@ |
|||
package com.galaxis.rcs.communication.amrCommunication; |
|||
|
|||
import org.eclipse.paho.mqttv5.client.IMqttMessageListener; |
|||
import org.eclipse.paho.mqttv5.client.MqttClient; |
|||
import org.eclipse.paho.mqttv5.common.MqttException; |
|||
import org.eclipse.paho.mqttv5.common.MqttMessage; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
@Service |
|||
public class MqttService implements IMqttMessageListener { |
|||
@Autowired |
|||
private MqttClient mqttClient; |
|||
|
|||
public void subscribe(String topic) throws MqttException { |
|||
mqttClient.subscribe(topic, 0, this); |
|||
} |
|||
|
|||
public void publish(String topic, String payload) throws MqttException { |
|||
mqttClient.publish(topic, new MqttMessage(payload.getBytes())); |
|||
} |
|||
|
|||
@Override |
|||
public void messageArrived(String topic, MqttMessage message) throws Exception { |
|||
System.out.println("Received message: " + message.toString() + " from topic: " + topic); |
|||
} |
|||
} |
|||
@ -0,0 +1,4 @@ |
|||
package com.galaxis.rcs.connector.cl2; |
|||
|
|||
public class Cl2TaskManger { |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.galaxis.rcs.connector.cl2.receiveEntity; |
|||
|
|||
// RCS 接收 AMR的消息
|
|||
public class AmrMessage<T> { |
|||
// 作业序号 UInt32 从1开始,0作为超级序号使用,不参与序号规则判断
|
|||
public long SeqNo; |
|||
// AMR编号 UInt16
|
|||
public int VehicleId; |
|||
// 消息创建时间 UInt64 毫秒级时间戳
|
|||
public long CreateTime; |
|||
// 消息创建时主机的开机时长 UInt64 毫秒级时间戳
|
|||
public long CreateMonoTime; |
|||
// 发送消息的时间 UInt64 毫秒级时间戳
|
|||
public long SendTime; |
|||
|
|||
} |
|||
Loading…
Reference in new issue