|
|
@ -14,8 +14,16 @@ ps_packet::ps_packet(uint8_t _src_addr, uint8_t _dest_addr,
|
|
|
|
src_addr = &data[1];
|
|
|
|
src_addr = &data[1];
|
|
|
|
dest_addr = &data[2];
|
|
|
|
dest_addr = &data[2];
|
|
|
|
frame_data_len = &data[3];
|
|
|
|
frame_data_len = &data[3];
|
|
|
|
|
|
|
|
frame_data = &data[4];
|
|
|
|
|
|
|
|
msg_len = 5 + _frame_data_len;
|
|
|
|
checksum = nullptr;
|
|
|
|
checksum = nullptr;
|
|
|
|
memcpy(frame_data, _frame_data, MAX_FRAME_DATA_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
*src_addr = _src_addr;
|
|
|
|
|
|
|
|
*dest_addr = _dest_addr;
|
|
|
|
|
|
|
|
*frame_data_len = _frame_data_len;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
memset(frame_data, 0, MAX_FRAME_DATA_LEN);
|
|
|
|
|
|
|
|
memcpy(frame_data, _frame_data, _frame_data_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ps_packet::~ps_packet()
|
|
|
|
ps_packet::~ps_packet()
|
|
|
|
{}
|
|
|
|
{}
|
|
|
@ -53,19 +61,6 @@ bool ps_packet::validate()
|
|
|
|
void ps_packet::calc_checksum()
|
|
|
|
void ps_packet::calc_checksum()
|
|
|
|
{}
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
ps_packet ps_packet::from_xy(int32_t x, int32_t y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t frame_data[MAX_FRAME_DATA_LEN];
|
|
|
|
|
|
|
|
memset(frame_data, 0, MAX_FRAME_DATA_LEN);
|
|
|
|
|
|
|
|
// op command
|
|
|
|
|
|
|
|
// 0x01 = set xy
|
|
|
|
|
|
|
|
frame_data[0] = 0x01; // + 1
|
|
|
|
|
|
|
|
memcpy(&frame_data[1], &x, 4; // + sizeof(x)
|
|
|
|
|
|
|
|
memcpy(&frame_data[5], &y, 4); // + sizeof(y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ps_packet(MASTER_ADDR, 0x02, frame_data, 1 + sizeof(x) + sizeof(y));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ps_packet::stuff_bytes()
|
|
|
|
bool ps_packet::stuff_bytes()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int old_ind = 0;
|
|
|
|
int old_ind = 0;
|
|
|
@ -97,3 +92,16 @@ bool ps_packet::destuff_bytes()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ps_packet ps_packet::from_xy(int32_t x, int32_t y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t frame_data[MAX_FRAME_DATA_LEN];
|
|
|
|
|
|
|
|
memset(frame_data, 0, MAX_FRAME_DATA_LEN);
|
|
|
|
|
|
|
|
// op command
|
|
|
|
|
|
|
|
// 0x01 = set xy
|
|
|
|
|
|
|
|
frame_data[0] = 0x01; // + 1
|
|
|
|
|
|
|
|
memcpy(&frame_data[1], &x, 4); // + sizeof(x)
|
|
|
|
|
|
|
|
memcpy(&frame_data[5], &y, 4); // + sizeof(y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ps_packet(MASTER_ADDR, 0x02, frame_data, 1 + sizeof(x) + sizeof(y));
|
|
|
|
|
|
|
|
}
|
|
|
|