formatting a FIX message to a c++ struct or classe - c++

say I want to format my fix message received in a XML form ( not FIXML ! ) but kind of like the spec description, for example like that
<message name="Heartbeat" msgcat="admin" msgtype="0">
<field name="TestReqID" required="N" />
</message>
and in my output I need to have a c++ struct or a class called HeartbeatMsg whose attribute are its own fields.
So after parsing my XML file, I want to stock those messages parsed into an object that I can call later by a printer or formatting class that take my message object and write it into a file.
so I thought this message object that I want to instantiate maybe I can create it as a new class that inherit from the message class in the QuickFix library, so my question is :
could I do it? because I read the QuickFix message and it's loaded with functions that can be used for more than describing the message but also for extracting it, serializing it
from a stream input.
so although my need is far away from that, can I still use this classe for a simple formatting.

What you get from your XML can be parsed into a FIX object, using the Quickfix library. But it is going to be doing the work twice. 2 places when it can be done
When you receive and process your XML message to use, you can as a concurrent job create a FIX message using the Quickfix library. But that would surely slow down the processing of your original application.
When you process the XML message and convert it into a format your code understands, store that object you create and create a FIX message out of it as a side task totally independent of your original application. That way your original application runs as it is and it doesn't care about the FIX message creation. But you may have to copy your objects to a place from where the FIX message creation can be started.
Both require a combination of your original API and Quickfix library. So be careful when integrating them.

Related

Embedded graphics in original mail change to attached graphics in reply when using exchangelib in python

We have a python script that replies to incoming emails using exchangelib. User A sends us an email that can contain a picture/graphic (e.g. company logo in signature line). Our script is able to reply to his mail, and user A will get our reply. Unfortunately, the picture/graphic that was embedded in the original mail to us, is now an attached file instead of an embedded picture.
Here is the code that we're using:
origmsg.reply(
subject='Re: ' + origmsg.subject,
body="This is my reply to your inquiry...."
)
I understand that for new messages the HTML code needs to include a reference to the attached file to make it embedded. How can this be done in a reply?
Thanks.
https://ecederstrand.github.io/exchangelib/#attachments has some example of embedding images in emails.
The .reply() method is for simple replies. You may need to call .create_reply() instead and edit the returned ReplyToItem object as needed before calling .send() on it.
If you have even more special requirements, you can call .save() on the ReplyToItem object to save it as a draft, fetch the draft as a plain Message object with account.drafts.get(id=reply_to_item_id) and do whatever you need to do before sending the draft.

QT, c++ dlls, and objects

I'm fairly new to dlls, and completely new to QT. I've been playing for a few days and am trying to create a project wherein I read the contents of a file and display the parsed results neatly. I have written a dll to parse the file format and wish to use that dll within my QT GUI.
My dll contains 4 files, SignalParse.h/cpp and Signal.h/cpp.
SignalParse is the meat of the dll, containing the functionality, and Signal is an object for storing data.
My aim is for my QT program to use this function from within SignalParse:
__declspec(dllexport) vector<Signal> ReturnSignal()
{
return sigList;
}
sigList is a vector containing all the data from my signal objects. Signal data is something like as follows parsed into variables within the signal object:
[SignalOne]
bytes: 2
format: int
offset: 0
The aim behind this is to have the GUI able to access the dll and use it to parse files, then read the parsed data.
However, seeing as I am returning a vector of Signal, I (think I) will need to include signal in my QT project. Is this normal practice? Or should I attempt to store my data in another manner?
As a novice, I'm not sure how to handle situations like this. The idea of storing my signal data in an object seems the neatest, but having to then include the object in every program that uses the dll seems less neat.
Perhaps there is a better way of doing it? I would very much like to know whether my approach is reasonable, or if there is another obvious way of handling this kind of thing that I've blindsided.
Thanks!

How can I add a new message in the mavlink protocol?

I'm new in Mavlink, I want to add a new message in the Mavlink protocol and send it each second periodically. How can I do it?
Here you can find detailed steps about how to add new message to mavlink protocol and how you handle it.
Ensure you have the latest ArduPilot code and Mavproxy installed.
Decide what type of message you want to add.
Add the new message definition to the common.xml or ardupilotmega.xml file in the mavlink submodule.
Add functions to the main vehicle code to handle sending or receiving the command.
It depends on what autopilot you are using. If you're using ardupilot then you would need to add a new xml message definition in ardupilot/modules/mavlink/message_definitions/v1.0/ardupilotmega.xml.
You can look at the other messages to see how it should be formatted. Just make sure you choose an id that is unused.
Next you need to decide how to put this in the code. You could place it in the data_stream_send task by adding the message id to, say, STREAM_EXTRA3. This will send your message as often as the other data is sent there. As part of that you will need to define the function to actually pack your data structure using the function generated by pymavgen, the message id and enumerations. This is what I have done in my own project for ASH_DATA. You can see the changes I've made in my repository for reference. Note that some of those include changes to incorporate reception of ash data on the pixhawk and adding the data to a log file.
Given that you want to run this once a second you may want to add to the one_second_loop task or create your own task that simply calls the try_send_message function using your new message id.
You will of course need to incorporate the new message in your gcs so you can actually receive it, but that's another matter.
Hopefully this can nudge others in the right direction who are trying to do the same.

Qt: How to create a file using a path on any Windows machine?

I am not exactly sure if the title captures what exactly I want to ask so here it is:
I just made my first desktop application that uses a XML file to store data. The XML File is stored somewhere in C:/Users/myname/Documents/adjsklf/asdjfklasd/.... on my own machine.
How do I go about creating this file in a specific location C:/Users/theirname/Documents/myAppName/data.xml? Or more specifically, how do I get the "theirname" file name? For machines that have multiple users, how do I get the filename that belongs to the user who actually is using the app?
Also, when I first started this application, I wasn't really thinking of deploying this application. So I made an explicit constructor of a class, dataManipulation, that manipulates all the data in my XML file. What happens is that when my program runs, it executes MainWindow, which at the same time constructs my dataManipulation object with the path I want. However, since now I have a few friends who want to try out this app, I need to be able to detect whether the file exists first using the path I mentioned earlier. What's the best way to achieve that?
Thank you so much!
Use QStandardPaths::writableLocation.
There are many ways to perform file opening checks. If you want to do it in Qt-like way, take a look at QFile and do similarily. In constructor it only sets the path, but the file is opened only in QFile::open, and its return value indicates whether it was successfully opened. You can create init() method in your data manipulation class, check its return value and show a message to user if needed.

Is it possible to send compiled protobuf message definition inside a protobuf?

I'd like to do some message debugging on traffic for a few protobuf based services we use.
The services all use compiled .proto files for messages, and I'd like to serialize the actual format of the message back to .proto file text and send that to a client so that the client does not need to know implementation details at compile time.
Is this possible in C++? I know that I can get the structure of a message without the definition, but having the names of the message fields would be critical for debugging. Is there another way of getting this information without having the .proto files?
Thanks!
If the original sender has the .proto files, they can be compiled by "protoc" into a protobuf data file, matching "descriptor.proto" (which should be available in your distribution of protobuf). You can do this by using
protoc --descriptor_set_out={out_path} --proto_path={in_path}
(or to stdout if you prefer, IIRC - untested)
The resultant binary data can be included as a bytes field, and deserialized serparately as long as the client also has an object-model generated from descriptor.proto.
In terms of what to do once you have deserialized it: FileDescriptorSet is the top-level object; you should be able to traverse down to FieldDescriptorProto, which has the member-name etc
Perhaps not very elegant, but it should work.
Alternatively, include the metadata any-which-way, and treat everything as extension fields.