| 12345678910111213141516171819202122232425262728293031323334 |
- package parking
- // RoutingGateController 按设备编码在多个道闸后端之间路由。
- // fallback 为默认后端(UHF 继电器 DeviceManager 或 SimulatedGateController),
- // mqtt 为可选的独立网络道闸后端;仅当 mqtt 存在且持有该设备路由时才走 MQTT。
- type RoutingGateController struct {
- fallback GateController
- mqtt *MQTTGateController
- }
- func NewRoutingGateController(fallback GateController, mqtt *MQTTGateController) *RoutingGateController {
- return &RoutingGateController{fallback: fallback, mqtt: mqtt}
- }
- func (r *RoutingGateController) OpenGate(deviceCode string, validTime byte) error {
- if r.mqtt != nil && r.mqtt.HasRoute(deviceCode) {
- return r.mqtt.OpenGate(deviceCode, validTime)
- }
- return r.fallback.OpenGate(deviceCode, validTime)
- }
- func (r *RoutingGateController) CloseGate(deviceCode string, validTime byte) error {
- if r.mqtt != nil && r.mqtt.HasRoute(deviceCode) {
- return r.mqtt.CloseGate(deviceCode, validTime)
- }
- return r.fallback.CloseGate(deviceCode, validTime)
- }
- func (r *RoutingGateController) IsGateConnected(deviceCode string) bool {
- if r.mqtt != nil && r.mqtt.HasRoute(deviceCode) {
- return r.mqtt.IsGateConnected(deviceCode)
- }
- return r.fallback.IsGateConnected(deviceCode)
- }
|