Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(protocol): add support for CFSolo serial ports and CFMini on-board serial port #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Demo/cflink-simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var CFL = {
CF.unwatch(CF.FeedbackMatchedEvent, this.system, this.feedback);
this.watches = [];
this.watchid = 1;
//this.system = "";
//this.feedback = "";
this.system = null;
this.feedback = null;
},

watch: function (array) {
Expand Down Expand Up @@ -80,7 +80,7 @@ var CFL = {
port: function (port) {
if (arguments.length == 2) port = [arguments[0], arguments[1]];
if (port instanceof Array) return "M" + port[0] + "|P0" + port[1];
if (port instanceof Number) return ("P0" + port).substr(0, 3);
if (port instanceof Number || typeof port === 'number') return ("P0" + port).substr(0, 3);
var a = port.split('|');
if (a.length === 1) return parseInt(port.substring(1), 10); // "P01" -> 1
return [parseInt(a[0].substring(1), 10), parseInt(a[1].substring(1), 10)];
Expand All @@ -89,7 +89,7 @@ var CFL = {
_packetRegex: function(id,cmd,payload) {
id = (id == null || id === "") ? "[\\s\\S]" : "\\"+String.fromCharCode(parseInt(id,16));
payload = (payload == null || payload === "") ? "" : payload.replace("|","\\|");
return new RegExp("^\xF2" + id + "\xF3" + cmd + "\xF4" + payload);
return new RegExp("^\xF2" + '(' +id + '|\xFF)' + "\xF3" + cmd + "\xF4" + payload); // TODO: fix hack here around FF.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ugly, but I'm not sure how else to handle the fact that the on-board serial port in a CFMini sends back FF instead of the CFLink ID. Maybe you can issue a firmware update?

},

/*-----------------------------------------------
Expand All @@ -108,14 +108,19 @@ var CFL = {

watchSerial: function (id, module, callback) {
var orig = "COM";

if (module == null || module === "" || module.indexOf('|') === -1) {
orig = "(?!COM)(...)";
}

if (module == null || module === "") {
orig = "(?!COM)(...)";
module = "";
}

var self = this;
return this.watch([ function (watchID, message) {
var m = self.unpack(message), origin = "", data = m[4];
if (m[2] == "COM") {
if (m[2] == "COM" || m[2] == "SOL") {
var idx = data.indexOf(':');
origin = data.substr(0, idx);
data = data.substr(idx + 1);
Expand Down Expand Up @@ -255,8 +260,7 @@ var CFL = {
*-----------------------------------------------
*/
sendIR: function (id, port, format, data) {
//CF.log(id + " TIRXSND" + port + ":" + format + ":" + data);
this.message(id, "TIRXSND", port + ":" + format + ":" + data);
this.message(id, "TCFXSND", port + ":" + format + ":" + data);
},

watchIR: function (id, port, callback) {
Expand Down