Skip to content

Commit

Permalink
- update code of time format to 24h format
Browse files Browse the repository at this point in the history
  • Loading branch information
IoTKETI committed Mar 13, 2020
1 parent ca172b7 commit 50d3d0e
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 134 deletions.
260 changes: 130 additions & 130 deletions mobius/cb.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,130 @@
/**
* Copyright (c) 2018, KETI
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**
* @file
* @copyright KETI Korea 2018, KETI
* @author Il Yeup Ahn [[email protected]]
*/

var xml2js = require('xml2js');
var xmlbuilder = require('xmlbuilder');
var util = require('util');
var ip = require('ip');
var http = require('http');
var merge = require('merge');
var moment = require('moment');

var db_sql = require('./sql_action');

function cb_create_action(connection, callback) {
var rootnm = 'cb';
var rspObj = {};
var resource_Obj = {};
resource_Obj[rootnm] = {};

var cur_d = new Date();

resource_Obj[rootnm].ty = '5';
resource_Obj[rootnm].rn = usecsebase;
resource_Obj[rootnm].pi = '';
resource_Obj[rootnm].ri = resource_Obj[rootnm].pi + '/' + resource_Obj[rootnm].rn;
resource_Obj[rootnm].ct = moment().utc().format('YYYYMMDDThhmmss');
resource_Obj[rootnm].lt = resource_Obj[rootnm].ct;
resource_Obj[rootnm].et = moment().utc().add(10, 'years').format('YYYYMMDDTHHmmss');
resource_Obj[rootnm].acpi = [];
resource_Obj[rootnm].lbl = [];
resource_Obj[rootnm].lbl[0] = resource_Obj[rootnm].rn;
resource_Obj[rootnm].at = [];
resource_Obj[rootnm].aa = [];
resource_Obj[rootnm].st = '0';
resource_Obj[rootnm].srv = [];
resource_Obj[rootnm].subl = [];

resource_Obj[rootnm].srv.push('1');
resource_Obj[rootnm].srv.push('2');
resource_Obj[rootnm].srv.push('2a');

resource_Obj[rootnm].csi = usecseid;

//resource_Obj[rootnm].srt = ty_list;
resource_Obj[rootnm].srt = ['1', '2', '3', '4', '5', '9', '10', '13', '14', '16', '17', '23'];

resource_Obj[rootnm].poa = [];
resource_Obj[rootnm].poa.push('http://' + ip.address() + ':' + usecsebaseport);
// resource_Obj[rootnm].poa.push('mqtt://' + ip.address() + ':' + use_mqtt_port + '/' + resource_Obj[rootnm].csi.replace('/', ''));
// resource_Obj[rootnm].poa.push('coap://' + ip.address() + ':' + usecsebaseport);
// resource_Obj[rootnm].poa.push('ws://' + ip.address() + ':' + usepxywsport);

resource_Obj[rootnm].nl = '';
resource_Obj[rootnm].ncp = '';
resource_Obj[rootnm].cst = '1';

db_sql.select_ri_lookup(connection, resource_Obj[rootnm].ri, function (err, results_ri) {
if(!err) {
if(results_ri.length == 1) {
db_sql.update_cb_poa_csi(connection, JSON.stringify(resource_Obj[rootnm].poa), resource_Obj[rootnm].csi, JSON.stringify(resource_Obj[rootnm].srt), resource_Obj[rootnm].ri, function (err, results) {
if (!err) {
usecseid = resource_Obj[rootnm].csi;
rspObj.rsc = '2004';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = '';
callback(rspObj);
}
else {
rspObj.rsc = '5000';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = results.message;
callback(rspObj);
}
});
}
else {
db_sql.get_sri_sri(connection, resource_Obj[rootnm].pi, function (err, results) {
if (!err) {
resource_Obj[rootnm].spi = (results.length == 0) ? '' : results[0].sri;
//resource_Obj[rootnm].sri = require('shortid').generate();
resource_Obj[rootnm].sri = '5-' + moment().utc().format('YYYYMMDDhhmmssSSS');
db_sql.insert_cb(connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
rspObj.rsc = '2001';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = '';
}
else {
rspObj.rsc = '5000';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = results.message;
}
callback(rspObj);
});
}
});
}
}
else {
rspObj.rsc = '5000';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = results_ri.message;
callback(rspObj);
}
});
}

