| | |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import com.battery.device.api.DeviceAdapter; |
| | | import com.battery.device.model.AdapterCapabilities; |
| | | import com.battery.device.model.ChannelIdentity; |
| | | import com.battery.device.model.DetectedChannel; |
| | | import com.battery.device.model.HistoryAvailability; |
| | | import com.battery.device.model.HistoryPage; |
| | | import com.battery.device.model.RealtimeSnapshot; |
| | | import com.battery.device.api.model.AdapterCapabilities; |
| | | import com.battery.device.api.model.ChannelIdentity; |
| | | import com.battery.device.api.model.DetectedChannel; |
| | | import com.battery.device.api.model.RealtimeSnapshot; |
| | | |
| | | public final class BtsDeviceAdapter implements DeviceAdapter |
| | | { |
| | |
| | | this.capabilities = capabilities; |
| | | } |
| | | |
| | | /** 返回本实例登记的适配器编码。 */ |
| | | @Override |
| | | public String adapterCode() |
| | | { |
| | | return adapterCode; |
| | | } |
| | | |
| | | /** 返回本实例登记的能力标记;BTS 协议路线按只观测装配。 */ |
| | | @Override |
| | | public AdapterCapabilities capabilities() |
| | | { |
| | | return capabilities; |
| | | } |
| | | |
| | | /** 通过设备信息命令读取通道登记事实,作为发现候选返回。 */ |
| | | @Override |
| | | public List<DetectedChannel> discoverChannels() |
| | | { |
| | | return codec.parseDeviceInfo(transport.exchange(codec.getDeviceInfoRequest())); |
| | | } |
| | | |
| | | /** 按给定通道集合请求一次实时状态;通道为空时不发请求。 */ |
| | | @Override |
| | | public Map<ChannelIdentity, RealtimeSnapshot> inquire(Set<ChannelIdentity> channels) |
| | | { |
| | | if (channels == null || channels.isEmpty()) return Map.of(); |
| | | return codec.parseSnapshots(transport.exchange(codec.inquireRequest(channels, false)), Instant.now()); |
| | | // 带上请求集合:服务端会改写应答里的 devtype,按请求的身份归集才拿得到自己要的通道。 |
| | | return codec.parseSnapshots(transport.exchange(codec.inquireRequest(channels, false)), channels, |
| | | Instant.now()); |
| | | } |
| | | |
| | | @Override |
| | | public List<HistoryAvailability> inquireHistory(Set<ChannelIdentity> channels) |
| | | { |
| | | if (!capabilities.historyDownload()) throw new UnsupportedOperationException("History download is not supported"); |
| | | if (channels == null || channels.isEmpty()) return List.of(); |
| | | return codec.parseHistoryAvailability(transport.exchange(codec.inquireHistoryRequest(channels))); |
| | | } |
| | | |
| | | @Override |
| | | public HistoryPage downloadHistory(ChannelIdentity channel, String btsTestId, long startPosition, int limit) |
| | | { |
| | | if (!capabilities.historyDownload()) throw new UnsupportedOperationException("History download is not supported"); |
| | | return codec.parseHistory(transport.exchange(codec.downloadRequest(channel, btsTestId, startPosition, limit)), |
| | | channel, btsTestId, startPosition); |
| | | } |
| | | |
| | | /** 关闭底层传输连接。 */ |
| | | @Override |
| | | public void close() |
| | | { |