Discussion:
Problems using Objects of type Any and Qt
Andreas Benzler
2008-12-03 12:23:56 UTC
Permalink
Hallo,
I´m using a client-server model based on Mico and I defined an idl
interface like this:

interface ifRec
{
long Register( in string name, in string ns );
void WriteData( in long id, in any data );
void SetEnv( in string Key, in string Value );
void Rec();
void Break();
void Resume();
void Replay( in double speed );
void Stop();
long Load( in string filename );
};

The WriteData function uses the parameter "data" of type Any, which
represents a structure (struct) containing other structures inside, and I
get a run-time error whenever a client calls this function. The client has
been compiled with Qt and uses the QApplication function. I discovered
that the run-time error it´s based on the problem that the object of type
Any is codified in the wrong way from Mico during the serialization
process only when the QApplication function is used in the client code and
also when the tree´s depth of the structures codified in the Any object is
too big, otherwise no run-time error comes up and the octet sequence that
represents the object, made by the Mico serialization process, has the
correct length. I also discovered that the difference between the octet
sequence with and without using QApplication is fixed and always 268 bytes
(more bytes without QApplication) and it does not depend on the complexity
of the structure that the Any object represents. I discovered this last
detail simulating a serialization process of the Any object using the
available Mico internal codec. I tried to compile the system with the two
Mico versions 2.3.11 and 2.3.13, both versions compiled specifying also the
--with-qt=<qt-path> directive for the configure script, but I have same
problems.

Here is also the Mico codec I used to simulate the serialization process:

void operator>> ( const Any& anyobject, OctetSeq& dataseq)
{
// Codec
ORB_var orb;
Object_var obj;
IOP::CodecFactory_var cf;
IOP::Encoding enc2;
IOP::Codec_ptr codec_ptr;

// Generate codec based on CodecFactory
int argc = 1;
char* argv[1];
argv[0] = "anyserial";
orb = ORB_init( argc, argv, "mico-local-orb" );
obj = orb->resolve_initial_references("CodecFactory");
cf = IOP::CodecFactory::_narrow(obj);
enc2.format = IOP::ENCODING_CDR_ENCAPS;
enc2.major_version = 1;
enc2.minor_version = 2;
codec_ptr = cf->create_codec(enc2);

// Encode anyobject and generate a new octet sequence
OctetSeq_var newdataseq_ptr = codec_ptr->encode(anyobject);
int length = newdataseq_ptr->length();

// Copy generated octet sequence into dataseq
dataseq.length(length);

for (int i=0; i<length; i++)
dataseq[i] = (*newdataseq_ptr)[i];
}

Any and OctetSeq types are exactly CORBA::Any and CORBA::OctetSeq types
defined in MICO.

Could please anyone help to understand why Mico has this strange behavior
and eventually to find a solution?

Many Thanks in advance,
Pasquale Zarcone

Because the mail did not come trough with my colleges account I post
this message on his behalf

Andreas
Andreas Benzler
2008-12-10 20:46:41 UTC
Permalink
Hi all

Is there nobody out there with similar problems?
Can someone give my a hint where to look for the encoding during
serializing a mico any type. We tried what I described in my last mail
without success.

But maybe there is a better way of solving the problem we are facing...
I try to describe what we actually want to achieve:
We have multiple mico servers (auto generated by c++ templates) running
and we need some sort of transaction server to do a record and replay of
the whole communication.
Currently we try to solve this by adding an additional interface to the
server where we send an any type to the transaction server and serialize
it there to store the data on disk. With the problems described in the
previous mail when a QT application sends data to the server. The server
can handle the data well until it comes to serializing... None of the
servers does contain any QT code.

Is there a better way of building a transaction server where multiple
different servers can send their data at to do a replay of the whole
communication.
Because we also are interested in working with the recorded data in
tools like matlab it would be great if it would be possible to save the
data in an human readable way. For example XML. This would avoid the
manual converting from mico structures to text files. Is there a way to
automatically convert MiCO objects to XML and back?

Regards

Andreas
Karel Gardas
2009-01-12 10:28:51 UTC
Permalink
Hello,

what exactly does your anyobject Any variable contain? The strange thing
is that you are only able to duplicate the issue when you use Qt...

