Stream Function of Arduino equivalent in Free Rtos ESP-IDF - arduino

i am trying to find an equivalent function on ESP-IDF that will be like Stream() of arduino ,
what i am trying to do is to make an MSP function to communicate with the MSP protocol with the ESPs UART, i am using ESP-IDF and Free-Rtos in an Ubuntu environment and cmake to built
https://www.arduino.cc/reference/en/language/functions/communication/stream/
https://github.com/yajo10/MSP-Arduino/blob/master/MSP.cpp
i tryied to use std::ostringstream* but obviously doesnt make the same job

ostringstream is a specialised ostream where the "device" is a memory buffer. Stream is an unspecialised base class for a number of device sub-classes, and it is bi-directional. The standard library equivalent given a suitable stream I/O driver would be std::istream and std::ostream for input and output respectively, each opened on the specific device. In most cases you would use the derived std::ifstream and std::ofstream class s and open the device as a "file stream".
If you require an identical interface in order to use the code unmodified, then implementing Stream as a wrapper around iostream is feasible.

Related

how to implement TxDataAvailable. how to know the size of buffer to be sent to USB layer

I want to develop a serial driver using a driver kit framework.I am trying to override IOUserserial class methods.But i don't know how to get the size of buffer to be sent to USB layer using TXDataAvailable() and RXDataAvailable() functions? Any reference code will be helpful.

Using Gattlib package to Write without response to BLE device- RN4871

I am trying to control an LED via RN4871 BLE from microchip (http://ww1.microchip.com/downloads/en/DeviceDoc/50002466B.pdf) and I would like to provide brief pulses (below 10ms).
For this purpose I installed gattlib package for C from https://github.com/labapart/gattlib
First on my RN4871 side I define a characteristic with Write property (Write value of characteristic with acknowledgment from client to server) and using the read_write.c example from the library works just fine.
However, since I want to have a fast communication to provide short pulses of LED then I have to use write without response function. On my BLE device side, I create only one characteristic with the property of "Write without response" and associate the digital out with the UUID handle.
PS,59c88760536411e7b114b2f933d5fe66
PC,59c889e0536411e7b114b2f933d5fe66,06,01
and for the script:
#PW_ON
SHW,0072,18
#CONN
|O,08,%0072
Now when I use the example from the library (nordic_UART) to have write without response, it fails. I removed the parts for notify and rx. I am only using the tx uuid.
My question is more on the basic level, am I following the right direction for configuring my BLE device for write without response? Should I add additional characteristics (like notify)? Or the problem is how I am managing the gattlib package examples?

How does a kernel driver talk with another device?

I have an FPGA board with unix-based firmware. I need write out the program to run on this firmware that will send commands to some devices via I2C bus and will receive responses. I use for this special character file in Unix that i map in my program and write to it special commands & read from it responses. Each memory area in this mapped memory corresponds specific register of the FPGA which specified in Unix-based firmware (as i understand).
So, the question is the next one. As i understand, when i write some command to that mapped memory region of the special character file the kernel calls certain driver to handle bytes that I've written and send them through I2C bus (for example). Am I right? If so, is there some guarantee that the response from that device will be buffered and I will be able to read it from the mapped region in any time? Or does it depend on implementation specific driver?
I'm sorry if question is not clear some way, I am a newbie in this stuff.

Find Serial Buffer Size of Converter

I'm using an FTDI USB-to-Serial converter on linux. I'm writing an application that implements the standard functionality of changing settings like baud rate, etc... The only thing that I'm not sure how to get is the buffer size, e.g. if the user wants to know.
For example in the javax.comm SerialPort API there's a method getInputBufferSize(), so I thought there must be a way to check this on the device being used. So if I'm using a USB-to-Serial converter, is it possible to query it for the buffer size? I checked the termios documentation and cannot see such a setting.
Any suggestions on this please?

List machine's serial ports

I have an Arduino-based device which connects through USB.
I'd like to detect it from my Qt 4 application, using QExtSerialPort (or whatever necessary), when it's plugged in.
If this weren't possible, I thought I could somehow get a list of the system's port names and just try all of them in search for my Arduino (where I'd implement some kind of handshaking procedure for it to detect it correctly). My concern in this approach is that I'm not sure if a device (for example, printer) would get damaged if I send some kind of handshaking ack at a different baud rate.
So, I don't really know where to start for any of them. Which would be the best approach? How would I implement it?
I believe you can find list of serial ports on Windows by looking into
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
registry key
Each serial port on a UNIX system has one or more device files (files in the /dev directory) associated with it:
System Port 1 Port 2
IRIX® /dev/ttyf1 /dev/ttyf2
HP-UX /dev/tty1p0 /dev/tty2p0
Solaris®/SunOS® /dev/ttya /dev/ttyb
Linux® /dev/ttyS0 /dev/ttyS1
Digital UNIX® /dev/tty01 /dev/tty02
more details on serial programing on POSIX systems here
Since your device is USB, your UART port will be emulated by some kind of conversor in his hardware. So first you must understand what driver is being used on your system.
The most common SERIAL->USB conversor uses PL2303/PL2301 chip, so it would create a path on /dev, if its the first device, it will appear as "/dev/ttyUSB0", but you may also see the list reading the proc path (like "cat /proc/bus/usb/devices").
Under Windows it usually creates a virtual "COM", just go to device manager and check the port.
When you are sure about how the HW talks to your system, you may use QExtSerialPort for wrapping the system API and talk to the device.
Way too hard and too platform specific, using weird Windows Registry keys or rely on hard wired device nodes on Linux.
You are on the right way. Get QextSerialPort or QSerialDevice (which I preffer in my projects, because it got integrated in Qt5), have a look at the examples and simply use it. In both libraries you get some kind of port enumerator class which returns you a list of all configures serial ports. Only platform/device specific settings you will have to do manually (like getting RS485 in half-duplex mode on my current embedded project), but "standard" problems are perfectly encapsulated in a QIODevice implementation.
You can use both QextSerialPort and QSerialDevice like a file. Open it (instead of a filename you specify the device name ie. "COM1" on Windows or "/dev/tty0" on Linux, depending on your configuration) and then read or write like you are doing it with an ordinary QFile, QBuffer, Qwhatever-inherits-from-QIODevice.
If you have any problems opening the port and communicating, don't hesitate to ask! :)

Resources