Skip to content

Commit

Permalink
Merge pull request #63 from Trakkasure/master
Browse files Browse the repository at this point in the history
New release 2.5.6
  • Loading branch information
Trakkasure authored Nov 5, 2017
2 parents 4d54ef7 + 0dd919f commit f8ebf61
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1,299 deletions.
31 changes: 31 additions & 0 deletions examples/testCount.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

var MikroNode = require('../dist/mikronode.js');
// Create API instance to a host.
var device = new MikroNode('10.10.10.10');
// device.setDebug(MikroNode.DEBUG);

// Connect to MikroTik device
device.connect().then(([login])=>login('admin','password')).then(conn=>{
// When all channels are marked done, close the connection.
console.log('connected');

conn.closeOnDone(true);

var channel1=conn.openChannel();
channel1.closeOnDone(true);

console.log('going write 1');

// get only a count of the addresses.
channel1.write('/ip/address/print',{
'=count-only=':''
}).then(data=>{
console.log("Done",JSON.stringify(data));
}).catch(error=>{
console.log("Error result ",error);
});
console.log('Wrote');
}
).catch(error=>{
console.log("Error logging in ",error);
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "mikronode",
"description": "Mikrotik API implemented in Node",
"version": "2.3.5",
"version": "2.3.6",
"author": "Brandon Myers <[email protected]>",
"scripts": {
"prebuild": "pegjs src/parser.g",
"build": "webpack --color --progress",
"dev": "webpack --watch --color -d --progress",
"compile:debug": "f(){ webpack --entry=\"$1\" --output-path=./.compiled --output-filename=debug.js; };f",
Expand Down
20 changes: 10 additions & 10 deletions src/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,17 @@ export default class Channel extends events.EventEmitter {
.do(e=>this.debug>=DEBUG.SILLY&&console.log('Channel (%s)::%s Sentence on channel ',e.tag))
.flatMap(data=>{
const cmd=this.getCommandId(data);
return Observable.of({...data,tag:data.tag.substring(0,data.tag.lastIndexOf('-')),cmd:(this.getCommand(cmd)||{cmd:null}).cmd});
const d={...data,tag:data.tag.substring(0,data.tag.lastIndexOf('-')),cmd:(this.getCommand(cmd)||{cmd:null}).cmd};
if (d.type==EVENT.DONE_RET||d.type===EVENT.DONE_RET_TAG) {
d.data=d.data[0];
const d2={...d,type:EVENT.DATA};
return Observable.of(d2).concat(Observable.of(d));
}
return Observable.of(d);
}).share();

// Stream for sentences with data.
this.data = this.createStream(this.read,[EVENT.DATA,EVENT.DONE_RET]).share();
this.data = this.createStream(this.read,[EVENT.DATA,EVENT.DATA_RET,EVENT.DATA_RET_TAG]).share();

// Stream for signaling when done.
this.done = this.createStream(this.read,[EVENT.DONE,EVENT.DONE_RET,EVENT.DONE_TAG]).share();
Expand Down Expand Up @@ -349,17 +355,11 @@ export default class Channel extends events.EventEmitter {
}
p.reject(error);
this.emit('trap',error);
},null,
// this should happen for every command
()=>{
this.debug>=DEBUG.SILLY&&console.log("*** Register Command: complete from trap", commandId);
});
} else
return o;
},null);
} else return o;
},{})

const isListen=command.split('/').indexOf('listen')>0;
const data=
this.data
.filter(data=>data.cmd.id===id)
.takeUntil(race)
Expand Down
16 changes: 8 additions & 8 deletions src/parser.g
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packet
/ re s tag:tag { return {type: "re", tag:tag} }
/ re s data:data+ tag:tag { return {type: "data", data:data, tag:tag} }
/ re s data:data+ { return {type: "data", data:data} }
/ re s { return {type: "re"} }
/ re:re s { return {type: "re"} }
/ e:end s {return e}

re
Expand All @@ -24,13 +24,13 @@ value
/ v:[\r\n\0] {return ''}

end
= f:fatal {return {type: "fatal", data:f } }
/ t:trap {return t}
/ "!done" s "=ret=" ret:[a-z0-9]+ {return {type: "done_ret", data:ret.join('')}}
/ "!done" s tag:tag "=ret=" ret:ns {return {type: "done_ret", tag: tag, data:ret.join('')}}
/ "!done" s tag:tag {return {type: "done_tag", tag:tag}}
/ "!done" {return {type: "done" }}
/ tag:tag {return {type: "tag", tag:tag }}
= f:fatal {return {type: "fatal", data:f } }
/ t:trap {return t}
/ "!done" s "=ret=" ret:[a-zA-Z0-9]+ {return {type: "done_ret", data:ret.join('')}}
/ "!done" s tag:tag s "=ret=" ret:[a-zA-Z0-9]+ {return {type: "done_ret", tag:tag, data:ret}}
/ "!done" s tag:tag {return {type: "done_ret", tag:tag}}
/ "!done" {return {type: "done" }}
/ tag:tag {return {type: "tag", tag:tag }}

tag
= ".tag=" id:[a-zA-Z_\-0-9]+ colon subid:[0-9]+ s {return id.join('')+":"+subid.join('')}
Expand Down
Loading

0 comments on commit f8ebf61

Please sign in to comment.