Cumulocity 找到跟踪器的所有未决操作
Cumulocity find all pending operations for tracker
我正在为我的跟踪器代理中的特定确认消息编写解析器。解析后,我想检索跟踪器的所有未决 commands/firmware 更新,以便我可以将它们与确认的内容进行比较并更新相关操作,以便它们相应地显示在 Cumulocity 中。
我该怎么做?例如,也许我可以使用 OperationsHelper.getOperationsByStatusAndAgent() ?但是我如何才能访问这个级别的 OperationsHelper?
编辑
这是我现在要尝试的方法:
跟踪器设备:
public Iterable<OperationRepresentation> getPendingOps() {
OperationFilter opsFilter = new OperationFilter().byStatus(OperationStatus.PENDING)
.byAgent(this.gid.getValue());
return deviceControl.getOperationsByFilter(opsFilter).get().allPages();
}
我的自定义解析器:
TrackerDevice trackerDevice = trackerAgent.getOrCreateTrackerDevice(reportCtx.getEntry(POS_IMEI));
// Looking into pending operations...
for (OperationRepresentation operation: trackerDevice.getPendingOps()) {
Firmware frm = operation.get(Firmware.class);
// ...for firmware updates
if (frm != null) {
String command = (String) frm.getProperty("command");
// (GL200Fallback associated a command string to these)
if (command != null) {
Matcher m = commandPattern.matcher(command);
// In each command there is a random count number...
if (m.find()) {
String cmdCountNumber = command.substring(m.start(), m.end());
// ...that must match with the acknowledgement's
if (cmdCountNumber.equals(reportCtx.getEntry(POS_COUNT_NUMBER))) {
trackerDevice.setOperationSuccessful(operation);
return true;
}
}
}
}
}
getOperationsByStatusAndAgent() 函数将获取所有跟踪器设备的操作。这可能不是你想要的。
如果您检查 OperationDispatcher 中的 startPolling() 方法,您会看到代理自动轮询每个跟踪器的操作。这应该在新设备连接或启动代理时自动触发(然后它将开始对所有已注册的设备进行轮询)。
您无需为新的跟踪器协议自行处理此问题。您只需要为实现 Translator 接口的协议添加 类。只要代理收到设备的新操作,这些就会被触发。
编辑:
如果您想在设备应答后更新操作,您可以通过多种方式进行。首先,我将使用 TrackerDevice 中的 DeviceControlApi 与操作进行交互。它目前未在 TrackerDevice 中公开,但您可以更改它。
以后要更新操作,您需要操作的 ID。您可以缓存操作,例如在将其发送到设备后在设备对象中,或者您需要查询它,例如按状态和片段类型
我正在为我的跟踪器代理中的特定确认消息编写解析器。解析后,我想检索跟踪器的所有未决 commands/firmware 更新,以便我可以将它们与确认的内容进行比较并更新相关操作,以便它们相应地显示在 Cumulocity 中。
我该怎么做?例如,也许我可以使用 OperationsHelper.getOperationsByStatusAndAgent() ?但是我如何才能访问这个级别的 OperationsHelper?
编辑
这是我现在要尝试的方法:
跟踪器设备:
public Iterable<OperationRepresentation> getPendingOps() {
OperationFilter opsFilter = new OperationFilter().byStatus(OperationStatus.PENDING)
.byAgent(this.gid.getValue());
return deviceControl.getOperationsByFilter(opsFilter).get().allPages();
}
我的自定义解析器:
TrackerDevice trackerDevice = trackerAgent.getOrCreateTrackerDevice(reportCtx.getEntry(POS_IMEI));
// Looking into pending operations...
for (OperationRepresentation operation: trackerDevice.getPendingOps()) {
Firmware frm = operation.get(Firmware.class);
// ...for firmware updates
if (frm != null) {
String command = (String) frm.getProperty("command");
// (GL200Fallback associated a command string to these)
if (command != null) {
Matcher m = commandPattern.matcher(command);
// In each command there is a random count number...
if (m.find()) {
String cmdCountNumber = command.substring(m.start(), m.end());
// ...that must match with the acknowledgement's
if (cmdCountNumber.equals(reportCtx.getEntry(POS_COUNT_NUMBER))) {
trackerDevice.setOperationSuccessful(operation);
return true;
}
}
}
}
}
getOperationsByStatusAndAgent() 函数将获取所有跟踪器设备的操作。这可能不是你想要的。
如果您检查 OperationDispatcher 中的 startPolling() 方法,您会看到代理自动轮询每个跟踪器的操作。这应该在新设备连接或启动代理时自动触发(然后它将开始对所有已注册的设备进行轮询)。
您无需为新的跟踪器协议自行处理此问题。您只需要为实现 Translator 接口的协议添加 类。只要代理收到设备的新操作,这些就会被触发。
编辑:
如果您想在设备应答后更新操作,您可以通过多种方式进行。首先,我将使用 TrackerDevice 中的 DeviceControlApi 与操作进行交互。它目前未在 TrackerDevice 中公开,但您可以更改它。
以后要更新操作,您需要操作的 ID。您可以缓存操作,例如在将其发送到设备后在设备对象中,或者您需要查询它,例如按状态和片段类型