I’m extending a driver (tfmini) with new features. The tfmini driver is currently reading data from device and I want to be able to write data to configure it.
I have implemented a new command to be called via “nsh”:
PRINT_MODULE_USAGE_COMMAND_DESCR("command","Configure driver (require -c hexacommand as in -c 5A04015F)");
This command is similar to “tfmini start” 'tfmini stop" and “tfmini status”: it will re-use the TFMINI object allocated upon “tfmini start” and will write commands to the tfmini driver. This is simplified code example:
uint8_t mycommand; size_t mycommandlen=4; mycommand = 0x5A; mycommand = 0x04; mycommand = 0x01; mycommand = 0x5F; ret = ::write(_fd, command, framelen);
The above is failing when called via nsh like:
$> tfmini command -c 5A04015F result: fd=4 error: EBADF - Bad File Descriptor
However, I have tried to call the same “::write”, but inside the “TFMINI::collect()” method (this is where the ::read is made). The same ::write is successful in that method.
It looks like I can access the global TFMINI object and many of its parameters, but I cannot re-use the _fd parameter from this scope.
Can someone explain this? This will help me for further px4 dev…
Is there any solution to call ::write in the call stack of my “tfmini command -c 5A04015F” command line?
Tks to all!