#include <iomanip>
#include "SampleAppsHelper.h"
#include "rsi.h"
static std::vector<int> MinMaxAvg(std::vector<int> data)
{
int min = data[0];
int max = data[0];
int sum = 0;
for (int i = 0; i < data.size(); i++)
{
if (data[i] < min)
{
min = data[i];
}
if (data[i] > max)
{
max = data[i];
}
sum += data[i];
}
int avg = sum / data.size();
return {min, max, avg};
}
int main()
{
const std::string SAMPLE_APP_NAME = "Utilities: Record Performance";
const int RECORD_PERIOD_SAMPLES = 1;
const int RECORD_TIME = 1000;
int exitCode = -1;
try
{
int valuesPerRecord;
bool networkTimingEnabled = false;
if (controller->
NetworkStateGet() != RSINetworkState::RSINetworkStateOPERATIONAL)
{
std::cout << "Network is not operational. Only Firmware Timing Deltas will be recorded." << std::endl;
valuesPerRecord = 1;
}
else
{
networkTimingEnabled = true;
valuesPerRecord = 3;
}
{
}
if (networkTimingEnabled)
{
}
controller->
OS->
Sleep(RECORD_TIME);
std::cout << "There are " << recordCount << " records available." << std::endl;
std::vector<int> firmawareTimingDeltas(recordCount);
std::vector<int> networkTimingDeltas(recordCount);
std::vector<int> networkTimingReceiveDeltas(recordCount);
for (int i = 0; i < recordCount; i++)
{
if (networkTimingEnabled)
{
}
}
std::vector<int> firmwareTimingStats = MinMaxAvg(firmawareTimingDeltas);
std::cout << "Firmware Timing Deltas (us): ";
std::cout << " Min = " << std::setw(4) << firmwareTimingStats[0];
std::cout << " Max = " << std::setw(4) << firmwareTimingStats[1];
std::cout << " Avg = " << std::setw(4) << firmwareTimingStats[2] << std::endl;
if (networkTimingEnabled)
{
std::vector<int> networkTimingStats = MinMaxAvg(networkTimingDeltas);
std::cout << "Network Timing Deltas (us): ";
std::cout << " Min = " << std::setw(4) << networkTimingStats[0];
std::cout << " Max = " << std::setw(4) << networkTimingStats[1];
std::cout << " Avg = " << std::setw(4) << networkTimingStats[2] << std::endl;
std::vector<int> networkTimingReceiveStats = MinMaxAvg(networkTimingReceiveDeltas);
std::cout << "Network Timing Receive Deltas (us):";
std::cout << " Min = " << std::setw(4) << networkTimingReceiveStats[0];
std::cout << " Max = " << std::setw(4) << networkTimingReceiveStats[1];
std::cout << " Avg = " << std::setw(4) << networkTimingReceiveStats[2] << std::endl;
}
exitCode = 0;
}
catch (const std::exception &ex)
{
std::cerr << ex.what() << std::endl;
exitCode = -1;
}
return exitCode;
}
int32_t RecorderRecordCountGet()
Get the number of records that are stored and ready for reading.
void RecorderStart()
Start recording data.
void RecorderCircularBufferSet(bool enable)
Configure recorder as circular buffer (or not).
RSINetworkState NetworkStateGet()
void RecorderRecordDataRetrieve()
Retrieve one record of recorded data.
void RecorderDataCountSet(int32_t count)
Set the number of data values to be recorded.
uint64_t AddressGet(RSIControllerAddressType type)
Get the an address for some location on the MotionController.
int32_t RecorderRecordDataValueGet(int32_t index)
Get one value from a retrieved record.
void RecorderStop()
Stop recording data.
void Delete(void)
Delete the MotionController and all its objects.
void RecorderReset()
Reset the recorder.
int32_t RecorderCountGet()
Get the number of Recorder available in the firmware.
void RecorderDataAddressSet(int32_t index, uint64_t address)
Setup the addresses to be recorded.
void RecorderPeriodSet(uint32_t samples)
Set the number of samples between records.
void RecorderCountSet(int32_t recorderCount)
Set the number of processed Recorders in the controller.
bool RecorderEnabledGet()
Determine if the recorder is recording.
Represents the RMP soft motion controller. This class provides an interface to general controller con...
RapidCodeOS * OS
Provides access to operating system (Windows) features.
void NetworkTimingEnableSet(bool enable)
Enable or disable the firmware to start timing the network packets.
void Sleep(int32_t milliseconds)
Put the current thread to sleep.
static void PrintFooter(std::string sampleAppName, int exitCode)
Print a message to indicate the sample app has finished and if it was successful or not.
static void CheckErrors(RapidCodeObject *rsiObject)
Checks for errors in the given RapidCodeObject and throws an exception if any non-warning errors are ...
static void PrintHeader(std::string sampleAppName)
Print a start message to indicate that the sample app has started.
static MotionController::CreationParameters GetCreationParameters()
Returns a MotionController::CreationParameters object with user-defined parameters.
CreationParameters for MotionController::Create.