2016-05-24 36 views
1

我想在java-agent中實現c8y_Command(Shell)OperationType。 我已經到了可以在設備上運行命令的地步,我也可以設置OperationStatus,但我沒有找到發送結果(命令輸出)字符串的方式。設置Java的c8y_Command結果字符串

http://www.cumulocity.com/guides/reference/device-management/ 說:

進行通信的特定命令的結果,該裝置增加了一個 屬性 「結果」:

"c8y_Command": { 
    "text": "get uboot.sn", 
    "result": "165711141901401" 
} 

如果是這樣的藥劑可以如何設置狀態:

operation.setStatus(OperationStatus.SUCCESSFUL.toString()); 

然後你可以顯示請怎麼發回命令結果字符串!

謝謝你一堆。

回答

2

對應於Json中「c8y_Command」對象的類是c8y.Command。因此,設置結果的代碼將爲:

operation.get(Command.class).setResult("165711141901401"); 
+0

ThanksAndré,operation.get(Command.class)給出了null。 operation.get(「c8y_Command」)給了我一些對象,但我不確定它是什麼類型。我沒有在javadoc中找到setResult方法http://resources.cumulocity.com/documentation/javasdk/current/你可能是指com.cumulocity.sdk.client.buffering.Result.setResponse(object)? – Peter

+0

您可能使用了錯誤的Command.class。檢查它是否是導入中的包c8y中的一個。如果它返回null,這意味着它沒有找到那個類的對象。 –

1

aha,我不得不像這樣施放它。

((c8y.Command)operation.get("c8y_Command")).setResult("165711141901401");