Search in sources :

Example 1 with DeviceRpcCallMsg

use of org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg in project thingsboard by thingsboard.

the class DeviceMsgConstructor method constructDeviceRpcCallMsg.

public DeviceRpcCallMsg constructDeviceRpcCallMsg(UUID deviceId, JsonNode body) {
    int requestId = body.get("requestId").asInt();
    boolean oneway = body.get("oneway").asBoolean();
    UUID requestUUID = UUID.fromString(body.get("requestUUID").asText());
    long expirationTime = body.get("expirationTime").asLong();
    String method = body.get("method").asText();
    String params = body.get("params").asText();
    RpcRequestMsg.Builder requestBuilder = RpcRequestMsg.newBuilder();
    requestBuilder.setMethod(method);
    requestBuilder.setParams(params);
    DeviceRpcCallMsg.Builder builder = DeviceRpcCallMsg.newBuilder().setDeviceIdMSB(deviceId.getMostSignificantBits()).setDeviceIdLSB(deviceId.getLeastSignificantBits()).setRequestUuidMSB(requestUUID.getMostSignificantBits()).setRequestUuidLSB(requestUUID.getLeastSignificantBits()).setRequestId(requestId).setExpirationTime(expirationTime).setOneway(oneway).setRequestMsg(requestBuilder.build());
    return builder.build();
}
Also used : DeviceRpcCallMsg(org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg) UUID(java.util.UUID) RpcRequestMsg(org.thingsboard.server.gen.edge.v1.RpcRequestMsg)

Example 2 with DeviceRpcCallMsg

use of org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg in project thingsboard by thingsboard.

the class DeviceEdgeProcessor method processRpcCallMsgToEdge.

public DownlinkMsg processRpcCallMsgToEdge(EdgeEvent edgeEvent) {
    log.trace("Executing processRpcCall, edgeEvent [{}]", edgeEvent);
    DeviceRpcCallMsg deviceRpcCallMsg = deviceMsgConstructor.constructDeviceRpcCallMsg(edgeEvent.getEntityId(), edgeEvent.getBody());
    return DownlinkMsg.newBuilder().setDownlinkMsgId(EdgeUtils.nextPositiveInt()).addDeviceRpcCallMsg(deviceRpcCallMsg).build();
}
Also used : DeviceRpcCallMsg(org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg)

Example 3 with DeviceRpcCallMsg

use of org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg in project thingsboard by thingsboard.

the class BaseEdgeTest method testRpcCall.

@Test
public void testRpcCall() throws Exception {
    Device device = findDeviceByName("Edge Device 1");
    ObjectNode body = mapper.createObjectNode();
    body.put("requestId", new Random().nextInt());
    body.put("requestUUID", Uuids.timeBased().toString());
    body.put("oneway", false);
    body.put("expirationTime", System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10));
    body.put("method", "test_method");
    body.put("params", "{\"param1\":\"value1\"}");
    EdgeEvent edgeEvent = constructEdgeEvent(tenantId, edge.getId(), EdgeEventActionType.RPC_CALL, device.getId().getId(), EdgeEventType.DEVICE, body);
    edgeImitator.expectMessageAmount(1);
    edgeEventService.save(edgeEvent);
    clusterService.onEdgeEventUpdate(tenantId, edge.getId());
    Assert.assertTrue(edgeImitator.waitForMessages());
    AbstractMessage latestMessage = edgeImitator.getLatestMessage();
    Assert.assertTrue(latestMessage instanceof DeviceRpcCallMsg);
    DeviceRpcCallMsg latestDeviceRpcCallMsg = (DeviceRpcCallMsg) latestMessage;
    Assert.assertEquals("test_method", latestDeviceRpcCallMsg.getRequestMsg().getMethod());
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Random(java.util.Random) Device(org.thingsboard.server.common.data.Device) DeviceRpcCallMsg(org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent) AbstractControllerTest(org.thingsboard.server.controller.AbstractControllerTest) Test(org.junit.Test)

Aggregations

DeviceRpcCallMsg (org.thingsboard.server.gen.edge.v1.DeviceRpcCallMsg)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Random (java.util.Random)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 Device (org.thingsboard.server.common.data.Device)1 EdgeEvent (org.thingsboard.server.common.data.edge.EdgeEvent)1 AbstractControllerTest (org.thingsboard.server.controller.AbstractControllerTest)1 RpcRequestMsg (org.thingsboard.server.gen.edge.v1.RpcRequestMsg)1