exports.create = function(connection, callback) {
db_sql.set_hit(connection, '', function (err, results) {
cb_create_action(connection, function(rspObj) {
callback(rspObj);
});
});


};
/**
* Copyright (c) 2018, KETI
* All rights reserved.
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**
* @file
* @copyright KETI Korea 2018, KETI
* @author Il Yeup Ahn [[email protected]]
*/

var xml2js = require('xml2js');
var xmlbuilder = require('xmlbuilder');
var util = require('util');
var ip = require('ip');
var http = require('http');
var merge = require('merge');
var moment = require('moment');

var db_sql = require('./sql_action');

function cb_create_action(connection, callback) {
var rootnm = 'cb';
var rspObj = {};
var resource_Obj = {};
resource_Obj[rootnm] = {};

var cur_d = new Date();

resource_Obj[rootnm].ty = '5';
resource_Obj[rootnm].rn = usecsebase;
resource_Obj[rootnm].pi = '';
resource_Obj[rootnm].ri = resource_Obj[rootnm].pi + '/' + resource_Obj[rootnm].rn;
resource_Obj[rootnm].ct = moment().utc().format('YYYYMMDDTHHmmss');
resource_Obj[rootnm].lt = resource_Obj[rootnm].ct;
resource_Obj[rootnm].et = moment().utc().add(10, 'years').format('YYYYMMDDTHHmmss');
resource_Obj[rootnm].acpi = [];
resource_Obj[rootnm].lbl = [];
resource_Obj[rootnm].lbl[0] = resource_Obj[rootnm].rn;
resource_Obj[rootnm].at = [];
resource_Obj[rootnm].aa = [];
resource_Obj[rootnm].st = '0';
resource_Obj[rootnm].srv = [];
resource_Obj[rootnm].subl = [];

resource_Obj[rootnm].srv.push('1');
resource_Obj[rootnm].srv.push('2');
resource_Obj[rootnm].srv.push('2a');

resource_Obj[rootnm].csi = usecseid;

//resource_Obj[rootnm].srt = ty_list;
resource_Obj[rootnm].srt = ['1', '2', '3', '4', '5', '9', '10', '13', '14', '16', '17', '23'];

resource_Obj[rootnm].poa = [];
resource_Obj[rootnm].poa.push('http://' + ip.address() + ':' + usecsebaseport);
// resource_Obj[rootnm].poa.push('mqtt://' + ip.address() + ':' + use_mqtt_port + '/' + resource_Obj[rootnm].csi.replace('/', ''));
// resource_Obj[rootnm].poa.push('coap://' + ip.address() + ':' + usecsebaseport);
// resource_Obj[rootnm].poa.push('ws://' + ip.address() + ':' + usepxywsport);

resource_Obj[rootnm].nl = '';
resource_Obj[rootnm].ncp = '';
resource_Obj[rootnm].cst = '1';

db_sql.select_ri_lookup(connection, resource_Obj[rootnm].ri, function (err, results_ri) {
if(!err) {
if(results_ri.length == 1) {
db_sql.update_cb_poa_csi(connection, JSON.stringify(resource_Obj[rootnm].poa), resource_Obj[rootnm].csi, JSON.stringify(resource_Obj[rootnm].srt), resource_Obj[rootnm].ri, function (err, results) {
if (!err) {
usecseid = resource_Obj[rootnm].csi;
rspObj.rsc = '2004';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = '';
callback(rspObj);
}
else {
rspObj.rsc = '5000';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = results.message;
callback(rspObj);
}
});
}
else {
db_sql.get_sri_sri(connection, resource_Obj[rootnm].pi, function (err, results) {
if (!err) {
resource_Obj[rootnm].spi = (results.length == 0) ? '' : results[0].sri;
//resource_Obj[rootnm].sri = require('shortid').generate();
resource_Obj[rootnm].sri = '5-' + moment().utc().format('YYYYMMDDHHmmssSSS');
db_sql.insert_cb(connection, resource_Obj[rootnm], function (err, results) {
if (!err) {
rspObj.rsc = '2001';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = '';
}
else {
rspObj.rsc = '5000';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = results.message;
}
callback(rspObj);
});
}
});
}
}
else {
rspObj.rsc = '5000';
rspObj.ri = resource_Obj[rootnm].ri;
rspObj = results_ri.message;
callback(rspObj);
}
});
}

exports.create = function(connection, callback) {
db_sql.set_hit(connection, '', function (err, results) {
cb_create_action(connection, function(rspObj) {
callback(rspObj);
});
});


};

8 changes: 4 additions & 4 deletions mobius/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ function build_resource(request, response, callback) {
return;
}

resource_Obj[rootnm].rn = request.ty + '-' + moment().utc().format('YYYYMMDDhhmmssSSS');
resource_Obj[rootnm].rn = request.ty + '-' + moment().utc().format('YYYYMMDDHHmmssSSS');
if (request.headers['x-m2m-nm'] != null && request.headers['x-m2m-nm'] != '') {
resource_Obj[rootnm].rn = request.headers['x-m2m-nm'];
}
Expand All @@ -849,7 +849,7 @@ function build_resource(request, response, callback) {
resource_Obj[rootnm].ty = request.ty;
resource_Obj[rootnm].pi = url.parse(request.url).pathname;
resource_Obj[rootnm].ri = resource_Obj[rootnm].pi + '/' + resource_Obj[rootnm].rn;
resource_Obj[rootnm].ct = moment().utc().format('YYYYMMDDThhmmss');
resource_Obj[rootnm].ct = moment().utc().format('YYYYMMDDTHHmmss');
resource_Obj[rootnm].lt = resource_Obj[rootnm].ct;
resource_Obj[rootnm].st = 0;
resource_Obj[rootnm].et = moment().utc().add(2, 'years').format('YYYYMMDDTHHmmss');
Expand Down Expand Up @@ -1035,7 +1035,7 @@ exports.create = function (request, response, callback) {
var resource_Obj = request.resourceObj;

resource_Obj[rootnm].spi = request.targetObject[Object.keys(request.targetObject)[0]].sri;
resource_Obj[rootnm].sri = request.ty + '-' + moment().utc().format('YYYYMMDDhhmmssSSS');
resource_Obj[rootnm].sri = request.ty + '-' + moment().utc().format('YYYYMMDDHHmmssSSS');

if(resource_Obj[rootnm].ty == 2) {
resource_Obj[rootnm].sri = resource_Obj[rootnm].aei;
Expand Down Expand Up @@ -2088,7 +2088,7 @@ function update_resource(request, response, callback) {
update_body(rootnm, body_Obj, resource_Obj); // (attr == 'aa' || attr == 'poa' || attr == 'lbl' || attr == 'acpi' || attr == 'srt' || attr == 'nu' || attr == 'mid' || attr == 'macp')

resource_Obj[rootnm].st = (parseInt(resource_Obj[rootnm].st, 10) + 1).toString();
resource_Obj[rootnm].lt = moment().utc().format('YYYYMMDDThhmmss');
resource_Obj[rootnm].lt = moment().utc().format('YYYYMMDDTHHmmss');

if (body_Obj[rootnm].et == '') {
if (body_Obj[rootnm].et < resource_Obj[rootnm].ct) {
Expand Down

0 comments on commit 50d3d0e

Please sign in to comment.