Created
February 13, 2018 14:10
-
-
Save IvanSanchez/0ad8008789a263f142b027d2566e18ff to your computer and use it in GitHub Desktop.
RTT logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jprog = require('pc-nrfjprog-js'); | |
const rtt = jprog.RTT; | |
const debug = require('debug'); | |
function rttReadLoop(sn, ch, size, log){ | |
rtt.read(ch, size, (err, str)=>{ | |
if (err) { | |
log(err); | |
} else if (str) { | |
log(str); | |
rttReadLoop(sn, ch, size, log); | |
} else { | |
setTimeout(()=>{ | |
rttReadLoop(sn, ch, size, log) | |
}, 5); | |
} | |
}); | |
} | |
module.exports = new Promise((res, rej)=>{ | |
jprog.getSerialNumbers((err, sns)=>{ | |
if (!sns || !sns.length) { | |
// return rej('No jlink probes present'); | |
return res(); | |
} | |
for (const sn of sns) { | |
jprog.getProbeInfo(sn, (err, probeInfo)=>{ | |
const probeDebug = debug('rtt:' + sn); | |
if (err) { | |
return probeDebug(err); | |
} | |
probeDebug(probeInfo.firmwareString); | |
rtt.start(sn, {}, (err, down, up)=>{ | |
probeDebug('Down channels (to probe):', down); | |
probeDebug('Up channels (from probe):', up); | |
if (!up || up.length === 0) { | |
return rej('No down channels'); | |
} | |
for (upChannel of up) { | |
const channelDebug = debug('rtt:' + sn + ':up' + upChannel.channelIndex); | |
rttReadLoop(sn, upChannel.channelIndex, upChannel.size, channelDebug); | |
// Exit after the first channel of the first probe, because of no | |
// multithreading in jprog. | |
return res(rtt); | |
} | |
// const channelDebug = debug('rtt:' + sn + ':up0'); | |
// rttReadLoop(sn, 0, 4096, channelDebug); | |
// No RTT channels on the first probe | |
return rej(); | |
}) | |
}) | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment