Hi,
I have the following function:
function send_command(name, msg_class, msg_id, payload, callback = null) { log("LOG", format("call %s", name)); // Queue the callback, build the packet and send it off local command = {name=name, msg_class=msg_class, msg_id=msg_id, callback=callback}; local timer = imp.wakeup(20, function() { // The timeout has expired. Send an event. command.result <- "timeout"; fire_response(command); }.bindenv(this)); command.timer <- timer; _response_callbacks.push(command) local len = payload == null ? 0 : payload.len(); local header = format("%c%c%c%c", 0x20, len, msg_class, msg_id); server.log("this is my error?!?!?!"); server.log(header) uart_write(header, payload); }
Which is a slight variation of the send_command() function found on the BLE112 class library (being adapted for BGM113, which is what I’m using).
For the BLE112, the main difference is at this line:
local header = format(“%c%c%c%c”, (len >> 8) & 0x07, len & 0xFF, cid, cmd);
Where cid and cmd are msg_class and msg_id.
I’ve been processing most of my commands properly, see for example what happens for “system_addresss_get” command:
Notice that on the line that says “this is my error?!?!?!”, the header is being printed before calling uart_write(). A correct execution of this, ends with a response of the type:
LOG: resp system_address_get: OK
Now, applying the same methodology to “get_scan_response”, the callback is unhandled and I don’t truly know why, meaning the execution is not entirely correct, see the screenshot please:
In comparison with the previous command, when I print the header, I get 3 empty boxes. Like if the header can’t be read. I tried typing server.log(typeof header) and it says string, like it should be. But there’s something here that’s causing this event to be unhandled properly. What’s weird about it is that the message sent and the message recieved are exactly what we should expect (if we refer to this SDK).
I’m lost here, if anybody can help, I’d appreciate it.