Cheers,
Karel
Post by Andreas Benzler
Hallo,
I´m using a client-server model based on Mico and I defined an idl
interface ifRec
{
long Register( in string name, in string ns );
void WriteData( in long id, in any data );
void SetEnv( in string Key, in string Value );
void Rec();
void Break();
void Resume();
void Replay( in double speed );
void Stop();
long Load( in string filename );
};
The WriteData function uses the parameter "data" of type Any, which
represents a structure (struct) containing other structures inside, and I
get a run-time error whenever a client calls this function. The client has
been compiled with Qt and uses the QApplication function. I discovered
that the run-time error it´s based on the problem that the object of type
Any is codified in the wrong way from Mico during the serialization
process only when the QApplication function is used in the client code and
also when the tree´s depth of the structures codified in the Any object is
too big, otherwise no run-time error comes up and the octet sequence that
represents the object, made by the Mico serialization process, has the
correct length. I also discovered that the difference between the octet
sequence with and without using QApplication is fixed and always 268 bytes
(more bytes without QApplication) and it does not depend on the complexity
of the structure that the Any object represents. I discovered this last
detail simulating a serialization process of the Any object using the
available Mico internal codec. I tried to compile the system with the two
Mico versions 2.3.11 and 2.3.13, both versions compiled specifying also the
--with-qt=<qt-path> directive for the configure script, but I have same
problems.
void operator>> ( const Any& anyobject, OctetSeq& dataseq)
{
// Codec
ORB_var orb;
Object_var obj;
IOP::CodecFactory_var cf;
IOP::Encoding enc2;
IOP::Codec_ptr codec_ptr;
// Generate codec based on CodecFactory
int argc = 1;
char* argv[1];
argv[0] = "anyserial";
orb = ORB_init( argc, argv, "mico-local-orb" );
obj = orb->resolve_initial_references("CodecFactory");
cf = IOP::CodecFactory::_narrow(obj);
enc2.format = IOP::ENCODING_CDR_ENCAPS;
enc2.major_version = 1;
enc2.minor_version = 2;
codec_ptr = cf->create_codec(enc2);
// Encode anyobject and generate a new octet sequence
OctetSeq_var newdataseq_ptr = codec_ptr->encode(anyobject);
int length = newdataseq_ptr->length();
// Copy generated octet sequence into dataseq
dataseq.length(length);
for (int i=0; i<length; i++)
dataseq[i] = (*newdataseq_ptr)[i];
}
Any and OctetSeq types are exactly CORBA::Any and CORBA::OctetSeq types
defined in MICO.
Could please anyone help to understand why Mico has this strange behavior
and eventually to find a solution?
Many Thanks in advance,
Pasquale Zarcone
Because the mail did not come trough with my colleges account I post
this message on his behalf
Andreas
_______________________________________________
Mico-devel mailing list
http://www.mico.org/mailman/listinfo/mico-devel
--
Karel Gardas ***@objectsecurity.com
ObjectSecurity Ltd. http://www.objectsecurity.com
Karel Gardas
2009-01-14 15:06:17 UTC
Permalink
Hi Pascal,

this is strange, please try to reorder your header files to

#include "anyserial.h"
#include "ifDKAircraftInterface.h"
#include <QApplication>

or to:

#include "ifDKAircraftInterface.h"
#include "anyserial.h"
#include <QApplication>

