For FS-to-FS test case we do use windows timing: it's not very precise timing, but almost quick. With a simple 'Sleep(0)' in the data read&send loop we send messages at intervals ranging from 5-6 to 15ms.
To get quicker sending times, just minimize the source FS window (when minimized FS continues to run but its CPU usage is 1/10 than usual).
My main loop at receiver's side is:
while (netRunning == true)
{
itmp = sizeof(inaddr);
retval = csock->ReceiveFrom(inbuff, BUFSZ, (SOCKADDR*) &inaddr, &itmp, 0);
if (retval == sizeof(indata))
{
fslat = inpkt->Latitude * LAT_DEG2FS;
fslon = inpkt->Longitude * LON_DEG2FS;
fsalt = inpkt->Altitude * ASL_M2FS;
fspitch = inpkt->Thetad * PRY_DEG2FS;
fsroll = inpkt->Phid * PRY_DEG2FS;
fsyaw = inpkt->Psid * PRY_DEG2FS;
fsuipc.Write(FS_LAT_FSUNITS, FS_LAT_FSUNITS_size, &fslat);
fsuipc.Write(FS_LON_FSUNITS, FS_LON_FSUNITS_size, &fslon);
fsuipc.Write(FS_ASLHGT_M65536, FS_ASLHGT_M65536_size, &fsalt);
fsuipc.Write(FS_PITCH_CIRCLE, FS_PITCH_CIRCLE_size, &fspitch);
fsuipc.Write(FS_ROLL_CIRCLE, FS_ROLL_CIRCLE_size, &fsroll);
fsuipc.Write(FS_HDG_CIRCLE, FS_HDG_CIRCLE_size, &fsyaw);
retval = fsuipc.Process();
}
}
while at the sender's:
while (this->runFlag_ == TRUE)
{
Sleep(0);
latDeg = FSDataInterface::GetLatDegrees(); // fsuipc->ReadAndProcess(0x560...)
lonDeg = FSDataInterface::GetLonDegrees(); // fsuipc->ReadAndProcess(0x568...)
hdgDeg = FSDataInterface::GetHeadingDegrees(); // fsuipc->ReadAndProcess(0x580...)
pitchDeg = FSDataInterface::GetPitchDegrees(); // fsuipc->ReadAndProcess(0x578...)
rollDeg = FSDataInterface::GetRollDegrees(); // fsuipc->ReadAndProcess(0x57c...)
hgtasl_m = FSDataInterface::GetAltitudeASL_m(); // fsuipc->ReadAndProcess(0x570...)
// ----------------- SEND DATA
indata omsg;
omsg.Latitude = latDeg;
omsg.Longitude = lonDeg;
omsg.Altitude = hgtasl_m;
omsg.Thetad = pitchDeg;
omsg.Phid = rollDeg;
omsg.Psid = hdgDeg;
pData = (void*) &omsg;
dataLen = sizeof(omsg);
dsink->Send(pData, dataLen); // This is a simple UDP socket
}
As an example, the FSDataInterface::GetLatDegrees() is
double FSDataInterface::GetLatDegrees()
{
double dval = 0.0;
DWORD dwResult;
__int64 rVal;
if (FSUIPC_Read(FS_LAT_FSUNITS, FS_LAT_FSUNITS_size, &rVal, &dwResult) &&
FSUIPC_Process(&dwResult))
{
dval = (double) rVal;
dval = dval * 90.0 / (10001750.0 * 65536.0 * 65536.0);
}
return dval;
}
PLS NOTE that we use 'double' because 'float' has insufficient precision!
ALSO note that this code is stripped out of a test application so may be somehow incomplete/incorrect.
Sorry for the long post - hope it's useful to somebody.