Make ack bit and receiver byte parameters

refactor
PgSocks 2 years ago
parent 1eca1b25e7
commit 3a2afcc93a

@ -61,7 +61,8 @@ The data is always at least one byte.
The last two bits of the attri byte starting from the LSB represent if the The last two bits of the attri byte starting from the LSB represent if the
message is an ack and if an ack is needed. The other bits in the byte are message is an ack and if an ack is needed. The other bits in the byte are
unused. unused. Any request can specify if an ack is required, or not. If no ack is
required, the drone will not send a response.
| bit | set | unset | | bit | set | unset |
|-----|-------------|-------| |-----|-------------|-------|

@ -124,7 +124,7 @@ req_send(struct Connection* conn, union Request* req, size_t length) {
} }
void void
req_finalize(struct Client* client, uint8_t cmdset, uint8_t cmdid, size_t length, union Request* req) { req_finalize(struct Client* client, uint8_t cmdset, uint8_t cmdid, uint8_t hostbyte, bool need_ack, size_t length, union Request* req) {
req->header.preamble = 0x55; req->header.preamble = 0x55;
req->header.length_l = length & 0xFF; req->header.length_l = length & 0xFF;
@ -133,8 +133,9 @@ req_finalize(struct Client* client, uint8_t cmdset, uint8_t cmdid, size_t length
req->header.seq_id = client->seq++; req->header.seq_id = client->seq++;
req->header.sender = client->hostbyte; req->header.sender = client->hostbyte;
// TODO: Figure out what this is supposed to be // TODO: Figure out what this is supposed to be
req->header.receiver = host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX); //req->header.receiver = host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX);
req->header.ack_needed = true; req->header.receiver = hostbyte;
req->header.ack_needed = need_ack;
req->header.cmdset = cmdset; req->header.cmdset = cmdset;
req->header.cmdid = cmdid; req->header.cmdid = cmdid;

@ -22,7 +22,7 @@ void
connection_read(struct Connection* connection, union Message* resp); connection_read(struct Connection* connection, union Message* resp);
void void
req_finalize(struct Client* client, uint8_t cmdset, uint8_t cmdid, size_t length, union Request* req); req_finalize(struct Client* client, uint8_t cmdset, uint8_t cmdid, uint8_t hostbyte, bool need_ack, size_t length, union Request* req);
void void
req_send(struct Connection* conn, union Request* req, size_t length); req_send(struct Connection* conn, union Request* req, size_t length);

@ -27,7 +27,7 @@ set_system_led (
req.led.t1 = t1; req.led.t1 = t1;
req.led.t2 = t2; req.led.t2 = t2;
req_finalize(session, 0x3F, SET_SYSTEM_LED_CMDID, sizeof(struct SetSystemLedReq), &req); req_finalize(session, 0x3F, SET_SYSTEM_LED_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SetSystemLedReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SetSystemLedReq)); req_send(session->dev_conn, &req, sizeof(struct SetSystemLedReq));
} }

@ -16,6 +16,6 @@ set_sdk_connection(
req.sdkconn.protocol = 0; req.sdkconn.protocol = 0;
req.sdkconn.ip_address = ip_address; req.sdkconn.ip_address = ip_address;
req.sdkconn.port = port; req.sdkconn.port = port;
req_finalize(session, 0x3F, SET_SDK_CONNECTION_CMDID, sizeof(struct SetSdkConnectionReq), &req); req_finalize(session, 0x3F, SET_SDK_CONNECTION_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SetSdkConnectionReq), &req);
req_send(session->sdk_conn, &req, sizeof(struct SetSdkConnectionReq)); req_send(session->sdk_conn, &req, sizeof(struct SetSdkConnectionReq));
} }

@ -8,6 +8,6 @@ set_sdk_mode(
bool enable ) { bool enable ) {
union Request req = {0}; union Request req = {0};
req.sdkmode.enable = enable; req.sdkmode.enable = enable;
req_finalize(session, 0x3F, SET_SDK_MODE_CMDID, sizeof(struct SetSdkModeReq), &req); req_finalize(session, 0x3F, SET_SDK_MODE_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SetSdkModeReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SetSdkModeReq)); req_send(session->dev_conn, &req, sizeof(struct SetSdkModeReq));
} }