BTW, does your anyserial includes anything from MICO/CORBA? Do you use
inside it `using namespace CORBA'?

Also please try to use PI's codec API as your college Andreas does.

Cheers,
Karel
--
Karel Gardas ***@objectsecurity.com
ObjectSecurity Ltd. http://www.objectsecurity.com
Hallo Karel,
thank you very much for your support. The anyobject Any variable contains
all data coming from a complex structure (struct) defined in two specific
IDL files: commonBasicTypes.idl and AircraftInterface.idl. Here are the
--- commonBasicTypes.idl ---
#ifndef __COMMONBASICTYPES_IDL__
#define __COMMONBASICTYPES_IDL__
struct SGeoPos
{
double lat_wgs84; // degrees
double lon_wgs84; // degrees
double alt_wgs84_m;
};
typedef sequence <SGeoPos> LGeoPos;
struct S2dPos // e.g. referring to a pos in an OpenGL display
{
double x; // normally -1.0 to +1.0
double y; // normally -1.0 to +1.0
};
typedef sequence <S2dPos> L2dPos;
struct STime
{
long hour;
long min;
long sec;
double ms; // milliseconds
};
/**
Operation modes of a flight management system
*/
enum EFMSMode
{
FMS_MODE_OFFLINE, //!< FMS is offline (caused by operator or
"end-of-track")
FMS_MODE_TEMPORARY_OFFLINE, //!< The FMS is offline for batch processing
FMS_MODE_LNAV, //!< horizontal navigation only
FMS_MODE_VNAV, //!< horizontal and vertical navigation, no speed control
FMS_MODE_VNAV_SPEED //!< HNAV + VNAV + speed control
};
// Different approach modes for waypoints.
enum EWPMode
{
WAYPOINT_MODE_TRACK, //!< The default: Use the waypoint as "fly-by"
navigation hint.
WAYPOINT_MODE_OVERFLY, //!< Fly over the waypoint. No pre-turning is
allowed.
WAYPOINT_MODE_HOVER, //!< Hover at the waypoint. The FMS is not allowed
to advance to the next waypoint. This is only supported for rotorcrafts.
WAYPOINT_MODE_CIRCLE //!< Circle around the waypoint. The FMS is not
allowed to advance to the next waypoint.
};
enum EWaypointType
{
WAYPOINTTYPE_UNKNOWN,
WAYPOINTTYPE_GROUND,
WAYPOINTTYPE_AIR,
WAYPOINTTYPE_TRAJECTORY //more to come
};
enum EDesiredTurnMode
{
TURNMODE_TURNFLYBY,
TURNMODE_TURNFLYOVER,
TURNMODE_TURNFLYOVERINTERCEPT
};
struct STurnModeConstraint
{
boolean constraintDefined;
EDesiredTurnMode eTurnMode;
};
struct SPositionConstraint
{
boolean constraintDefined;
double allowedLateralDeviation_m;
};
enum EAltitudeType
{
ALTTYPE_WGS84,
ALTTYPE_AGL,
ALTTYPE_MSL,
ALTTYPE_FL
};
struct SAltitudeConstraint
{
boolean constraintDefined;
boolean preferdAltSet;
double preferedAlt_m;
EAltitudeType ePreferdAltType;
boolean maxAltSet;
double maxAlt_m;
EAltitudeType eMaxAltType;
boolean minAltSet;
double minAlt_m;
EAltitudeType eMinAltType;
};
struct STimeConstraint
{
boolean constraintDefined;
STime sTargetTime;
long timeEarly_s;
long timeLate_s;
};
struct SWaypoint
{
boolean initialized; // A waypoint is valid if this flag is true.
long id; // Unique ID for identification
string name; // The name of this waypoint.
SGeoPos sPos; // The WGS84 coordinates of the waypoint
boolean hasHeading; // If set to true, the waypoint has an ingress
heading. e.g. for VOR navigation or corridor entrance.
double heading_rad; // If hasHeading is true, then this is the ingress
heading for the waypoint.
double ingress_speed_m_s; // Ingress speed in meter per second for this
waypoint.
double circle_radius_m; // Circle radius in meter (only valid, if mode =
WAYPOINT_MODE_CIRCLE)
boolean circle_clockwise; // true for clockwise, false for
counter-clockwise (only valid, if mode = WAYPOINT_MODE_CIRCLE)
EWPMode mode;
EWaypointType eWaypointType;
STurnModeConstraint sTurnModeConstraint; // TODO: shift constraints to
routenplaner_cmd_qe
SPositionConstraint sPositionConstraint;
SAltitudeConstraint sAltitudeConstraint;
STimeConstraint sTimeConstraint;
};
typedef sequence<SWaypoint> LWaypoint;
typedef sequence<long> LWpId;
struct SRoute
{
boolean initialized; // A Route is valid if this flag is true.
long id; // Unique ID for identification
string name;
//long nextRoutepointId; // only for MiRA integration. moved to
SFMSOutput->sCurrentRoute.routepointIndex
//LWaypoint lWaypoint; // only for MiRA integration. moved to
SRouteData->lWaypoint
LWpId lWpId; // For the new FMS a route consists of waypoint ids.
Waypoints are stored separately. The order of the waypoints corresponds
to the sequence order
};
typedef sequence<SRoute> LRoute;
typedef sequence<long> LRouteIds;
#endif
---- AircraftInterface.idl ---
#ifndef AIRCRAFTINTERFACE_IDL
#define AIRCRAFTINTERFACE_IDL
#include "commonBasicTypes.idl"
enum EAircraftType
{
AIRCRAFTTYPE_PLANE,
AIRCRAFTTYPE_HELI
};
struct SIdentification
{
short id; //id specified by the scenario simulation (and send to x-plane
via the d-sim control plugin)
string name;
string identifier; //military or civil aircraft identifier
EAircraftType eAircraftType;
//EAircraftModel eAircraftModel;
boolean isManned;
};
struct SAircraftAttitude
{
double phi_rad; // roll
double theta_rad; // pitch
double psi_rad_magN; // yaw
double psi_rad_trueN; // yaw
};
struct SAircraftRates
{
//in flugzeugkoordinaten
double p_rad_s; // phi_dot
double q_rad_s; // theta_dot
double r_rad_s; // psi_dot
};
struct SAircraftAccelerations
{
//in flugzeugkoordinaten
double x_m_s_s;
double y_m_s_s;
double z_m_s_s;
};
struct SAircraftVelocities
{
double north_m_s;
double east_m_s;
double vertical_m_s;
double ias_m_s;
double cas_m_s;
double tas_m_s;
double gs_m_s;
};
struct SFlightMechanics
{
SGeoPos sPos;
SAircraftAttitude sAtt;
SAircraftRates sRat;
SAircraftAccelerations sAcc;
SAircraftVelocities sVel;
double magneticVariation_rad;
};
struct SRotorState
{
double rpm_rad_s;
double torque_nm;
double maxTorque_nm; //used for % calculation of the torque;
};
enum EEngineOperatingState
{
ENGINESTATE_ON,
ENGINESTATE_OFF,
ENGINESTATE_STARTUP
};
struct SEngineState
{
double rpm_rad_s;
double torque_nm;
double maxTorque_nm; // used for % calculation of the
torque
double curFuelConsumption_kg_s;
EEngineOperatingState eOpState;
};
enum EGearState
{
GEAR_UP,
GEAR_DOWN,
GEAR_TRANSIT
};
struct SGearState
{
EGearState nose;
EGearState right;
EGearState left;
};
struct SSystemData
{
SRotorState sRotor;
long noOfEngines;
sequence<SEngineState,2> sEngine;
SGearState sGear;
double flaps; //-1 .. +1
double spoiler; //-1 .. +1
double break; //-1 .. +1
};
struct SCurrentInput
{
double roll; //-1 .. +1
double pitch; //-1 .. +1
double yaw; //-1 .. +1
double collective; //-1 .. +1
double throttle1; //-1 .. +1 0= no power +1 100% power
double throttle2; //-1 .. +1 0= no power +1 100% power
double trimRoll; //-1 .. +1
double trimPitch; //-1 .. +1
double trimYaw; //-1 .. +1
double trimCollective; //-1 .. +1
double flaps; //-1 .. +1 -> 0 = neutral (in) +1= down -1 = up ????????
double brakes; //-1 .. +1
double spoiler;
boolean gearUp;
};
struct SSateliteState
{
boolean l1Locked;
boolean l2Locked;
};
struct SGPSHealth
{
double pdop_m; // positional dilution of precision
double hdop_m; // horizontal dilution of precision
long noSat; // number of satellites
sequence<SSateliteState,20> sSateliteState;
long itow_ms; // international time of week
};
struct SSystemHealth
{
SGPSHealth sGPS;
boolean destroyed; // true => the aircraft is lost
};
struct SBaroData
{
double pressure_hPa;
double qnh_hPa;
double alt_m;
};
struct SSensorics
{
boolean hasGroundContact;
double airTemp_celsius;
SBaroData sBaroData;
double radarAlt_m;
double sonarAlt_m;
double laserAlt_m;
};
struct SWindData
{
double speed_m_s;
double dir_rad_magN;
double dir_rad_trueN;
};
struct SWeatherData
{
SWindData sWind;
};
struct SAircraftInterface
{
SIdentification sId;
SFlightMechanics sFm;
SSystemData sSystem;
SSystemHealth sHealth;
SSensorics sSensorics;
SWeatherData sWeather;
SCurrentInput sCurrentInput;
double simTime;
};
#endif
Here is the also the source cpp file I wrote and used to simulate a
serialization process variables of type SAircraftInterface
--- codec_test.cpp ---
#include <QApplication>
#include "anyserial.h"
#include "ifDKAircraftInterface.h"
using namespace std;
int main( int argc, char *argv[])
{
SAircraftInterface_var aci_src, aci_dst;
CORBA::Any anyobject_src, anyobject_dst;
OctetSeq sequence;
QApplication app(argc, argv);
aci_src = new SAircraftInterface;
aci_dst = new SAircraftInterface;
//identification
aci_src->sId.name="MiRA 1";
aci_src->sId.isManned = true;
aci_src->sId.eAircraftType = AIRCRAFTTYPE_HELI;
//position
aci_src->sFm.sPos.lat_wgs84 = 10.0;
aci_src->sFm.sPos.lon_wgs84 = 20.0;
aci_src->sFm.sPos.alt_wgs84_m = 5.0;
// Convert anyobject_src to an octet sequence using MICO internal codec
anyobject_src <<= *aci_src;
anyobject_src >> sequence;
// Show octet sequence length
cout << "sequence.length: " << sequence.length() << endl;
// Try to convert octet sequence to anyobject_dst using MICO internal codec
try
{
anyobject_dst << sequence;
anyobject_dst >>= *aci_dst;
cout << "aci.name: " << aci_dst->sId.name << endl;
cout << "Sequence converted back to object of type Any." << endl;
}
catch (...)
{
cout << "Error trying to convert sequence back to object of type Any."
<< endl;
}
return ( 0 );
}
1. If you remove the line where QApplication is called the try section
works and the result is of 4016 octet for the sequence generated by the
codec;
2. If you leave the line where QAppliaction is called the try section
works well only when the two lines where aci_src and aci_dst variables are
allocated through the new operator have been placed before the
QApplication, otherwise an exception is catched and the sequence results
of 3748 octet, exactely 268 octet less than normal, as I already specified
in my previous e-mail.
void operator>> ( const Any& anyobject, OctetSeq& dataseq)
2. ifDKAircraftInterface.h has been generated with the Mico idl compiler
#ifndef __IFDKAircraftInterface_IDL__
#define __IFDKAircraftInterface_IDL__
#include "AircraftInterface.idl"
interface ifDKAircraftInterface
{
SAircraftInterface ReadData ( );
void WriteData ( in SAircraftInterface var );
long long GetVersion ( );
};
#endif // #ifndef __IFDKAircraftInterface_IDL__
Many Thanks in advance,
Pasquale Zarcone
Post by Karel Gardas
Hello,
what exactly does your anyobject Any variable contain? The strange thing
is that you are only able to duplicate the issue when you use Qt...
Cheers,
Karel
Post by Andreas Benzler
Hallo,
I´m using a client-server model based on Mico and I defined an idl
interface ifRec
{
long Register( in string name, in string ns );
void WriteData( in long id, in any data );
void SetEnv( in string Key, in string Value );
void Rec();
void Break();
void Resume();
void Replay( in double speed );
void Stop();
long Load( in string filename );
};
The WriteData function uses the parameter "data" of type Any, which
represents a structure (struct) containing other structures inside, and I
get a run-time error whenever a client calls this function. The client has
been compiled with Qt and uses the QApplication function. I discovered
that the run-time error it´s based on the problem that the object of type
Any is codified in the wrong way from Mico during the serialization
process only when the QApplication function is used in the client code and
also when the tree´s depth of the structures codified in the Any object is
too big, otherwise no run-time error comes up and the octet sequence that
represents the object, made by the Mico serialization process, has the
correct length. I also discovered that the difference between the octet
sequence with and without using QApplication is fixed and always 268 bytes
(more bytes without QApplication) and it does not depend on the complexity
of the structure that the Any object represents. I discovered this last
detail simulating a serialization process of the Any object using the
available Mico internal codec. I tried to compile the system with the two
Mico versions 2.3.11 and 2.3.13, both versions compiled specifying also the
--with-qt=<qt-path> directive for the configure script, but I have same
problems.
void operator>> ( const Any& anyobject, OctetSeq& dataseq)
{
// Codec
ORB_var orb;
Object_var obj;
IOP::CodecFactory_var cf;
IOP::Encoding enc2;
IOP::Codec_ptr codec_ptr;
// Generate codec based on CodecFactory
int argc = 1;
char* argv[1];
argv[0] = "anyserial";
orb = ORB_init( argc, argv, "mico-local-orb" );
obj = orb->resolve_initial_references("CodecFactory");
cf = IOP::CodecFactory::_narrow(obj);
enc2.format = IOP::ENCODING_CDR_ENCAPS;
enc2.major_version = 1;
enc2.minor_version = 2;
codec_ptr = cf->create_codec(enc2);
// Encode anyobject and generate a new octet sequence
OctetSeq_var newdataseq_ptr = codec_ptr->encode(anyobject);
int length = newdataseq_ptr->length();
// Copy generated octet sequence into dataseq
dataseq.length(length);
for (int i=0; i<length; i++)
dataseq[i] = (*newdataseq_ptr)[i];
}
Any and OctetSeq types are exactly CORBA::Any and CORBA::OctetSeq types
defined in MICO.
Could please anyone help to understand why Mico has this strange behavior
and eventually to find a solution?
Many Thanks in advance,
Pasquale Zarcone
Because the mail did not come trough with my colleges account I post
this message on his behalf
Andreas
_______________________________________________
Mico-devel mailing list
http://www.mico.org/mailman/listinfo/mico-devel
--
ObjectSecurity Ltd. http://www.objectsecurity.com
_______________________________________________
Mico-devel mailing list
http://www.mico.org/mailman/listinfo/mico-devel
--
Karel Gardas ***@objectsecurity.com
ObjectSecurity Ltd. http://www.objectsecurity.com
Karel Gardas
2009-01-17 11:09:15 UTC
Permalink
Hi Pascal,

first of all, by PI I mean PortableInterceptor, i.e. specification which
also specifies API for CodecFactory and Codec which you seems to use in
the code below, but you didn't use in your original email where you used
MICO specific codec API. So everything is OK from this point of view.

Now, to your issue. As I understand the situation is that you have
perfectly working code and when you add #include <QApplication> to it
which comes from Qt library, then your code is not working at all. The
first thing which comes to mind is that your added include silently
redefine or undefine something which is needed and defined by the former
includes (CORBA). Hence I recommended to see if reordering of the
includes solves your issue. BTW: What compiler and on which platform do
you use exactly? i.e. version numbers might be interesting here.

Also what's very dangerous is to use any namespace in globaly included
header files. I would recommend you to use absolute scope names in all
your header files, hence fixing anyserial.h to:

#ifndef __ANYSERIAL__
#define __ANYSERIAL__

#include <CORBA.h>
#include <mico/throw.h>
#include <coss/CosNaming.h>

void operator<< ( CORBA::Any& anyobject, const CORBA::OctetSeq& dataseq);
void operator>> ( const CORBA::Any& anyobject, CORBA::OctetSeq& dataseq);

#endif

And finally third attempt I would do is to carefully examine
preprocessed source of your application to see any issue with silent
symbol undefine or redefine...

Cheers,
Karel
PS: also please sign to mico-***@mico.org mailing list here:
http://www.mico.org/mailman/listinfo/mico-devel from your address you
are using now, otherwise you still will not be able to sent any email
into the list.
Hi Karel,
many thanks again for your suggestions. I tried to change the #include
order in the file but the problem still comes up. To give you the best
answer regarding the anyserial.h file I just write you down the header and
the cpp files so that you can see how they are structured.
--- anyserial.h ---
#ifndef __ANYSERIAL__
#define __ANYSERIAL__
#include <CORBA.h>
#include <mico/throw.h>
#include <coss/CosNaming.h>
using namespace CORBA;
void operator<< ( Any& anyobject, const OctetSeq& dataseq);
void operator>> ( const Any& anyobject, OctetSeq& dataseq);
#endif
--- anyserial.cpp ---
// anyserial implementation
#include "anyserial.h"
void operator<< ( Any& anyobject, const OctetSeq& dataseq)
{
// Codec
ORB_var orb;
Object_var obj;
IOP::CodecFactory_var cf;
IOP::Encoding enc2;
IOP::Codec_ptr codec_ptr;
// Generate codec based on CodecFactory
int argc = 1;
char* argv[1];
argv[0] = "anyserial";
orb = ORB_init( argc, argv, "mico-local-orb" );
obj = orb->resolve_initial_references("CodecFactory");
cf = IOP::CodecFactory::_narrow(obj);
enc2.format = IOP::ENCODING_CDR_ENCAPS;
enc2.major_version = 1;
enc2.minor_version = 2;
codec_ptr = cf->create_codec(enc2);
// Decode dataseq and copy new generated object of type any into anyobject
anyobject = *(codec_ptr->decode(dataseq));
}
void operator>> ( const Any& anyobject, OctetSeq& dataseq)
{
// Codec
ORB_var orb;
Object_var obj;
IOP::CodecFactory_var cf;
IOP::Encoding enc2;
IOP::Codec_ptr codec_ptr;
// Generate codec based on CodecFactory
int argc = 1;
char* argv[1];
argv[0] = "anyserial";
orb = ORB_init( argc, argv, "mico-local-orb" );
obj = orb->resolve_initial_references("CodecFactory");
cf = IOP::CodecFactory::_narrow(obj);
enc2.format = IOP::ENCODING_CDR_ENCAPS;
enc2.major_version = 1;
enc2.minor_version = 2;
codec_ptr = cf->create_codec(enc2);
// Encode anyobject and generate a new octet sequence
OctetSeq_var newdataseq_ptr = codec_ptr->encode(anyobject);
int length = newdataseq_ptr->length();
// Copy generated octet sequence into dataseq
dataseq.length(length);
for (int i=0; i<length; i++)
dataseq[i] = (*newdataseq_ptr)[i];
}
I think I used what is really necessary of MICO/CORBA, am I right? As you
can see I also specified "using namespace MICO;". What is PI?
Pasquale
Post by Karel Gardas
Hi Pascal,
this is strange, please try to reorder your header files to
#include "anyserial.h"
#include "ifDKAircraftInterface.h"
#include <QApplication>
#include "ifDKAircraftInterface.h"
#include "anyserial.h"
#include <QApplication>
BTW, does your anyserial includes anything from MICO/CORBA? Do you use
inside it `using namespace CORBA'?
Also please try to use PI's codec API as your college Andreas does.
Cheers,
Karel
--
ObjectSecurity Ltd. http://www.objectsecurity.com
Hallo Karel,
thank you very much for your support. The anyobject Any variable contains
all data coming from a complex structure (struct) defined in two specific
IDL files: commonBasicTypes.idl and AircraftInterface.idl. Here are the
--- commonBasicTypes.idl ---
#ifndef __COMMONBASICTYPES_IDL__
#define __COMMONBASICTYPES_IDL__
struct SGeoPos
{
double lat_wgs84; // degrees
double lon_wgs84; // degrees
double alt_wgs84_m;
};
typedef sequence <SGeoPos> LGeoPos;
struct S2dPos // e.g. referring to a pos in an OpenGL display
{
double x; // normally -1.0 to +1.0
double y; // normally -1.0 to +1.0
};
typedef sequence <S2dPos> L2dPos;
struct STime
{
long hour;
long min;
long sec;
double ms; // milliseconds
};
/**
Operation modes of a flight management system
*/
enum EFMSMode
{
FMS_MODE_OFFLINE, //!< FMS is offline (caused by operator or
"end-of-track")
FMS_MODE_TEMPORARY_OFFLINE, //!< The FMS is offline for batch processing
FMS_MODE_LNAV, //!< horizontal navigation only
FMS_MODE_VNAV, //!< horizontal and vertical navigation, no speed control
FMS_MODE_VNAV_SPEED //!< HNAV + VNAV + speed control
};
// Different approach modes for waypoints.
enum EWPMode
{
WAYPOINT_MODE_TRACK, //!< The default: Use the waypoint as "fly-by"
navigation hint.
WAYPOINT_MODE_OVERFLY, //!< Fly over the waypoint. No pre-turning is
allowed.
WAYPOINT_MODE_HOVER, //!< Hover at the waypoint. The FMS is not allowed
to advance to the next waypoint. This is only supported for rotorcrafts.
WAYPOINT_MODE_CIRCLE //!< Circle around the waypoint. The FMS is not
allowed to advance to the next waypoint.
};
enum EWaypointType
{
WAYPOINTTYPE_UNKNOWN,
WAYPOINTTYPE_GROUND,
WAYPOINTTYPE_AIR,
WAYPOINTTYPE_TRAJECTORY //more to come
};
enum EDesiredTurnMode
{
TURNMODE_TURNFLYBY,
TURNMODE_TURNFLYOVER,
TURNMODE_TURNFLYOVERINTERCEPT
};
struct STurnModeConstraint
{
boolean constraintDefined;
EDesiredTurnMode eTurnMode;
};
struct SPositionConstraint
{
boolean constraintDefined;
double allowedLateralDeviation_m;
};
enum EAltitudeType
{
ALTTYPE_WGS84,
ALTTYPE_AGL,
ALTTYPE_MSL,
ALTTYPE_FL
};
struct SAltitudeConstraint
{
boolean constraintDefined;
boolean preferdAltSet;
double preferedAlt_m;
EAltitudeType ePreferdAltType;
boolean maxAltSet;
double maxAlt_m;
EAltitudeType eMaxAltType;
boolean minAltSet;
double minAlt_m;
EAltitudeType eMinAltType;
};
struct STimeConstraint
{
boolean constraintDefined;
STime sTargetTime;
long timeEarly_s;
long timeLate_s;
};
struct SWaypoint
{
boolean initialized; // A waypoint is valid if this flag is true.
long id; // Unique ID for identification
string name; // The name of this waypoint.
SGeoPos sPos; // The WGS84 coordinates of the waypoint
boolean hasHeading; // If set to true, the waypoint has an ingress
heading. e.g. for VOR navigation or corridor entrance.
double heading_rad; // If hasHeading is true, then this is the ingress
heading for the waypoint.
double ingress_speed_m_s; // Ingress speed in meter per second for this
waypoint.
double circle_radius_m; // Circle radius in meter (only valid, if mode =
WAYPOINT_MODE_CIRCLE)
boolean circle_clockwise; // true for clockwise, false for
counter-clockwise (only valid, if mode = WAYPOINT_MODE_CIRCLE)
EWPMode mode;
EWaypointType eWaypointType;
STurnModeConstraint sTurnModeConstraint; // TODO: shift constraints to
routenplaner_cmd_qe
SPositionConstraint sPositionConstraint;
SAltitudeConstraint sAltitudeConstraint;
STimeConstraint sTimeConstraint;
};
typedef sequence<SWaypoint> LWaypoint;
typedef sequence<long> LWpId;
struct SRoute
{
boolean initialized; // A Route is valid if this flag is true.
long id; // Unique ID for identification
string name;
//long nextRoutepointId; // only for MiRA integration. moved to
SFMSOutput->sCurrentRoute.routepointIndex
//LWaypoint lWaypoint; // only for MiRA integration. moved to
SRouteData->lWaypoint
LWpId lWpId; // For the new FMS a route consists of waypoint ids.
Waypoints are stored separately. The order of the waypoints corresponds
to the sequence order
};
typedef sequence<SRoute> LRoute;
typedef sequence<long> LRouteIds;
#endif
---- AircraftInterface.idl ---
#ifndef AIRCRAFTINTERFACE_IDL
#define AIRCRAFTINTERFACE_IDL
#include "commonBasicTypes.idl"
enum EAircraftType
{
AIRCRAFTTYPE_PLANE,
AIRCRAFTTYPE_HELI
};
struct SIdentification
{
short id; //id specified by the scenario simulation (and send to x-plane
via the d-sim control plugin)
string name;
string identifier; //military or civil aircraft identifier
EAircraftType eAircraftType;
//EAircraftModel eAircraftModel;
boolean isManned;
};
struct SAircraftAttitude
{
double phi_rad; // roll
double theta_rad; // pitch
double psi_rad_magN; // yaw
double psi_rad_trueN; // yaw
};
struct SAircraftRates
{
//in flugzeugkoordinaten
double p_rad_s; // phi_dot
double q_rad_s; // theta_dot
double r_rad_s; // psi_dot
};
struct SAircraftAccelerations
{
//in flugzeugkoordinaten
double x_m_s_s;
double y_m_s_s;
double z_m_s_s;
};
struct SAircraftVelocities
{
double north_m_s;
double east_m_s;
double vertical_m_s;
double ias_m_s;
double cas_m_s;
double tas_m_s;
double gs_m_s;
};
struct SFlightMechanics
{
SGeoPos sPos;
SAircraftAttitude sAtt;
SAircraftRates sRat;
SAircraftAccelerations sAcc;
SAircraftVelocities sVel;
double magneticVariation_rad;
};
struct SRotorState
{
double rpm_rad_s;
double torque_nm;
double maxTorque_nm; //used for % calculation of the torque;
};
enum EEngineOperatingState
{
ENGINESTATE_ON,
ENGINESTATE_OFF,
ENGINESTATE_STARTUP
};
struct SEngineState
{
double rpm_rad_s;
double torque_nm;
double maxTorque_nm; // used for % calculation of the
torque
double curFuelConsumption_kg_s;
EEngineOperatingState eOpState;
};
enum EGearState
{
GEAR_UP,
GEAR_DOWN,
GEAR_TRANSIT
};
struct SGearState
{
EGearState nose;
EGearState right;
EGearState left;
};
struct SSystemData
{
SRotorState sRotor;
long noOfEngines;
sequence<SEngineState,2> sEngine;
SGearState sGear;
double flaps; //-1 .. +1
double spoiler; //-1 .. +1
double break; //-1 .. +1
};
struct SCurrentInput
{
double roll; //-1 .. +1
double pitch; //-1 .. +1
double yaw; //-1 .. +1
double collective; //-1 .. +1
double throttle1; //-1 .. +1 0= no power +1 100% power
double throttle2; //-1 .. +1 0= no power +1 100% power
double trimRoll; //-1 .. +1
double trimPitch; //-1 .. +1
double trimYaw; //-1 .. +1
double trimCollective; //-1 .. +1
double flaps; //-1 .. +1 -> 0 = neutral (in) +1= down -1 = up ????????
double brakes; //-1 .. +1
double spoiler;
boolean gearUp;
};
struct SSateliteState
{
boolean l1Locked;
boolean l2Locked;
};
struct SGPSHealth
{
double pdop_m; // positional dilution of precision
double hdop_m; // horizontal dilution of precision
long noSat; // number of satellites
sequence<SSateliteState,20> sSateliteState;
long itow_ms; // international time of week
};
struct SSystemHealth
{
SGPSHealth sGPS;
boolean destroyed; // true => the aircraft is lost
};
struct SBaroData
{
double pressure_hPa;
double qnh_hPa;
double alt_m;
};
struct SSensorics
{
boolean hasGroundContact;
double airTemp_celsius;
SBaroData sBaroData;
double radarAlt_m;
double sonarAlt_m;
double laserAlt_m;
};
struct SWindData
{
double speed_m_s;
double dir_rad_magN;
double dir_rad_trueN;
};
struct SWeatherData
{
SWindData sWind;
};
struct SAircraftInterface
{
SIdentification sId;
SFlightMechanics sFm;
SSystemData sSystem;
SSystemHealth sHealth;
SSensorics sSensorics;
SWeatherData sWeather;
SCurrentInput sCurrentInput;
double simTime;
};
#endif
Here is the also the source cpp file I wrote and used to simulate a
serialization process variables of type SAircraftInterface
--- codec_test.cpp ---
#include <QApplication>
#include "anyserial.h"
#include "ifDKAircraftInterface.h"
using namespace std;
int main( int argc, char *argv[])
{
SAircraftInterface_var aci_src, aci_dst;
CORBA::Any anyobject_src, anyobject_dst;
OctetSeq sequence;
QApplication app(argc, argv);
aci_src = new SAircraftInterface;
aci_dst = new SAircraftInterface;
//identification
aci_src->sId.name="MiRA 1";
aci_src->sId.isManned = true;
aci_src->sId.eAircraftType = AIRCRAFTTYPE_HELI;
//position
aci_src->sFm.sPos.lat_wgs84 = 10.0;
aci_src->sFm.sPos.lon_wgs84 = 20.0;
aci_src->sFm.sPos.alt_wgs84_m = 5.0;
// Convert anyobject_src to an octet sequence using MICO internal codec
anyobject_src <<= *aci_src;
anyobject_src >> sequence;
// Show octet sequence length
cout << "sequence.length: " << sequence.length() << endl;
// Try to convert octet sequence to anyobject_dst using MICO internal codec
try
{
anyobject_dst << sequence;
anyobject_dst >>= *aci_dst;
cout << "aci.name: " << aci_dst->sId.name << endl;
cout << "Sequence converted back to object of type Any." << endl;
}
catch (...)
{
cout << "Error trying to convert sequence back to object of type Any."
<< endl;
}
return ( 0 );
}
1. If you remove the line where QApplication is called the try section
works and the result is of 4016 octet for the sequence generated by the
codec;
2. If you leave the line where QAppliaction is called the try section
works well only when the two lines where aci_src and aci_dst variables are
allocated through the new operator have been placed before the
QApplication, otherwise an exception is catched and the sequence results
of 3748 octet, exactely 268 octet less than normal, as I already specified
in my previous e-mail.
void operator>> ( const Any& anyobject, OctetSeq& dataseq)
2. ifDKAircraftInterface.h has been generated with the Mico idl compiler
#ifndef __IFDKAircraftInterface_IDL__
#define __IFDKAircraftInterface_IDL__
#include "AircraftInterface.idl"
interface ifDKAircraftInterface
{
SAircraftInterface ReadData ( );
void WriteData ( in SAircraftInterface var );
long long GetVersion ( );
};
#endif // #ifndef __IFDKAircraftInterface_IDL__
Many Thanks in advance,
Pasquale Zarcone
Post by Karel Gardas
Hello,
what exactly does your anyobject Any variable contain? The strange thing
is that you are only able to duplicate the issue when you use Qt...
Cheers,
Karel
Post by Andreas Benzler
Hallo,
I´m using a client-server model based on Mico and I defined an idl
interface ifRec
{
long Register( in string name, in string ns );
void WriteData( in long id, in any data );
void SetEnv( in string Key, in string Value );
void Rec();
void Break();
void Resume();
void Replay( in double speed );
void Stop();
long Load( in string filename );
};
The WriteData function uses the parameter "data" of type Any, which
represents a structure (struct) containing other structures inside,
and
I
get a run-time error whenever a client calls this function. The client has
been compiled with Qt and uses the QApplication function. I discovered
that the run-time error it´s based on the problem that the object of type
Any is codified in the wrong way from Mico during the serialization
process only when the QApplication function is used in the client code and
also when the tree´s depth of the structures codified in the Any
object
is
too big, otherwise no run-time error comes up and the octet sequence that
represents the object, made by the Mico serialization process, has the
correct length. I also discovered that the difference between the octet
sequence with and without using QApplication is fixed and always 268 bytes
(more bytes without QApplication) and it does not depend on the complexity
of the structure that the Any object represents. I discovered this last
detail simulating a serialization process of the Any object using the
available Mico internal codec. I tried to compile the system with the two
Mico versions 2.3.11 and 2.3.13, both versions compiled specifying
also
the
--with-qt=<qt-path> directive for the configure script, but I have same
problems.
void operator>> ( const Any& anyobject, OctetSeq& dataseq)
{
// Codec
ORB_var orb;
Object_var obj;
IOP::CodecFactory_var cf;
IOP::Encoding enc2;
IOP::Codec_ptr codec_ptr;
// Generate codec based on CodecFactory
int argc = 1;
char* argv[1];
argv[0] = "anyserial";
orb = ORB_init( argc, argv, "mico-local-orb" );
obj = orb->resolve_initial_references("CodecFactory");
cf = IOP::CodecFactory::_narrow(obj);
enc2.format = IOP::ENCODING_CDR_ENCAPS;
enc2.major_version = 1;
enc2.minor_version = 2;
codec_ptr = cf->create_codec(enc2);
// Encode anyobject and generate a new octet sequence
OctetSeq_var newdataseq_ptr = codec_ptr->encode(anyobject);
int length = newdataseq_ptr->length();
// Copy generated octet sequence into dataseq
dataseq.length(length);
for (int i=0; i<length; i++)
dataseq[i] = (*newdataseq_ptr)[i];
}
Any and OctetSeq types are exactly CORBA::Any and CORBA::OctetSeq types
defined in MICO.
Could please anyone help to understand why Mico has this strange behavior
and eventually to find a solution?
Many Thanks in advance,
Pasquale Zarcone
Because the mail did not come trough with my colleges account I post
this message on his behalf
Andreas
_______________________________________________
Mico-devel mailing list
http://www.mico.org/mailman/listinfo/mico-devel
--
ObjectSecurity Ltd. http://www.objectsecurity.com
_______________________________________________
Mico-devel mailing list
http://www.mico.org/mailman/listinfo/mico-devel
--
ObjectSecurity Ltd. http://www.objectsecurity.com
--
Karel Gardas ***@objectsecurity.com
ObjectSecurity Ltd. http://www.objectsecurity.com
Continue reading on narkive:
Loading...