Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dConnectJavascriptApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<script src="./js/profile/fabo.js" type="text/javascript"></script>
<script src="./js/profile/mouse.js" type="text/javascript"></script>
<script src="./js/profile/keyboard.js" type="text/javascript"></script>
<script src="./js/profile/device.js" type="text/javascript"></script>
<script src="./js/sdk/util.js" type="text/javascript"></script>
<script src="./js/demo.js" type="text/javascript"></script>

Expand Down
4 changes: 3 additions & 1 deletion dConnectJavascriptApp/js/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ function authorization(callback, oncalcel) {
'tv', 'powermeter','humidity','illuminance', 'videochat',
'airconditioner','gpio', 'ecg', 'stressEstimation', 'poseEstimation',
'walkState', 'messagehook', 'atmosphericPressure', 'geolocation',
'echonetLite', 'power', 'fabo', 'mouse', 'keyboard');
'echonetLite', 'power', 'fabo', 'mouse', 'keyboard', 'device');
dConnect.authorization(scopes, 'Demo Web Site',
function(clientId, newAccessToken) {
// Client ID
Expand Down Expand Up @@ -438,5 +438,7 @@ function searchProfile(serviceId, profile) {
showMouse(serviceId);
} else if (isEqualToStringIgnoreCase(profile, 'keyboard')) {
showKeyboard(serviceId);
} else if (isEqualToStringIgnoreCase(profile, 'device')) {
showDevice(serviceId);
}
}
96 changes: 96 additions & 0 deletions dConnectJavascriptApp/js/profile/device.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
device.js
Copyright (c) 2017 NTT DOCOMO,INC.
Released under the MIT license
http://opensource.org/licenses/mit-license.php
*/

/**
* Show Device Menu
*
* @param {String} serviceId service Id
*/
function showDevice(serviceId) {
initAll();
setTitle('Device Profile');

var sessionKey = currentClientId;

var btnStr = getBackButton('Device Top', 'doPowerMeterBack', serviceId, '');
reloadHeader(btnStr);
reloadFooter(btnStr);

var str = '';

str += makeInputText('Result', 'post-pairing', 'post-pairing');
str += devMakeButton('PostPairing (Connect)','doDevicePostPairing',serviceId);
str += '<hr>';

str += makeInputText('Result', 'delete-pairing', 'delete-pairing');
str += devMakeButton('DeletePairing (Disconnect)','doDeviceDeletePairing',serviceId);
str += '<hr>';

reloadContent(str);
}

function doDevicePostPairing(serviceId){
var builder = devMakeUriBuilder(serviceId, 'pairing');
var successCallback = function (json){
console.log('Response: ', json);
$('#post-pairing').val(json.result);
};
console.log('Uri: ', builder.build());
dConnect.post(builder.build(),null,null,successCallback,pmAlertError);
}

function doDeviceDeletePairing(serviceId){
var builder = devMakeUriBuilder(serviceId, 'pairing');
var successCallback = function (json){
console.log('Response: ', json);
$('#delete-pairing').val(json.result);
};
console.log('Uri: ', builder.build());
dConnect.delete(builder.build(),null,successCallback,devAlertError);
}

/**
* Back button
*
* @param {String}serviceId service id
* @param {String}sessionKey session key
*/
function doDeviceBack(serviceId, sessionKey) {
searchSystem(serviceId);
}

//////common (dev = device)

function devMakeButton(title,functionName,params) {
var paramStr = '';
if(params !== null && params.length > 0){
if( typeof params === 'string' ) {
params = [ params ];
}
for (var i = 0;i<params.length;i++){
paramStr += '\''+params[i]+'\'';
paramStr += ',';
}
paramStr = paramStr.slice(0,-1);
}
return '<input onclick="'+functionName+'('+paramStr+');" type="button" value="'+title+'"/>';
}

function devMakeUriBuilder(serviceId, attribute){
var builder = new dConnect.URIBuilder();
builder.setProfile('device');
builder.setServiceId(serviceId);
builder.setAccessToken(accessToken);
if(typeof attribute !== 'undefined'){
builder.setAttribute(attribute);
}
return builder;
}

function devAlertError(errorCode, errorMessage){
showError('device error', errorCode, errorMessage);
}
114 changes: 104 additions & 10 deletions dConnectJavascriptApp/js/profile/powermeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function showPowerMeter(serviceId) {
var str = '';

str += makeInputText('PowerStatus', 'power-status', 'power-status');
str += pmMakeButton('GetPowerState','doPowerMeterGetPowerState',serviceId);
str += pmMakeButton('GetPowerStatus','doPowerMeterGetPowerStatus',serviceId);
str += pmMakeButton('PutPowerOn','doPowerMeterPutPowerOn',serviceId);
str += pmMakeButton('DeletePowerOff','doPowerMeterDeletePowerOff',serviceId);
str += '<hr>';
Expand All @@ -32,22 +32,76 @@ function showPowerMeter(serviceId) {
str += '<input name="newDate" id="newDate" type="text" data-role="datebox" data-options=\'{"mode":"datebox"}\' />';
str += '<input name="newTime" id="newTime" type="text" data-role="datebox" data-options=\'{"mode":"timebox"}\' />';

str += '<form name="integratedPowerUnitForm">';
str += '<SELECT name="integrated-unit" id="integrated-unit">';
str += '<OPTION value="null_value">unit : 指定なし</OPTION>';
str += '<OPTION value="Wh">unit : Wh</OPTION>';
str += '<OPTION value="kWh">unit : kWh</OPTION>';
str += '<OPTION value="MWh">unit : MWh (Error Case)</OPTION>';
str += '</SELECT>';
str += '</form>';

str += '<form name="integratedPowerCountForm">';
str += '<SELECT name="count-power" id="count-power">';
str += '<OPTION value="null_value">count : 指定なし</OPTION>';
str += '<OPTION value="24">count : 24</OPTION>';
str += '<OPTION value="48">count : 48</OPTION>';
str += '<OPTION value="96">count : 96 (Error Case)</OPTION>';
str += '</SELECT>';
str += '</form>';

str += '<form name="integratedPowerPowerFlowForm">';
str += '<SELECT name="powerFlow-power" id="powerFlow-power">';
str += '<OPTION value="null_value">powerFlow : 指定なし</OPTION>';
str += '<OPTION value="normal">powerFlow : normal</OPTION>';
str += '<OPTION value="reverse">powerFlow : reverse</OPTION>';
str += '<OPTION value="turn">powerFlow : turn (Error Case)</OPTION>';
str += '</SELECT>';
str += '</form>';

str += makeInputText('IntegratedPower', 'integrated-power', 'integrated-power');
str += makeInputText('Unit', 'integrated-power-unit', 'integrated-power-unit');
str += makeInputText('Count', 'integrated-power-count', 'integrated-power-count');
str += makeInputText('powerFlow', 'integrated-power-powerflow', 'integrated-power-powerflow');
str += pmMakeButton('GetIntegratedPower','doPowerMeterGetIntegratedPower',serviceId);
str += '<hr>';

str += '<form name="instantaneousPowerUnitForm">';
str += '<SELECT name="unit-power" id="unit-power">';
str += '<OPTION value="null_value">unit : 指定なし</OPTION>';
str += '<OPTION value="W">unit : W</OPTION>';
str += '<OPTION value="kW">unit : kW</OPTION>';
str += '<OPTION value="MW">unit : MW (Error Case)</OPTION>';
str += '</SELECT>';
str += '</form>';

str += makeInputText('InstantaneousPower', 'instantaneous-power', 'instantaneous-power');
str += makeInputText('Unit', 'instantaneous-power-unit', 'instantaneous-power-unit');
str += pmMakeButton('GetInstantaneousPower','doPowerMeterGetInstantaneousPower',serviceId);
str += '<hr>';

str += '<form name="integratedCurrentUnitForm">';
str += '<SELECT name="unit-current" id="unit-current">';
str += '<OPTION value="null_value">unit : 指定なし</OPTION>';
str += '<OPTION value="A">unit : A</OPTION>';
str += '<OPTION value="mA">unit : mA</OPTION>';
str += '<OPTION value="uA">unit : uA (Error Case)</OPTION>';
str += '</SELECT>';
str += '</form>';

str += makeInputText('InstantaneousCurrent(R)', 'instantaneous-current-r', 'instantaneous-current-r');
str += makeInputText('InstantaneousCurrent(T)', 'instantaneous-current-t', 'instantaneous-current-t');
str += makeInputText('Unit', 'instantaneous-current-unit', 'instantaneous-current-unit');
str += pmMakeButton('GetInstantaneousCurrent','doPowerMeterGetInstantaneousCurrent',serviceId);
str += '<hr>';
reloadContent(str);
}

function doPowerMeterGetPowerState(serviceId){
function doPowerMeterGetPowerStatus(serviceId){
var builder = pmMakeUriBuilder(serviceId);
var successCallback = function (json){
console.log('Response: ', json);
$('#power-stauts').val(json.powerstatus);
$('#power-status').val(json.powerstatus);
};
dConnect.get(builder.build(), null, successCallback, pmAlertError);
}
Expand All @@ -69,26 +123,66 @@ function doPowerMeterGetIntegratedPower(serviceId){
var newTime = $('#newTime').val();

if(newDate && newTime){
var newDateStr = newDate + 'T' + newTime + ':00+0900';
var newDateStr = newDate + 'T' + newTime + ':00+09:00';
builder.addParameter('date', newDateStr);
}

var unit = $('#integrated-unit').val();

if (unit != 'null_value') {
builder.addParameter('unit', unit);
}

var count = $('#count-power').val();

if (count != 'null_value') {
builder.addParameter('count', count);
}

var powerFlow = $('#powerFlow-power').val();

if (powerFlow != 'null_value') {
builder.addParameter('powerFlow', powerFlow);
}

var successCallback = function (json){
var integra = json.integratedpower;
var total = 0;
jQuery.each(integra,function(i,value){
total+=value;
});
$('#integrated-power').val(total);
$('#integrated-power').val(json.integratedpower);
$('#integrated-power-unit').val(json.unit);
$('#integrated-power-count').val(json.count);
$('#integrated-power-powerflow').val(json.powerFlow);
};
dConnect.get(builder.build(), null, successCallback, pmAlertError);
}

function doPowerMeterGetInstantaneousPower(serviceId){
var builder = pmMakeUriBuilder(serviceId,'instantaneouspower');
var unit = $('#unit-power').val();

if (unit != 'null_value') {
builder.addParameter('unit', unit);
}

var successCallback = function (json){
console.log('Response: ', json);
$('#instantaneous-power').val(json.instantaneouspower);
$('#instantaneous-power-unit').val(json.unit);
};
dConnect.get(builder.build(), null, successCallback, pmAlertError);
}

function doPowerMeterGetInstantaneousCurrent(serviceId){
var builder = pmMakeUriBuilder(serviceId,'instantaneouscurrent');
var unit = $('#unit-current').val();

if (unit != 'null_value') {
builder.addParameter('unit', unit);
}

var successCallback = function (json){
console.log('Response: ', json);
$('#instantaneous-current-r').val(json.instantaneouscurrent.rphase);
$('#instantaneous-current-t').val(json.instantaneouscurrent.tphase);
$('#instantaneous-current-unit').val(json.instantaneouscurrent.unit);
};
dConnect.get(builder.build(), null, successCallback, pmAlertError);
}
Expand Down
3 changes: 2 additions & 1 deletion dConnectSDKForJavascriptTest/dconnect-test-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ function initScopes() {
'fabo',
'mouse',
'keyboard',
'hogp'
'hogp',
'device'

);
}
Expand Down
4 changes: 4 additions & 0 deletions dConnectSDKForJavascriptTest/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ <H1>デバイスプラグインテスト</H1>
<td><b>HOGPデバイスプラグイン</b></td>
<td><button style="padding:10px;" type="button" name="テスト" onclick="onTestClick('tests/hogp_test.html');">テスト</button></td>
</tr>
<tr>
<td><b>SmartMeterデバイスプラグイン</b></td>
<td><button style="padding:10px;" type="button" name="テスト" onclick="onTestClick('tests/smartmeter_test.html');">テスト</button></td>
</tr>
</table>
<H1>Javascript SDK テスト</H1>
<table border="1" width="100%">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module('DeviceProfileAbnormalTest', {
setup: function() {
init();
}
});

/**
* Deviceプロファイルの異常系テストを行うクラス。
* @class
*/
var DeviceProfileAbnormalTest = {};

/**
* 定義されていないPUTメソッドでアクセスするテストを行う。
* <h3>【HTTP通信】</h3>
* <p id='test'>
* Method: PUT<br/>
* Path: /device/pairing?serviceId=xxxx&accessToken=xxx<br/>
* </p>
* <h3>【期待する動作】</h3>
* <p id='expected'>
* ・resultに1が返ってくること。<br/>
* </p>
*/
DeviceProfileAbnormalTest.pairingAbnormalTest001 = function(assert) {
var accessToken = getCurrentAccessToken();
var serviceId = getCurrentServiceId();
var builder = new dConnect.URIBuilder();
builder.setProfile('device');
builder.setAttribute('pairing');
builder.setServiceId(serviceId);
builder.setAccessToken(accessToken);
var uri = builder.build();
dConnect.get(uri, null, function(json) {
assert.ok(false, 'json: ' + JSON.stringify(json));
QUnit.start();
},
function(errorCode, errorMessage) {
if (errorCode == 8) {
assert.ok(true, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
} else if (checkErrorCode(errorCode)) {
assert.ok(true, 'not support');
} else {
assert.ok(false, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
}
QUnit.start();
});
};
QUnit.asyncTest('pairingAbnormalTest001(Calling a get method that does not support.)',
DeviceProfileAbnormalTest.pairingAbnormalTest001);

/**
* 定義されていないPUTメソッドでアクセスするテストを行う。
* <h3>【HTTP通信】</h3>
* <p id='test'>
* Method: PUT<br/>
* Path: /device/pairing?serviceId=xxxx&accessToken=xxx<br/>
* </p>
* <h3>【期待する動作】</h3>
* <p id='expected'>
* ・resultに1が返ってくること。<br/>
* </p>
*/
DeviceProfileAbnormalTest.pairingAbnormalTest002 = function(assert) {
var accessToken = getCurrentAccessToken();
var serviceId = getCurrentServiceId();
var builder = new dConnect.URIBuilder();
builder.setProfile('device');
builder.setAttribute('pairing');
builder.setServiceId(serviceId);
builder.setAccessToken(accessToken);
var uri = builder.build();
dConnect.put(uri, null, null, function(json) {
assert.ok(false, 'json: ' + JSON.stringify(json));
QUnit.start();
},
function(errorCode, errorMessage) {
if (errorCode == 8) {
assert.ok(true, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
} else if (checkErrorCode(errorCode)) {
assert.ok(true, 'not support');
} else {
assert.ok(false, 'errorCode=' + errorCode + ', errorMessage=' + errorMessage);
}
QUnit.start();
});
};
QUnit.asyncTest('pairingAbnormalTest002(Calling a put method that does not support.)',
DeviceProfileAbnormalTest.pairingAbnormalTest002);
Loading