@ -14,7 +14,7 @@ set_wheel_speed (
req.wheel.wheel_speed[1] = w2; req.wheel.wheel_speed[1] = w2;
req.wheel.wheel_speed[2] = w3; req.wheel.wheel_speed[2] = w3;
req.wheel.wheel_speed[3] = w4; req.wheel.wheel_speed[3] = w4;
req_finalize(session, 0x3F, SET_WHEEL_SPEED_CMDID, sizeof(struct SetWheelSpeedReq), &req); req_finalize(session, 0x3F, SET_WHEEL_SPEED_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SetWheelSpeedReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SetWheelSpeedReq)); req_send(session->dev_conn, &req, sizeof(struct SetWheelSpeedReq));
} }
@ -30,7 +30,7 @@ set_chassis_wheel_speed (
req.chswheel.wheel_speed[1] = w2; req.chswheel.wheel_speed[1] = w2;
req.chswheel.wheel_speed[2] = w3; req.chswheel.wheel_speed[2] = w3;
req.chswheel.wheel_speed[3] = w4; req.chswheel.wheel_speed[3] = w4;
req_finalize(session, 0x3F, SET_CHASSIS_WHEEL_SPEED_CMDID, sizeof(struct SetChassisWheelSpeedReq), &req); req_finalize(session, 0x3F, SET_CHASSIS_WHEEL_SPEED_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SetChassisWheelSpeedReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SetChassisWheelSpeedReq)); req_send(session->dev_conn, &req, sizeof(struct SetChassisWheelSpeedReq));
} }
@ -44,7 +44,7 @@ chassis_speed_mode (
req.chsspeed.speed[0] = x; req.chsspeed.speed[0] = x;
req.chsspeed.speed[1] = y; req.chsspeed.speed[1] = y;
req.chsspeed.speed[2] = z; req.chsspeed.speed[2] = z;
req_finalize(session, 0x3F, CHASSIS_SPEED_MODE_CMDID, sizeof(struct ChassisSpeedModeReq), &req); req_finalize(session, 0x3F, CHASSIS_SPEED_MODE_CMDID, host2byte(3, 6), false, sizeof(struct ChassisSpeedModeReq), &req);
req_send(session->dev_conn, &req, sizeof(struct ChassisSpeedModeReq)); req_send(session->dev_conn, &req, sizeof(struct ChassisSpeedModeReq));
} }
@ -54,7 +54,7 @@ set_robot_mode (
enum MOVEMENTMODE mode ) { enum MOVEMENTMODE mode ) {
union Request req = {0}; union Request req = {0};
req.mvmode.mode = mode; req.mvmode.mode = mode;
req_finalize(session, 0x3F, SET_ROBOT_MODE_CMDID, sizeof(struct SetRobotModeReq), &req); req_finalize(session, 0x3F, SET_ROBOT_MODE_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SetRobotModeReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SetRobotModeReq)); req_send(session->dev_conn, &req, sizeof(struct SetRobotModeReq));
} }
@ -63,7 +63,7 @@ subnode_reset (
Client session ) { Client session ) {
union Request req = {0}; union Request req = {0};
req.subnodereset.hostbyte = session->hostbyte; req.subnodereset.hostbyte = session->hostbyte;
req_finalize(session, 0x48, SUBNODE_RESET_CMDID, sizeof(struct SubNodeResetReq), &req); req_finalize(session, 0x48, SUBNODE_RESET_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SubNodeResetReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SubNodeResetReq)); req_send(session->dev_conn, &req, sizeof(struct SubNodeResetReq));
} }
@ -73,6 +73,6 @@ subscribe_add_node (
union Request req = {0}; union Request req = {0};
req.subnodeadd.hostbyte = session->hostbyte; req.subnodeadd.hostbyte = session->hostbyte;
req.subnodeadd.sub_vision = 0x03000000; req.subnodeadd.sub_vision = 0x03000000;
req_finalize(session, 0x48, SUBSCRIBE_ADD_NODE_CMDID, sizeof(struct SubscribeAddNodeReq), &req); req_finalize(session, 0x48, SUBSCRIBE_ADD_NODE_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SubscribeAddNodeReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SubscribeAddNodeReq)); req_send(session->dev_conn, &req, sizeof(struct SubscribeAddNodeReq));
} }

Loading…
Cancel
Save