123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- # coding=utf-8
- from apps.web.core.device_define.cmCZ import DEV_PREFIX
- from apps.web.device.models import Device, DeviceDict
- from apps.web.eventer import EventBuilder
- from apps.web.eventer.base import WorkEvent
- from apps.web.eventer.cmCZSub import cmCZSubEventWorker, cmCZSubComNetPayAckEvent, cmCZSubIdStartAckEvent, cmCZSubAckEventProcessorIntf
- class builder(EventBuilder):
- """
- gateway是代理人的角色 目前网关没有事件 因此所有信息都转到sub
- """
- def __getEvent__(self, device_event):
- if "order_id" in device_event:
- addr = device_event["addr"]
- devNo = "{}{}".format(DEV_PREFIX, addr)
- sub = Device.get_dev(devNo)
- if device_event["order_type"] == "com_start":
- return cmCZSubComNetPayAckEvent(sub.deviceAdapter, device_event)
- if device_event["order_type"] == "id_start":
- return cmCZSubIdStartAckEvent(sub.deviceAdapter, device_event, pre_processor=cmCZSubAckEventProcessorIntf())
- elif "subs" in device_event:
- return CMCZGateway(self.device.deviceAdapter, device_event)
- else:
- addr = int(device_event["data"][6: 14], 16)
- devNo = "{}{}".format(DEV_PREFIX, addr)
- sub = Device.get_dev(devNo)
- event_data = sub.deviceAdapter.analyze_event_data(device_event["data"])
- return cmCZSubEventWorker(sub.deviceAdapter, event_data)
- class CMCZGateway(WorkEvent):
- """
- 无用的 主板没有实现该协议
- """
- def do(self, **args):
- if not self.event_data["subs"]:
- return
- for sub, signal in self.event_data["subs"].items():
- dev = Device.get_dev("{}{}".format(DEV_PREFIX, sub)) # type: DeviceDict
- if not dev:
- continue
- # 信号上报的时候 也将整机上报上去
- other = dev.otherConf
- if "master" not in other:
- other["master"] = self.device.devNo
- Device.objects.filter(devNo=dev.devNo).first().update(
- otherConf=other,
- coreVer=self.device.coreVer,
- softVer=self.device.softVer,
- hwVer=self.device.hwVer,
- driverCode=self.device.driverCode,
- driverVersion=self.device.driverVersion
- )
- Device.invalid_device_cache(dev.devNo)
- if signal:
- dev.set_online(30)
- else:
- dev.set_offline()
|