forked from beagleboard/cloud9-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PocketBeagle/TechLab: add rpmsg example
- Loading branch information
Jason Kridner
committed
Jan 29, 2020
1 parent
7bce79f
commit 85fe903
Showing
3 changed files
with
60 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env node | ||
var fs = require('fs'); | ||
var os = require('os'); | ||
var process = require('process'); | ||
|
||
var buffer = Buffer.alloc(16); | ||
|
||
fs.open("/dev/rpmsg_pru30", "r+", null, onOpen); | ||
|
||
function onOpen(err, fd) { | ||
if (err) { | ||
console.log("Unble to open /dev/rpmsg_pru30"); | ||
os.exit(-1); | ||
} | ||
fs.read(fd, buffer, 0, 10, null, onData); | ||
|
||
process.stdin.setEncoding('utf8'); | ||
process.stdin.on('readable', onStdin); | ||
console.log("Type red, green, blue or white and press <ENTER>"); | ||
|
||
function onStdin(err) { | ||
var chunk; | ||
if (err) { | ||
console.log("Error reading from /dev/rpmsg_pru30"); | ||
os.exit(-1); | ||
} | ||
while ((chunk = process.stdin.read()) !== null) { | ||
fs.write(fd, chunk); | ||
} | ||
} | ||
|
||
function onData(err, bytes, data) { | ||
if(err) { | ||
console.log("Error reading from /dev/rpmsg_pru30"); | ||
os.exit(-1); | ||
} | ||
console.log('response: ' + data.toString('ascii')); | ||
fs.read(fd, buffer, 0, 10, null, onData); | ||
} | ||
} | ||
|
This file contains 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
This file contains 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