Skip to content

Commit

Permalink
Merge pull request #75 from axians/dev
Browse files Browse the repository at this point in the history
2020-09-01 => 3.5.0
  • Loading branch information
wmmihaa authored Sep 1, 2020
2 parents 02d45e0 + ba55ccd commit fa5676b
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 43 deletions.
28 changes: 14 additions & 14 deletions lib/MicroServiceBusHost.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,18 +902,18 @@ function MicroServiceBusHost(settingsHelper) {
function OnStartTerminal(connid, user) {
log(`Starting terminal for ${user}`);
var pty, os;
try{
try {
pty = require('node-pty');
}
catch(ex){
_client.invoke('terminalError', `Terminal dependancies are not yet installed. Please try again in a couple of minutes.`,connid);
util.addNpmPackage('node-pty',(err)=>{
if(err){
catch (ex) {
_client.invoke('terminalError', `Terminal dependancies are not yet installed. Please try again in a couple of minutes.`, connid);
util.addNpmPackage('node-pty', (err) => {
if (err) {
log(`Unable to install terminal dependancies. Error ${err}`);
}
else{
else {
log(`Terminal dependancies installed successfully.`);
_client.invoke('terminalReady',connid);
_client.invoke('terminalReady', connid);
}
});
return;
Expand All @@ -935,17 +935,17 @@ function MicroServiceBusHost(settingsHelper) {
_ptyProcess.on('data', function (data) {
_client.invoke('terminalData', data, connid);
});
_client.invoke('terminalReady',connid);
_client.invoke('terminalReady', connid);
log(`Terminal started`);
}
function OnStopTerminal() {
if(_ptyProcess){
if (_ptyProcess) {
_ptyProcess.kill();
_ptyProcess = null;
log(`terminal closed for ${_ptyProcessUser}`);
_ptyProcessUser = null;
}

}
}
function OnTerminalCommand(command) {
_ptyProcess.write(command);
Expand Down Expand Up @@ -1441,9 +1441,9 @@ function MicroServiceBusHost(settingsHelper) {
});
_client.on('executeScript', function (patchScript, connid) {
let parameters = "";
if(path.basename(patchScript).indexOf(" ") > 0) { // Check for parameters
parameters= patchScript.split(" ").splice(1).join(" ");
patchScript = patchScript.split(" ")[0];
if (path.basename(patchScript).indexOf(" ") > 0) { // Check for parameters
parameters = patchScript.split(" ").splice(1).join(" ");
patchScript = patchScript.split(" ")[0];
}

OnExecuteScript(patchScript, parameters, connid);
Expand Down
68 changes: 45 additions & 23 deletions lib/MicroServiceBusNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ function MicroServiceBusNode(settingsHelper) {
self.onLog();
self.onLog("Restarting COM".yellow);
self.onLog();
com.Stop(()=>{
com.Stop(() => {
self.onLog("COM stopped".yellow);
com.Start(()=>{
com.Start(() => {
self.onLog("COM started".green);
callback();
})
Expand Down Expand Up @@ -684,12 +684,12 @@ function MicroServiceBusNode(settingsHelper) {
MicroServiceBusNode.prototype.SignIn = function (newNodeName, temporaryVerificationCode, useMacAddress, recoveredSignIn, useAssert) {

if (useMacAddress) {
try{
try {
let macAddress = util.getMacs();
self.onLog(`mac: ${macAddress}`);
self.onCreateNodeFromMacAddress(macAddress.join(','));
}
catch(macErr){
catch (macErr) {
self.onLog('Unable to fetch mac address.');
}
}
Expand Down Expand Up @@ -734,23 +734,45 @@ function MicroServiceBusNode(settingsHelper) {
let ImeiLoginHandler = require('./ImeiLoginHandler');
let imeiLoginHandler = new ImeiLoginHandler(this.settingsHelper);
imeiLoginHandler.tryGetIMEI(function (imei) {
var hostData = {
id: "",
connectionId: "",
Name: settingsHelper.settings.nodeName,
machineName: settingsHelper.settings.machineName,
imei: imei,
OrganizationID: settingsHelper.settings.organizationId,
npmVersion: self.nodeVersion,
sas: settingsHelper.settings.sas,
recoveredSignIn: recoveredSignIn
};

self.onSignedIn(hostData);

if (settingsHelper.settings.debug != null && settingsHelper.settings.debug && !recoveredSignIn) {// jshint ignore:line
self.onLog("Waiting for signin response".grey);
}
let RaucHandler = require('./RaucHandler');
let raucHandler = new RaucHandler();
var firmwareState = {};
raucHandler.raucGetSlotStatus((err, raucState) => {

if (!err) {
let arrayToObject = (array) =>
array.reduce((obj, item) => {
obj[item.key] = item.val
return obj
}, {})
firmwareState = {
rootfs0: arrayToObject(raucState.rootfs0),
rootfs1: arrayToObject(raucState.rootfs1)
};
}
require('network').get_interfaces_list((err, nw) => {
var hostData = {
id: "",
connectionId: "",
Name: settingsHelper.settings.nodeName,
machineName: settingsHelper.settings.machineName,
imei: imei,
OrganizationID: settingsHelper.settings.organizationId,
npmVersion: self.nodeVersion,
sas: settingsHelper.settings.sas,
recoveredSignIn: recoveredSignIn,
ipAddresses: nw.map(i => i.ip_address).filter(i => i),
macAddresses: nw.map(i => i.mac_address).filter(i => i),
firmwareState: firmwareState
};
self.onSignedIn(hostData);

if (settingsHelper.settings.debug != null && settingsHelper.settings.debug && !recoveredSignIn) {// jshint ignore:line
self.onLog("Waiting for signin response".grey);
}
})
});

});
}
};
Expand Down Expand Up @@ -1280,7 +1302,7 @@ function MicroServiceBusNode(settingsHelper) {
if (!com.IsConnected()) {
return;
}
_persistHelper.storage.forEach(async function(item) {
_persistHelper.storage.forEach(async function (item) {
let data = item.value;
if (item.key.startsWith('_h_')) { // history
}
Expand All @@ -1302,7 +1324,7 @@ function MicroServiceBusNode(settingsHelper) {
}
});


}
catch (ex) {
self.onLog(`Unable to restore persisted messages (${ex})`.red);
Expand Down
5 changes: 5 additions & 0 deletions lib/RaucHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ function RaucHandler(){
});
};
RaucHandler.prototype.raucGetSlotStatus = function (callback) {

try {
if (process.env.MSB_PLATFORM !== "YOCTO" && process.env.MSB_PLATFORM !== "AZUREIOTEDGE") {
callback("DBUS not installed");
return;
}
const dbus = require('dbus-native');
if (!dbus) {
callback("DBUS not installed");
Expand Down
10 changes: 5 additions & 5 deletions lib/protocols/AZUREIOT.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function AZUREIOT(nodeName, connectionSettings) {
var tracker;
var tokenRefreshTimer;
var tokenRefreshInterval = (connectionSettings.tokenLifeTime * 60 * 1000) * 0.9;
var npmPackage = "azure-iot-device@1.12.0";
var npmPackage = "azure-iot-device@1.17.1";

this.startInProcess = false;
this.deviceClient;
Expand All @@ -53,11 +53,11 @@ function AZUREIOT(nodeName, connectionSettings) {
switch (connectionSettings.communicationProtocol) {
case "MQTT":
case "MQTT-WS":
npmPackage = "azure-iot-common@1.11.2,azure-iot-device@1.12.2,azure-iot-device-mqtt@1.11.2";
npmPackage = "azure-iot-common@1.12.5,azure-iot-device@1.17.1,azure-iot-device-mqtt@1.15.1";
break;
case "AMQP":
case "AMQP-WS":
npmPackage = "azure-iot-common@1.11.2,azure-iot-device@1.12.2,azure-iot-device-amqp@1.11.2";
npmPackage = "azure-iot-common@1.12.5,azure-iot-device@1.17.1,azure-iot-device-amqp@1.13.1";
break;
default:
break;
Expand Down Expand Up @@ -209,7 +209,7 @@ function AZUREIOT(nodeName, connectionSettings) {
}
else {
self.onQueueDebugCallback("AZURE IoT: Device twin is ready");

callback();
twin.on('properties.desired', function (desiredChange) {
// Incoming state
self.onQueueDebugCallback("AZURE IoT: Received new state");
Expand All @@ -221,7 +221,7 @@ function AZUREIOT(nodeName, connectionSettings) {
self.onStateReceivedCallback(self.currentState);
if (self.startInProcess) {
self.startInProcess = false;
callback();
//callback();
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@
"lint": "jshint Utils.js",
"test": "nyc --reporter=html --reporter=text mocha"
},
"version": "3.4.1"
"version": "3.5.0"
}

0 comments on commit fa5676b

Please sign in to comment.