Add heartbeat message

refactor
PgSocks 2 years ago
parent 3a2afcc93a
commit f0befa0b7b

@ -178,6 +178,17 @@ struct PACKED SetWheelSpeedResp
struct Footer footer; struct Footer footer;
}; };
struct PACKED SdkHeartbeatReq {
struct Header header;
struct Footer footer;
};
struct PACKED SdkHeartbeatResp {
struct Header header;
uint8_t retcode;
struct Footer footer;
};
struct PACKED SetSdkModeReq { struct PACKED SetSdkModeReq {
struct Header header; struct Header header;
uint8_t enable; uint8_t enable;
@ -213,6 +224,7 @@ union Request {
struct Header header; struct Header header;
struct SetSdkConnectionReq sdkconn; struct SetSdkConnectionReq sdkconn;
struct SetSdkModeReq sdkmode; struct SetSdkModeReq sdkmode;
struct SdkHeartbeatReq heartbeat;
struct SetSystemLedReq led; struct SetSystemLedReq led;
struct SetWheelSpeedReq wheel; struct SetWheelSpeedReq wheel;
struct SetChassisWheelSpeedReq chswheel; struct SetChassisWheelSpeedReq chswheel;
@ -225,6 +237,7 @@ union Response {
struct Header header; struct Header header;
struct SetSdkConnectionResp sdkconn; struct SetSdkConnectionResp sdkconn;
struct SetSdkModeResp sdkmode; struct SetSdkModeResp sdkmode;
struct SdkHeartbeatResp heartbeat;
struct SetSystemLedResp led; struct SetSystemLedResp led;
struct SetWheelSpeedResp wheel; struct SetWheelSpeedResp wheel;
struct SetChassisWheelSpeedResp chswheel; struct SetChassisWheelSpeedResp chswheel;

@ -19,3 +19,9 @@ set_sdk_connection(
enum CONNECTION connection_type, enum CONNECTION connection_type,
uint32_t ip_address, uint32_t ip_address,
uint16_t port ); uint16_t port );
static const uint8_t SDK_HEARTBEAT_CMDID = 0xD5;
void
sdk_heartbeat(
Client session );

@ -11,3 +11,11 @@ set_sdk_mode(
req_finalize(session, 0x3F, SET_SDK_MODE_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, 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));
} }
void
sdk_heartbeat(
Client session ) {
union Request req = {0};
req_finalize(session, 0x3F, SDK_HEARTBEAT_CMDID, host2byte(DEFAULT_CLIENT_HOST, DEFAULT_ROBOT_INDEX), true, sizeof(struct SdkHeartbeatReq), &req);
req_send(session->dev_conn, &req, sizeof(struct SdkHeartbeatReq));
}

@ -44,6 +44,13 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
sdk_heartbeat(client);
poll_message(client, &msg);
if(msg.header.cmdid != SDK_HEARTBEAT_CMDID || msg.resp.heartbeat.retcode) {
fprintf(stderr, "Did not receive heartbeat\n");
return 1;
}
int c; int c;
while((c = getopt(argc, argv, "hl:::s:::")) != -1) { while((c = getopt(argc, argv, "hl:::s:::")) != -1) {
switch(c) { switch(c) {
@ -70,11 +77,6 @@ int main(int argc, char* argv[])
atof(argv[optind + 0]), atof(argv[optind + 0]),
atof(argv[optind + 1]), atof(argv[optind + 1]),
atof(argv[optind + 2]) ); atof(argv[optind + 2]) );
poll_message(client, &msg);
if(msg.header.cmdid != CHASSIS_SPEED_MODE_CMDID || msg.resp.chsspeed.retcode) {
fprintf(stderr, "Could not set speed\n");
return 1;
}
break; break;
case '?': case '?':
default: default:

Loading…
Cancel
Save