From 3a2afcc93adef85427036bdb17299c8c5c998740 Mon Sep 17 00:00:00 2001 From: PgSocks Date: Sun, 1 Jan 2023 15:44:04 -0600 Subject: [PATCH] Make ack bit and receiver byte parameters --- README.md | 3 ++- src/connection.c | 7 ++++--- src/connection.h | 2 +- src/messages/led.c | 2 +- src/messages/sdk_connection.c | 2 +- src/messages/sdk_mode.c | 2 +- src/messages/set_wheel_speed.c | 12 ++++++------ 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e065835..f36166c 100644 --- a/README.md +++ b/README.md @@ -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 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 | |-----|-------------|-------| diff --git a/src/connection.c b/src/connection.c index e6165c3..ba62051 100644 --- a/src/connection.c +++ b/src/connection.c @@ -124,7 +124,7 @@ req_send(struct Connection* conn, union Request* req, size_t length) { } 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.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.sender = client->hostbyte; // TODO: Figure out what this is supposed to be - req->header.receiver = host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX); - req->header.ack_needed = true; + //req->header.receiver = host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX); + req->header.receiver = hostbyte; + req->header.ack_needed = need_ack; req->header.cmdset = cmdset; req->header.cmdid = cmdid; diff --git a/src/connection.h b/src/connection.h index cc2475c..80196c1 100644 --- a/src/connection.h +++ b/src/connection.h @@ -22,7 +22,7 @@ void connection_read(struct Connection* connection, union Message* resp); 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 req_send(struct Connection* conn, union Request* req, size_t length); diff --git a/src/messages/led.c b/src/messages/led.c index 70fa9c2..9d7ae38 100644 --- a/src/messages/led.c +++ b/src/messages/led.c @@ -27,7 +27,7 @@ set_system_led ( req.led.t1 = t1; 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)); } diff --git a/src/messages/sdk_connection.c b/src/messages/sdk_connection.c index 06dcf21..4586126 100644 --- a/src/messages/sdk_connection.c +++ b/src/messages/sdk_connection.c @@ -16,6 +16,6 @@ set_sdk_connection( req.sdkconn.protocol = 0; req.sdkconn.ip_address = ip_address; 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)); } diff --git a/src/messages/sdk_mode.c b/src/messages/sdk_mode.c index f15f7e7..1f4ef6b 100644 --- a/src/messages/sdk_mode.c +++ b/src/messages/sdk_mode.c @@ -8,6 +8,6 @@ set_sdk_mode( bool enable ) { union Request req = {0}; 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)); } diff --git a/src/messages/set_wheel_speed.c b/src/messages/set_wheel_speed.c index 6cbc737..0103c18 100644 --- a/src/messages/set_wheel_speed.c +++ b/src/messages/set_wheel_speed.c @@ -14,7 +14,7 @@ set_wheel_speed ( req.wheel.wheel_speed[1] = w2; req.wheel.wheel_speed[2] = w3; 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)); } @@ -30,7 +30,7 @@ set_chassis_wheel_speed ( req.chswheel.wheel_speed[1] = w2; req.chswheel.wheel_speed[2] = w3; 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)); } @@ -44,7 +44,7 @@ chassis_speed_mode ( req.chsspeed.speed[0] = x; req.chsspeed.speed[1] = y; 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)); } @@ -54,7 +54,7 @@ set_robot_mode ( enum MOVEMENTMODE mode ) { union Request req = {0}; 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)); } @@ -63,7 +63,7 @@ subnode_reset ( Client session ) { union Request req = {0}; 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)); } @@ -73,6 +73,6 @@ subscribe_add_node ( union Request req = {0}; req.subnodeadd.hostbyte = session->hostbyte; 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)); }