Hi mblock developpers!
I’m talking about the development of a device (not an extension).
On my device firmware, I implemented the “ff55” communication protocol “ff55” (like for the mbot). It works, I tested it using a custom program (written in C++).
Now I’m struggling with the live mode. How can I use device.asyncReadProtocol and device.asyncWriteProtocol to read&write data using the ff55 protocol.
So first, do we need to register ff55 ? is it already defined?
I added the following code in the “common code”. But I cannot register the protocol
// enter your javascript code here
const my_ff55 = {
id: ‘ff55’, // protocol name
pack(body) { // pack data
return [0xff, 0x55].concat(body)
},
unpack() { // data unpack methods
return {
type: ‘all’, // match all following
pattern: [
{
type: ‘bytesEq’, // match following
pattern: [0xff, 0x55]
},
{
type: ‘body’ // match data body
}
]
}
}
}
and to register the protocol, I added this in the event handler
onConnect(app, device) {
// TODO
app.log(‘Start Register protocol’);
device.registProtocol(my_ff55);
app.log(‘End Register protocol’);
},
Any help is welcome!