MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/communication/hiperface/HipPosition.hh
2024-06-07 11:12:56 +03:00

80 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* 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_ */