Read raw Ethernet using Qt - qt

I have a device which sends out a raw (Layer 2) Ethernet packet which I need to read and decode using a Qt based C++ Windows application. I believe I can do it using the winpcap libraries but would prefer a Qt way if possible.

Get a raw packet from pcap, wrap into QByteArray, munch on it using QDataStream. Qt doesn't include a replacement for pcap, so that's out of the question.

Related

STM32 usb cdc characters sending-receiving understanding

I'm trying to send data from C# app to the one STM32 dev board via USB CDC. I have problem with method SerialPort.Write() because write method send only first character instead of all characters of array or string. Same situation is it with serial terminals (terminte, cutecome,..) when attempt to send string. Can someone explain me how cdc usb really works. Does STM32 send data in same manner, character by character in each frame? I didn't use logic analyzer to see signals but that will be next step maybe.
If anyone has picture of usb cdc frame please share.
When I send string from STM32 dev board to the C# app that works fine. Any idea is welcome
The C# SerialPort.Write function is capable of writing an entire string at once if you call it the right way. The bytes of the string will be passed on to your operating system's USB drivers, which will split it up into packets according to the max packet size for the endpoint specified in your device's USB descriptors. Then those packets will be sent to the device, one packet at a time.
I suspect that there is a bug in your STM32 code, but since you have not posted an MCVE it will be difficult to help you debug any code.

conceiving a bus can adapter using stm32

So here is the thing, I want to conceive a universal BUS CAN adapter using stm32 with a desktop interface using Qt.
Still in the conception phase, I'm wondering how to treat the frames coming from the stm to PC GUI, weather 1) as a USB frame; in this case, how to encapsulate and decapsulate them into CAN frames and is there a Qt library to facilitate the job, or 2) as a CAN frame in this case I found the QCanBusDevice and QCanBusFrame Class which seem to be so helpful but in this case a CAN plugin must be specified during the object creation. So what should i do?
It doesn't really matter what you do because you're designing a custom protocol that rides on top of USB. Here you have an option of implementing a USB communications class device so that you don't need custom drivers nor libusb - especially given that the performance of libusb on Unixes is abysmal.
Once the data is available to the userspace, you can access it using QSerialPort. You'll have to frame the CAN frames somehow, as serial port is a stream-oriented transport and doesn't know of any packets. Most trivially, you can encapsulate the frames using RFC 1662 HDLC octet-stuffed framing. You can encapsulate the commands to your device, and their responses, in the same fashion, using one of the fields, e.g. the ADDRESS field, to multiplex CAN data and commands/responses.
If you now wish to expose this device to the Qt Serial Bus framework, you'll have to write a custom CAN plugin to access it.
To give some idea of how much code this is: total for Qt code and microcontroller code should be well under 1500 lines for a proof-of-concept. A minimal demo would be probably <400 lines of Qt code and <400 lines of STM32 code.

How to read/write a register via modbus TCP

I'm very new to modbus and I need to know how to read and write from/to a register via tcp.
Can someone post a tcp message example to read and one to write to a register?
Code in C/C++ or Golang would be appreciated but it doesn't have to be, just the string with the message would be fine.
Consider using libmodbus. It's a cross-platform library under LGPL with support for Modbus TCP and RTU.

Passing objects from smartphone app to Arduino through bluetooth

I'm writing a windows mobile app that connects to an Arduino board.
Currently in order to pass data i'm sending strings from and to the Arduino board.
Is there a way to pass objects or formatted data?
you could use json, which is very easily parsable on the mobile phone side.
it all depends on the kind of data you want to send.
As the arduino is a simple C++ device, you may go with a c structure or a binary object. If you are connecting from windows mobile OS <=6.5.3, you can write in c++ or c# (or vb). You can then use a serialized to convert from/to a structure/object. How many data do you need to transfer? And what types?

Qt - network interface statistics

Is there a way to get amount of bytes received/sent by a network interface using Qt on a Windows platform ? If it is cross-platform is even better.
I couldn't find anything useful in QtNetwork module.
The lowest OSI model layer which Qt can manage is the transport layer (maybe the layer 3 but I don't think). You can only get the number of received/sent bytes from/to a given port.
If you want to "sniff" the whole traffic on your interface, you should use a library based on pcap (winpcap for Windows, libpcap for GNU/Linux).

Resources