-
Notifications
You must be signed in to change notification settings - Fork 0
Home
TrainerControl - is dynamic library which provide service for work with Ant+ devices like HR monitor, etc.
InitAntService(void ** ant_instanance, int & max_channels)
Initialize Ant stick instance (via libUSB) Output: ant_instanance - in case of success returns pointer to AntStic instance max_channels - max number of Ant devices which can be connected with Ant stick in same time
int CloseAntService()
Destroy Ant stick instance
int RunSearch(void * ant_instanance, void ** pp_search_service, std::thread & thread)
Run service for find and keep Ant devices Input: ant_instanance - pointer to initialized AntStick instance Output: pp_search_service - in case of success returns pointer to SearchService thread - in case of success returns service thread
int StopSearch(void ** pp_search_service, std::thread & thread)
Destroy SearchService Input: pp_search_service - pointer to SearchService thread - service thread
AntSession InitSession(void * ant_instanance, void * hrm_device, void * bike_device)
Initialize AntSession and create TelemetryServer Input: ant_instanance - pointer to AntStikc hrm_device - pointer to initialized HeartRateMonitor instance bike_device - pointer to initialized FitnessEquipmentControl instance Return value: Initialized AntSession
int GetHRMList(void * p_search_service, void ** devices, int & num_hrm)
Fill array of HeartRateMonitor by current connected Ant devices which a recognized as HR monitor Input: p_search_service - pointer to running SearchService Output: devices - array of pointers to HeartRateMonitor instances num_hrm - number of connected HR monitors
int GetBikeList(void * p_search_service, void ** devices, int & num_hrm)
Fill array of FitnessEquipmentControl by current connected Ant devices which a recognized as "bike" Input: p_search_service - pointer to running SearchService Output: devices - array of pointers to FitnessEquipmentControl instances num_hrm - number of connected "bikes"
int CloseSession(AntSession & session)
Destroy AntSession (destroy TelemetryServer but not HR Monitor and "bike") Input: session - AntSession for destroy
int Run(AntSession & session, std::thread & thread)
Run TelemetryServer Input: session - AntSession thread - thread for TelemetryServer
int Stop(AntSession & session, std::thread & thread)
Stop TelemetryServer Input: session - AntSession thread - thread for TelemetryServer
Telemetry GetTelemetry(AntSession & session)
Returns current value of telemetry Input: session - AntSession Return value: current value of telemetry
struct AntSession
{
void * m_AntStick;
void * m_TelemtryServer;
bool m_bIsRun;
};
struct Telemetry
{
Telemetry()
: hr(-1), cad(-1), spd(-1), pwr(-1) {}
double hr;
double cad;
double spd;
double pwr;
};
Application thread:
{
// parent thread for SearchService and TelemertyServer threads
}
SearchService thread:
{
// finding Ant devices, create instance and keep them
// read all messages from AntStick, send messages from device to right instance
// check current status of connected devices, destroy instance if need
}
TelemertyServer thread:
{
// check status, telemetry instances of Ant devices (which stored by SeachService)
// handling user's actions (change configuration of device, etc)
}
int main()
{
// create instance AntStick instance
void * ant_handle;
int max_channels = 0;
InitAntService(&ant_handle, max_channels);
// Run SearchService
std::thread search_thread;
void * search_service;
RunSearch(ant_handle, &search_service, search_thread);
// wait for connection HR monitor
void ** hrm_list = new void*[max_channels];
memset(hrm_list, 0, max_channels);
int num_hrm = 0;
while (num_hrm == 0)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
GetHRMList(search_service, hrm_list, num_hrm);
}
// Init AntSession with connected HR monitor
AntSession ant_session = InitSession(ant_handle, hrm_list[0]);
// Run TelemetryServer
std::thread server_thread;
Run(ant_session, server_thread);
//while (true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
Telemetry t = GetTelemetry(ant_session);
printf("HR = %lf\n", t.hr);
}
// stop TelemetryServer
Stop(ant_session, server_thread);
// destroy AntSession
CloseSession(ant_session);
// destroy SearchService
StopSearch(&search_service, search_thread);
// destroy AntStick instance
CloseAntService();
return 0;
}