- added debug switch FS_DEBUG. With FS_DEBUG
- learn and eval Fs statistics - extra Gui element - lower Sample rate - try to detect replay mode - changes to FSM control git-svn-id: http://moon:8086/svn/software/trunk/projects/FsTrack@188 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+157
-15
@@ -6,14 +6,27 @@
|
||||
*/
|
||||
|
||||
#include "FsLink.hpp"
|
||||
|
||||
#include "memdump.h"
|
||||
#define TWO_PWR_16 (65536.0)
|
||||
#define TWO_PWR_32 (TWO_PWR_16*TWO_PWR_16)
|
||||
#ifdef FS_DEBUG
|
||||
#define TIMER_INTEVAL_MS 1000
|
||||
#else
|
||||
#define TIMER_INTEVAL_MS 100
|
||||
|
||||
#endif
|
||||
const char* FsLink::linkStateString[] = {"Init", "Disconnected", "Connected", "Paused", "Recording"};
|
||||
const char* FsLink::flightStateString[] = {"Init", "Suspend", "Ground", "Take off", "Enroute", "Touch down"};
|
||||
|
||||
typedef struct _DumpStatistics
|
||||
{
|
||||
bool isDynamic;
|
||||
|
||||
} DumpStatistics;
|
||||
|
||||
static DumpStatistics dumpStatistics[0x7800];
|
||||
static uint8_t dumpStatisticsDataInitial[0x7800];
|
||||
static uint8_t dumpStatisticsDataCurr[0x7800];
|
||||
|
||||
FsLink::FsLink(const char *pDocRoot)
|
||||
: m_docRoot(pDocRoot)
|
||||
, m_pKml(nullptr)
|
||||
@@ -23,6 +36,8 @@ FsLink::FsLink(const char *pDocRoot)
|
||||
, m_flightStateNext(fs_suspend)
|
||||
, m_kmlUpdateInterval(10)
|
||||
, m_kmlUpdateCount(0)
|
||||
, m_dumpOffset(0)
|
||||
, m_dumpLearnCount(0)
|
||||
{
|
||||
startTimer(TIMER_INTEVAL_MS);
|
||||
}
|
||||
@@ -36,6 +51,97 @@ FsLink::~FsLink()
|
||||
{
|
||||
}
|
||||
|
||||
void FsLink::setDumpOffset(uint32_t offset)
|
||||
{
|
||||
m_dumpOffset = offset;
|
||||
}
|
||||
|
||||
void FsLink::dump()
|
||||
{
|
||||
uint8_t dump[1024];
|
||||
DWORD result;
|
||||
|
||||
printf("---------------------------------------------------\n");
|
||||
FSUIPC_Read(m_dumpOffset, sizeof(dump), dump, &result);
|
||||
if (result == FSUIPC_ERR_OK)
|
||||
FSUIPC_Process(&result);
|
||||
|
||||
if (result == FSUIPC_ERR_OK)
|
||||
{
|
||||
memdump(dump, m_dumpOffset, 16, sizeof(dump));
|
||||
}
|
||||
}
|
||||
|
||||
void FsLink::statisticsLearnStart(uint32_t count)
|
||||
{
|
||||
DWORD result;
|
||||
|
||||
m_dumpLearnCount = count;
|
||||
memset(dumpStatistics, 0, sizeof(dumpStatistics));
|
||||
FSUIPC_Read(0, sizeof(dumpStatisticsDataInitial), dumpStatisticsDataInitial, &result);
|
||||
if (result == FSUIPC_ERR_OK)
|
||||
FSUIPC_Process(&result);
|
||||
else
|
||||
printf("%s: Problem FSUIPC_Read\n", __func__);
|
||||
|
||||
printf("Learning(%d) ", m_dumpLearnCount);
|
||||
}
|
||||
|
||||
void FsLink::statisticsLearn()
|
||||
{
|
||||
DWORD result;
|
||||
if (m_dumpLearnCount)
|
||||
{
|
||||
FSUIPC_Read(0, sizeof(dumpStatisticsDataCurr), dumpStatisticsDataCurr, &result);
|
||||
if (result == FSUIPC_ERR_OK)
|
||||
FSUIPC_Process(&result);
|
||||
else
|
||||
printf("%s: Problem FSUIPC_Read\n", __func__);
|
||||
|
||||
for (uint32_t i=0; i < sizeof(dumpStatisticsDataInitial); i++)
|
||||
{
|
||||
if (dumpStatisticsDataInitial[i] != dumpStatisticsDataCurr[i])
|
||||
{
|
||||
dumpStatistics[i].isDynamic = true;
|
||||
}
|
||||
}
|
||||
m_dumpLearnCount--;
|
||||
if (m_dumpLearnCount)
|
||||
{
|
||||
printf(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("done\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FsLink::statisticsEval()
|
||||
{
|
||||
printf("---------------------------------------------------\n");
|
||||
printf("Dump eval\n");
|
||||
printf("---------------------------------------------------\n");
|
||||
|
||||
DWORD result;
|
||||
FSUIPC_Read(0, sizeof(dumpStatisticsDataCurr), dumpStatisticsDataCurr, &result);
|
||||
if (result == FSUIPC_ERR_OK)
|
||||
FSUIPC_Process(&result);
|
||||
else
|
||||
printf("%s: Problem FSUIPC_Read\n", __func__);
|
||||
|
||||
for (uint32_t i=0; i < sizeof(dumpStatisticsDataCurr); i++)
|
||||
{
|
||||
if (dumpStatisticsDataInitial[i] != dumpStatisticsDataCurr[i])
|
||||
{
|
||||
if (!dumpStatistics[i].isDynamic)
|
||||
{
|
||||
printf("%08X : Initial=%02X, Current=%02X\n", i, dumpStatisticsDataInitial[i], dumpStatisticsDataCurr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FsLink::addListener(IFsLinkListener *pListener)
|
||||
{
|
||||
m_listeners.add(pListener);
|
||||
@@ -92,8 +198,9 @@ int FsLink::gatherData()
|
||||
DWORD result;
|
||||
unsigned lat_lo, lon_lo, alt_lo;
|
||||
char lat[8], lon[8], alt[8], FSRdy2Fly, FSDialog;
|
||||
int lat_hi, lon_hi, alt_hi, radio_alt, bank, pitch, hdg_true, gs, tas, ias, bpa, vs, groundLevel, replay_active;
|
||||
int lat_hi, lon_hi, alt_hi, radio_alt, bank, pitch, hdg_true, gs, tas, ias, bpa, vs, groundLevel;
|
||||
short mag_var, parking_brake, paused, framerate, plane_on_ground;
|
||||
short replay_active;
|
||||
|
||||
FSUIPC_Read(0x600C, sizeof(m_flightData.timeZulu), &m_flightData.timeZulu, &result);
|
||||
FSUIPC_Read(0x20, sizeof(groundLevel), &groundLevel, &result);
|
||||
@@ -125,7 +232,7 @@ int FsLink::gatherData()
|
||||
FSUIPC_Read(0x3160, sizeof(m_flightData.atcAircraftTypeStr), m_flightData.atcAircraftTypeStr, &result);
|
||||
FSUIPC_Read(0x366, sizeof(plane_on_ground), &plane_on_ground, &result);
|
||||
FSUIPC_Read(0xBC8, sizeof(parking_brake), &parking_brake, &result);
|
||||
FSUIPC_Read(0x628, sizeof(replay_active), &replay_active, &result);
|
||||
FSUIPC_Read(0x11D4, sizeof(replay_active), &replay_active, &result);
|
||||
FSUIPC_Process(&result);
|
||||
|
||||
if (result != FSUIPC_ERR_OK)
|
||||
@@ -169,13 +276,46 @@ int FsLink::gatherData()
|
||||
m_flightData.bpa_knots = (double)bpa/128.0; // knots
|
||||
m_flightData.vs_feetPerMin = 100*(double)vs/128.0; // ft/min
|
||||
m_flightData.framerate = TWO_PWR_16/(2*framerate);
|
||||
m_flightData.isFsReady = (FSRdy2Fly == 0);
|
||||
m_flightData.isFsDialog = (FSDialog != 0);
|
||||
m_flightData.isPaused = (paused != 0);
|
||||
m_flightData.isReplay = (replay_active != 0);
|
||||
m_flightData.isReady = (FSRdy2Fly == 0) && (FSDialog == 0);
|
||||
m_flightData.isPaused = (paused != 0) && (replay_active != 0xFADE);
|
||||
m_flightData.isParked = (parking_brake != 0);
|
||||
m_flightData.isOnGround = (plane_on_ground != 0);
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
printf("\n");
|
||||
printf("FSRdy2Fly = %08X\n", FSRdy2Fly);
|
||||
printf("FSDialog = %08X\n", FSDialog);
|
||||
printf("paused = %08X\n", paused);
|
||||
printf("replay_active = %08X\n", replay_active);
|
||||
printf("\n");
|
||||
#endif
|
||||
uint32_t x = (FSRdy2Fly == 0) << 3 | (FSDialog == 0) << 2 | (replay_active == 0xfade) << 1 | (paused == 0);
|
||||
|
||||
m_flightData.state = FlightData::State::STATE_INVALID;
|
||||
switch(x)
|
||||
{
|
||||
case 0x0d:
|
||||
m_flightData.state = FlightData::State::STATE_ACTIVE;
|
||||
break;
|
||||
|
||||
case 0x09:
|
||||
case 0x0c:
|
||||
m_flightData.state = FlightData::State::STATE_PAUSED;
|
||||
break;
|
||||
|
||||
case 0x00:
|
||||
case 0x05:
|
||||
case 0x08:
|
||||
m_flightData.state = FlightData::State::STATE_STOPPED;
|
||||
break;
|
||||
|
||||
default:
|
||||
#ifdef FS_DEBUG
|
||||
printf("State : 0x%02X\n", x);
|
||||
#endif
|
||||
break;
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -202,10 +342,12 @@ void FsLink::timerCallback()
|
||||
}
|
||||
}
|
||||
|
||||
// dump();
|
||||
statisticsLearn();
|
||||
switch(m_linkState)
|
||||
{
|
||||
case ls_connected:
|
||||
if (!m_flightData.isFsDialog && m_flightData.isFsReady)
|
||||
if (m_flightData.state == FlightData::State::STATE_ACTIVE)
|
||||
{
|
||||
m_pKml->updateFlightData(m_flightData);
|
||||
if (m_pKml)
|
||||
@@ -217,13 +359,13 @@ void FsLink::timerCallback()
|
||||
break;
|
||||
|
||||
case ls_recording:
|
||||
if (m_flightData.isFsDialog && !m_flightData.isFsReady)
|
||||
if (m_flightData.state == FlightData::State::STATE_STOPPED)
|
||||
{
|
||||
m_pKml->destroy();
|
||||
m_linkStateNext = ls_connected;
|
||||
break;
|
||||
}
|
||||
if (m_flightData.isPaused || m_flightData.isReplay)
|
||||
if (m_flightData.state == FlightData::State::STATE_PAUSED)
|
||||
{
|
||||
m_linkStateNext = ls_paused;
|
||||
break;
|
||||
@@ -232,13 +374,13 @@ void FsLink::timerCallback()
|
||||
break;
|
||||
|
||||
case ls_paused:
|
||||
if (m_flightData.isFsDialog)
|
||||
if (m_flightData.state == FlightData::State::STATE_STOPPED)
|
||||
{
|
||||
m_pKml->destroy();
|
||||
m_linkStateNext = ls_connected;
|
||||
break;
|
||||
}
|
||||
if (!(m_flightData.isPaused || m_flightData.isReplay))
|
||||
if (m_flightData.state == FlightData::State::STATE_ACTIVE)
|
||||
{
|
||||
m_linkStateNext = ls_recording;
|
||||
break;
|
||||
@@ -255,7 +397,7 @@ void FsLink::timerCallback()
|
||||
if (m_linkState == ls_disconnected)
|
||||
break;
|
||||
|
||||
if (!m_flightData.isFsDialog && !m_flightData.isReplay)
|
||||
if (m_flightData.isReady && !m_flightData.isPaused)
|
||||
{
|
||||
m_flightStateNext = fs_ground;
|
||||
if (!m_flightData.isOnGround)
|
||||
@@ -293,7 +435,7 @@ void FsLink::timerCallback()
|
||||
}
|
||||
|
||||
// Override flight states
|
||||
if (m_flightData.isFsDialog || m_flightData.isReplay)
|
||||
if (!m_flightData.isReady || m_flightData.isPaused)
|
||||
{
|
||||
m_flightStateNext = fs_suspend;
|
||||
}
|
||||
|
||||
+7
-1
@@ -43,6 +43,11 @@ public:
|
||||
void addListener(IFsLinkListener *pListener);
|
||||
void setKml(IKml *pKml);
|
||||
void setUpdateInterval(double seconds);
|
||||
void setDumpOffset(uint32_t offset);
|
||||
void dump();
|
||||
void statisticsLearnStart(uint32_t count);
|
||||
void statisticsLearn();
|
||||
void statisticsEval();
|
||||
|
||||
private:
|
||||
ListenerList <IFsLinkListener> m_listeners;
|
||||
@@ -55,10 +60,11 @@ private:
|
||||
FlightState m_flightStateNext;
|
||||
int m_kmlUpdateInterval;
|
||||
int m_kmlUpdateCount;
|
||||
uint32_t m_dumpOffset;
|
||||
uint32_t m_dumpLearnCount;
|
||||
char m_idStr[256];
|
||||
char m_fsInstallPath[256];
|
||||
FlightData m_flightData;
|
||||
|
||||
static const char *linkStateString[];
|
||||
static const char *flightStateString[];
|
||||
|
||||
|
||||
+12
-4
@@ -10,9 +10,18 @@
|
||||
|
||||
struct FlightData
|
||||
{
|
||||
enum State
|
||||
{
|
||||
STATE_INVALID = 0,
|
||||
STATE_STOPPED,
|
||||
STATE_PAUSED,
|
||||
STATE_ACTIVE,
|
||||
};
|
||||
|
||||
FlightData() {}
|
||||
~FlightData() {}
|
||||
bool isFsReady, isFsDialog, isPaused, isParked, isOnGround, isReplay;
|
||||
State state;
|
||||
bool isReady, isPaused, isParked, isOnGround;
|
||||
unsigned long timeZulu;
|
||||
double lat, lon, alt_meter, alt_feet, gl_meter, bank_deg, pitch_deg, hdgTrue_deg, hdgMag_deg, gs_meterPerSec, gs_knots, tas_knots, ias_knots, bpa_knots, vs_feetPerMin, magVar_deg;
|
||||
double framerate;
|
||||
@@ -27,12 +36,11 @@ struct FlightData
|
||||
|
||||
const FlightData& operator=(const FlightData &rhs)
|
||||
{
|
||||
isFsReady = rhs.isFsReady;
|
||||
isFsDialog = rhs.isFsDialog;
|
||||
state = rhs.state;
|
||||
isReady = rhs.isReady;
|
||||
isPaused = rhs.isPaused;
|
||||
isParked = rhs.isParked;
|
||||
isOnGround = rhs.isOnGround;
|
||||
isReplay = rhs.isReplay;
|
||||
lat = rhs.lat;
|
||||
lon = rhs.lon;
|
||||
alt_meter = rhs.alt_meter;
|
||||
|
||||
@@ -202,7 +202,6 @@ XmlElement* Kml::createPlane()
|
||||
}
|
||||
pName = pPlacemark->createNewChildElement("name");
|
||||
pName->addTextElement(temp_str);
|
||||
printf("%s\n", temp_str);
|
||||
|
||||
// Description
|
||||
pDescr = pPlacemark->createNewChildElement("description");
|
||||
|
||||
@@ -102,8 +102,30 @@ MainComponent::MainComponent (String const &homeDir, String const &hostIp)
|
||||
m_labelAbout->setColour (TextEditor::textColourId, Colours::black);
|
||||
m_labelAbout->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
|
||||
|
||||
addAndMakeVisible (m_labelDumpOffset = new Label ("Label Dump Offset",
|
||||
TRANS("0")));
|
||||
m_labelDumpOffset->setFont (Font (15.00f, Font::plain));
|
||||
m_labelDumpOffset->setJustificationType (Justification::centredRight);
|
||||
m_labelDumpOffset->setEditable (true, true, false);
|
||||
m_labelDumpOffset->setColour (TextEditor::textColourId, Colours::black);
|
||||
m_labelDumpOffset->setColour (TextEditor::backgroundColourId, Colour (0x00000000));
|
||||
m_labelDumpOffset->addListener (this);
|
||||
|
||||
addAndMakeVisible (m_textButtonStatisticsLearn = new TextButton ("Button StatisticsLearn"));
|
||||
m_textButtonStatisticsLearn->setButtonText (TRANS("Learn"));
|
||||
m_textButtonStatisticsLearn->addListener (this);
|
||||
|
||||
addAndMakeVisible (m_textButtonStatisticsEval = new TextButton ("Button StatisticsEval"));
|
||||
m_textButtonStatisticsEval->setButtonText (TRANS("Eval"));
|
||||
m_textButtonStatisticsEval->addListener (this);
|
||||
|
||||
|
||||
//[UserPreSize]
|
||||
#ifndef FS_DEBUG
|
||||
m_labelDumpOffset->setVisible(false);
|
||||
m_textButtonStatisticsLearn->setVisible(false);
|
||||
m_textButtonStatisticsEval->setVisible(false);
|
||||
#endif
|
||||
//[/UserPreSize]
|
||||
|
||||
setSize (300, 300);
|
||||
@@ -155,6 +177,9 @@ MainComponent::~MainComponent()
|
||||
m_labelCameraAltitude = nullptr;
|
||||
m_labelCameraTilt = nullptr;
|
||||
m_labelAbout = nullptr;
|
||||
m_labelDumpOffset = nullptr;
|
||||
m_textButtonStatisticsLearn = nullptr;
|
||||
m_textButtonStatisticsEval = nullptr;
|
||||
|
||||
|
||||
//[Destructor]. You can add your own custom destruction code here..
|
||||
@@ -197,6 +222,9 @@ void MainComponent::resized()
|
||||
m_labelCameraAltitude->setBounds (168, 32, 88, 24);
|
||||
m_labelCameraTilt->setBounds (168, 64, 88, 24);
|
||||
m_labelAbout->setBounds (272, 0, 24, 24);
|
||||
m_labelDumpOffset->setBounds (200, 112, 72, 24);
|
||||
m_textButtonStatisticsLearn->setBounds (224, 144, 64, 24);
|
||||
m_textButtonStatisticsEval->setBounds (224, 176, 64, 24);
|
||||
//[UserResized] Add your own custom resize handling here..
|
||||
//[/UserResized]
|
||||
}
|
||||
@@ -248,6 +276,18 @@ void MainComponent::buttonClicked (Button* buttonThatWasClicked)
|
||||
m_kml->setCameraFlyToView(buttonThatWasClicked->getToggleState());
|
||||
//[/UserButtonCode_m_cameraAutoFlyToView]
|
||||
}
|
||||
else if (buttonThatWasClicked == m_textButtonStatisticsLearn)
|
||||
{
|
||||
//[UserButtonCode_m_textButtonStatisticsLearn] -- add your button handler code here..
|
||||
m_fsLink->statisticsLearnStart(m_labelDumpOffset->getText().getIntValue());
|
||||
//[/UserButtonCode_m_textButtonStatisticsLearn]
|
||||
}
|
||||
else if (buttonThatWasClicked == m_textButtonStatisticsEval)
|
||||
{
|
||||
//[UserButtonCode_m_textButtonStatisticsEval] -- add your button handler code here..
|
||||
m_fsLink->statisticsEval();
|
||||
//[/UserButtonCode_m_textButtonStatisticsEval]
|
||||
}
|
||||
|
||||
//[UserbuttonClicked_Post]
|
||||
//[/UserbuttonClicked_Post]
|
||||
@@ -276,6 +316,12 @@ void MainComponent::labelTextChanged (Label* labelThatHasChanged)
|
||||
m_CameraTilt->setValue(labelThatHasChanged->getText().getFloatValue());
|
||||
//[/UserLabelCode_m_labelCameraTilt]
|
||||
}
|
||||
else if (labelThatHasChanged == m_labelDumpOffset)
|
||||
{
|
||||
//[UserLabelCode_m_labelDumpOffset] -- add your label text handling code here..
|
||||
m_fsLink->setDumpOffset(labelThatHasChanged->getText().getHexValue32());
|
||||
//[/UserLabelCode_m_labelDumpOffset]
|
||||
}
|
||||
|
||||
//[UserlabelTextChanged_Post]
|
||||
//[/UserlabelTextChanged_Post]
|
||||
@@ -403,6 +449,17 @@ BEGIN_JUCER_METADATA
|
||||
edBkgCol="0" labelText="" editableSingleClick="0" editableDoubleClick="0"
|
||||
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
|
||||
bold="0" italic="0" justification="33"/>
|
||||
<LABEL name="Label Dump Offset" id="8a8ce24b4c3ef02b" memberName="m_labelDumpOffset"
|
||||
virtualName="" explicitFocusOrder="0" pos="200 112 72 24" edTextCol="ff000000"
|
||||
edBkgCol="0" labelText="0" editableSingleClick="1" editableDoubleClick="1"
|
||||
focusDiscardsChanges="0" fontname="Default font" fontsize="15"
|
||||
bold="0" italic="0" justification="34"/>
|
||||
<TEXTBUTTON name="Button StatisticsLearn" id="11fb0e356e3867b1" memberName="m_textButtonStatisticsLearn"
|
||||
virtualName="" explicitFocusOrder="0" pos="224 144 64 24" buttonText="Learn"
|
||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||
<TEXTBUTTON name="Button StatisticsEval" id="6acf7f6a370fc3af" memberName="m_textButtonStatisticsEval"
|
||||
virtualName="" explicitFocusOrder="0" pos="224 176 64 24" buttonText="Eval"
|
||||
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
|
||||
</JUCER_COMPONENT>
|
||||
|
||||
END_JUCER_METADATA
|
||||
|
||||
@@ -84,6 +84,9 @@ private:
|
||||
ScopedPointer<Label> m_labelCameraAltitude;
|
||||
ScopedPointer<Label> m_labelCameraTilt;
|
||||
ScopedPointer<Label> m_labelAbout;
|
||||
ScopedPointer<Label> m_labelDumpOffset;
|
||||
ScopedPointer<TextButton> m_textButtonStatisticsLearn;
|
||||
ScopedPointer<TextButton> m_textButtonStatisticsEval;
|
||||
|
||||
|
||||
//==============================================================================
|
||||
|
||||
Reference in New Issue
Block a user