想用workerman做一个充电桩采集主站系统,充电桩上报给workerman服务端的数据包括实时数据、鉴权数据、交易记录等,数据项可参见附件。所有的充电桩设备设置的主站IP地址和端口都是一样的,也就是一个充电桩报上来的数据不同的帧,帧格式不一样,长度也不一样。
比如实时数据(f223)是这样的:
681A071A0768C40132BA04000C420101401B00FF00000000000000005522452253224800004600004700000100000031000080406D000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000801401B00FF00000000000000005522452253224800004600004700000100000031000080406D00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000D016
鉴权数据(f224)是这样的:
686A016A01684B0132BA04000CF00101101B127EB5F500000000436202011000000030000000000000000000000000000000000000000000000000000000000000000000000000000000608020000100000000000000000000000055471707004216
那么workerman服务端该怎么处理?是每个不同的帧都要定义一个新协议吗?
附件是我想实现的协议规则,用workerman能实现吗?
一个端口,一个协议即可,协议里根据帧类型来分包。
协议主要是用来分包的,至于内部传输的具体是什么数据,可以在onMessage里根据帧的类型来逐个字节解析,不用在协议层解析。
从协议规则文档来看不同的帧长度是固定的,如果能判断出来是什么帧,然后input返回对应帧的长度即可。例如充电起停事件帧长度固定为24字节,协议接口里input判断帧类型是充电起停则返回24。decode和encode感觉不做任何处理,直接原样返回buffer即可。