MotorControlModuleSDFM_TMS3.../Projects/EFC_Application/UMLibrary/communication/hiperface/HipPosition.hh

80 lines
2.1 KiB
C++

/*
* HipPosition.h
*
* Created on: 20 ôåâð. 2020 ã.
* Author: user
*/
#ifndef UMLIBRARY_COMMUNICATION_HIPERFACE_HIPPOSITION_H_
#define UMLIBRARY_COMMUNICATION_HIPERFACE_HIPPOSITION_H_
#include "../../math/math_inc.hh"
#include "../../driver/HiperfaceNetworkDriver.hh"
namespace communication {
namespace hiperface {
class HipPositionClient {
private:
driver::HiperfaceNetworkDriver & hip_driver;
mutable unsigned long position_code;
struct HipPosition {
unsigned char rec_data[4];
driver::MessageControl message_control = {
.address = 0,
.code = 0x42,
.send_data_size = 0,
.send_data = nullptr,
.rec_data_size = 4,
.rec_data = rec_data,
.timeout_ms = 10,
.ans_ready_flag = false,
.result = driver::OK
};
} position_request; bool request = false;
struct HipSetPosition {
struct {
unsigned char access_code = 0x55;
unsigned char send_data[4];
};
driver::MessageControl message_control = {
.address = 0,
.code = 0x43,
.send_data_size = 5,
.send_data = &access_code,
.rec_data_size = 0,
.rec_data = nullptr,
.timeout_ms = 40,
.ans_ready_flag = false,
.result = driver::OK
};
} set_position_request; bool set_request = false;
public:
///Âîçâðàùàåò àáñîëþòíîå ïîëîæåíèå â îòñ÷åòàõ.
unsigned long getPositionCode() const;
void set(unsigned long position);
bool sendRequest() { return hip_driver.send( &position_request.message_control ); }
bool isAnswerReady() const { return position_request.message_control.ans_ready_flag; }
bool isOk() const { return position_request.message_control.result == driver::OK; }
HipPositionClient( driver::HiperfaceNetworkDriver & hip_driver, unsigned short address);
};
} /* namespace hiperface */
} /* namespace communication */
#endif /* UMLIBRARY_COMMUNICATION_HIPERFACE_HIPPOSITION_H_ */