conplier_try

dev
IoTcat 3 years ago
parent 593c1f0dbd
commit 735d91f723
  1. 1
      src/cli/compiler/good.lua
  2. 1
      src/cli/compiler/good3.lua
  3. 1
      src/cli/compiler/good4.lua
  4. 153
      src/cli/compiler/test.js
  5. 15
      src/director/index.js
  6. 2
      src/director/modules/log.js
  7. 2
      src/director/modules/node.js
  8. 2
      src/drivers/nodemcu/lua/config.json

@ -0,0 +1 @@
gpio.mode(3,gpio.INPUT);tmr.create():alarm(100, tmr.ALARM_AUTO, function()a66=gpio.read(3);if not (f_a66==a66) then msg.send('good3','a66',a66);msg.send('good4','a66',a66);end;f_a66=a66; end);

@ -0,0 +1 @@
gpio.mode(4,gpio.OUTPUT);a66=0;tmr.create():alarm(100, tmr.ALARM_AUTO, function()gpio.write(4,a66); end);msg.onSend('a66',function(f,b) a66=b; end);

@ -0,0 +1 @@
gpio.mode(4,gpio.OUTPUT);a66=0;tmr.create():alarm(100, tmr.ALARM_AUTO, function()gpio.write(4,a66); end);msg.onSend('a66',function(f,b) a66=b; end);

@ -0,0 +1,153 @@
const md5 = (str) => {
let hash = require('crypto').createHash('sha256');
hash.update(str.toString());
return hash.digest('hex');
}
const g = () => {
let s = md5(Math.random());
for(let index in s.split('')){
if(s.split('')[index] != 0 && !Number(s.split('')[index])) {return s.substring(Number(index), Number(index)+3);}
}
}
const wiot = {
INPUT: 'gpio.INPUT',
OUTPUT: 'gpio.OUTPUT',
__: {
},
node: {
nodemcu: (nid) => {
wiot.__[nid] = {
head: [],
body: [],
loop: [],
footer: []
}
return {
D1: 1,
D2: 2,
D3: 3,
D4: 4,
nid: nid
}
}
},
udp: {
gpio: (mode, pin, wire, node) => {
let o = {
udp: 'pin',
node: node,
mode, mode,
pin: pin
};
wiot.__[node.nid].head.push(`gpio.mode(${pin},${mode});`);
if(mode == wiot.INPUT){
wiot.__[node.nid].loop.push(`${wire.id}=gpio.read(${pin});`);
o.output = wire;
wire.input.push(o);
}
if(mode == wiot.OUTPUT){
wiot.__[node.nid].head.push(`${wire.id}=0;`);
wiot.__[node.nid].loop.push(`gpio.write(${pin},${wire.id});`);
o.input = wire;
wire.output.push(o);
}
wire.generate(wire);
return o;
},
trigger: (wire, node) => {
},
wire: () => {
let id = g();
return {
upd: 'wire',
id: id,
input: [],
output: [],
generate: (wire) => {
let nodes_input = [],
nodes_output = [];
wire.input.forEach(udp => {
if(nodes_input.indexOf(udp.node) == -1){
nodes_input.push(udp.node);
}
});
wire.output.forEach(udp => {
if(nodes_output.indexOf(udp.node) == -1){
nodes_output.push(udp.node);
}
});
wiot.udp.channel(wire, nodes_input, nodes_output);
}
}
},
channel: (wire, nodes_input, nodes_output) => {
nodes_output.forEach(node_output => {
let s = `msg.onSend('${wire.id}',function(f,b) ${wire.id}=b; end);`;
if(wiot.__[node_output.nid].footer.indexOf(s) == -1) wiot.__[node_output.nid].footer.push(s);
});
nodes_input.forEach(node_input => {
let s1 = `if not (f_${wire.id}==${wire.id}) then `;
let s3 = `end;f_${wire.id}=${wire.id};`;
if(wiot.__[node_input.nid].loop.indexOf(s1) != -1) wiot.__[node_input.nid].loop.splice(wiot.__[node_input.nid].loop.indexOf(s1), 1);
if(wiot.__[node_input.nid].loop.indexOf(s3) != -1) wiot.__[node_input.nid].loop.splice(wiot.__[node_input.nid].loop.indexOf(s3), 1);
wiot.__[node_input.nid].loop.push(s1);
nodes_output.forEach(node_output => {
let s2 = `msg.send('${node_output.nid}','${wire.id}',${wire.id});`;
if(wiot.__[node_input.nid].loop.indexOf(s2) != -1) wiot.__[node_input.nid].loop.splice(wiot.__[node_input.nid].loop.indexOf(s2), 1);
wiot.__[node_input.nid].loop.push(s2);
})
wiot.__[node_input.nid].loop.push(s3);
});
}
}
}
let nodemcu1 = wiot.node.nodemcu('good');
let nodemcu2 = wiot.node.nodemcu('good3');
let nodemcu3 = wiot.node.nodemcu('good4');
let w1 = wiot.udp.wire()//,
// w2 = wiot.udp.wire();
//let buf = wiot.udp.buffer(w1, w2, nodemcu1);
let pin1 = wiot.udp.gpio(wiot.INPUT, nodemcu1.D3, w1, nodemcu1);
let pin2 = wiot.udp.gpio(wiot.OUTPUT, nodemcu2.D4, w1, nodemcu2);
let pin3 = wiot.udp.gpio(wiot.OUTPUT, nodemcu3.D4, w1, nodemcu3);
const fs = require('fs');
Object.keys(wiot.__).forEach(nid => {
let s = '';
let seg = wiot.__[nid];
seg.head.forEach(item => s += item);
seg.body.forEach(item=> s += item);
s += 'tmr.create():alarm(100, tmr.ALARM_AUTO, function()';
seg.loop.forEach(item => s += item);
s += ' end);';
seg.footer.forEach(item => s += item);
fs.writeFileSync('./'+nid+'.lua', /*new Buffer(*/s/*).toString('base64')*/);
});

@ -33,7 +33,20 @@ setInterval(async ()=>{
});
if(online.some(nid => OnlineBoard.indexOf(nid) == -1)){
await ns.set(await ns.get(online))
await ns.set(await ns.get(online, {
'good': {
'good3': {
port: 22,
ip: '111.222.333.44'
}
},
'good3': {
'good': {
port: 22,
ip: '111.222.333.44'
}
},
}))
}

@ -16,7 +16,7 @@ module.exports = (node, nodetable) => {
console: { type: 'console' }
},
categories: {
flow: {appenders: ['flow'], level: 'info' },
flow: {appenders: ['flow', 'console'], level: 'info' },
access: { appenders: ['access'], level: 'info' },
event: {appenders: ['event', 'console'], level: 'info' },
nslog: {appenders: ['nslog', 'console'], level: 'info' },

@ -213,7 +213,7 @@ module.exports = (logger, nodetable) => {
}
});
restartTime = new Date().valueOf();
counter = 100;
//counter = 100;
}
timer();
counter --;

@ -1,5 +1,5 @@
{
"nid": "good3",
"nid": "good",
"wifi": {
"ssid": "yimian-iot",
"pwd": "1234567890."

Loading…
Cancel
Save