UNPKG

ibctminer

Version:

```js const IntMiner = require('./src'); const Debug = require('./src/log')(); const fs = require('fs'); const COMP = '[SIPC]';

112 lines (102 loc) 3.14 kB
const sipc = require('./src/miner/simplenode.js'); const fs = require('fs'); opt = require('node-getopt').create([ ['m' , null , 'mode'], ['b' , null , 'burn'], ['q' , null, 'query'], ['j' , null , 'work'], ['r' , null , 'reboot'], ['y' , null , 'nonce'], ['s' , null , 'set'], ['g' , null , 'get'], ['l' , null , 'led'], ['L' , null , 'loop'] ]) .bindHelp() .parseSystem(); console.info({argv: opt.argv, options: opt.options}); const sncfg = { model: "simplenode", algo: "scrypt", varity: 0x30, targetFreq: 700, //MHz targetVoltage: 750, //mv targetTemp: 65, warnTemp: 115, offTemp: 125 }; var payload = [ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x24, 0x9a, 0x19, 0xff, 0xff, 0x00, 0x17, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x01, ]; const miner = sipc({ algo: 'scrypt', devPath: '/dev/ttyACM0', variety: 0x30, }); var sleep = function (time) { return new Promise(function (resolve, reject) { setTimeout(function () { resolve('ok'); }, time); }) }; var loop = async function () { console.log('start'); var n = 0; while (1) { await miner.snGetStaticInfo('simplenode'); await miner.snSetHWParams(0x30,700,750); await miner.snGetStaticInfo('simplenode'); await sleep(3000); await miner.snGetStaticInfo('simplenode'); await miner.snSetHWParams(0,0,0); n++; console.log('cnt', n); } console.log('end'); }; if (opt.options.m) { miner.snSetBootMode(); } else if (opt.options.b) { console.log('Burn Image') fs.readFile('./recovery.bin', (err, data) => { if (err) { console.log(err) } else { miner.burnFirmware(data.slice(64), function (err, data) { if (err) { console.log(err) return } console.log('Burn ', (data * 100).toFixed(1), '%') if ((data * 100).toFixed(1) === '100.0') { console.log('Burn Complete') } }) } }) } else if (opt.options.q) { miner.snGetStaticInfo('simplenode'); } else if (opt.options.s) { if (parseInt(opt.argv[0])) miner.snSetHWParams(0x30,700,750); else miner.snSetHWParams(0,0,0); } else if (opt.options.r) { miner.rebootDev(); } else if (opt.options.j) { data = Buffer.alloc(80); data = Buffer.from(payload); miner.snWriteJob(0xc,0x02ffffff,data); } else if (opt.options.l) { if (opt.argv.length > 0) { var enable = parseInt(opt.argv[0]) ? true :false; miner.setLed(enable); } } else if (opt.options.L) { loop(); }