Feature: Sends request to increase update rate

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2025-11-13 19:36:13 +00:00
parent 32b496b596
commit 8c6577bb2e
3 changed files with 82 additions and 33 deletions

Binary file not shown.

View File

@ -4,6 +4,9 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#define MAX_PLAYERS 64
const int MAX_TELEMETRY_CLIENTS = 128;
typedef struct handshake { typedef struct handshake {
// [not used in the current Remote Telemtry version by AC] // [not used in the current Remote Telemtry version by AC]
// In future versions it will identify the platform type of the client. // In future versions it will identify the platform type of the client.
@ -59,17 +62,17 @@ typedef struct postion {
} __attribute__((packed)) postion; } __attribute__((packed)) postion;
typedef enum flag { typedef enum flag {
NO_FLAG = 0, NO_FLAG = 0,
YELLOW_FLAG = 1, YELLOW_FLAG = 1,
BLUE_FLAG = 2, BLUE_FLAG = 2,
BLACK_FLAG = 3, BLACK_FLAG = 3,
CHECKERED_FLAG = 4, CHECKERED_FLAG = 4,
} __attribute__((packed)) flag; } __attribute__((packed)) flag;
typedef struct carAtributes { typedef struct carAtributes {
// Related to ACSP_CAR_INFO // Related to ACSP_CAR_INFO
u_char isConnected; // 1 = connected, 0 = disconnected u_char isConnected; // 1 = connected, 0 = disconnected
u_char isLoading; // 1 = loading, 0 = not isLoading u_char isLoading; // 1 = loading, 0 = not isLoading
char *car_model; char *car_model;
char *car_skin; char *car_skin;
@ -83,16 +86,16 @@ typedef struct carAtributes {
postion velocity; postion velocity;
u_int8_t carGear; u_int8_t carGear;
u_int16_t carRPM; u_int16_t carRPM;
u_int32_t lap_time; u_int32_t lap_time;
u_int32_t cuts; u_int32_t cuts;
u_int32_t total_cuts; u_int32_t total_cuts;
u_int32_t total_cuts_alltime; u_int32_t total_cuts_alltime;
u_int16_t total_laps_completed; u_int16_t total_laps_completed;
u_int16_t contacts; u_int16_t contacts;
u_int16_t total_contacts; u_int16_t total_contacts;
flag current_flag; // TODO: implement flag status updates flag current_flag; // TODO: implement flag status updates
// TAG:3 // TAG:3
float normalizedSplinePos; float normalizedSplinePos;
} __attribute__((packed)) carAtributes; } __attribute__((packed)) carAtributes;
@ -100,7 +103,7 @@ typedef struct carAtributes {
typedef struct carAtributesAPI { typedef struct carAtributesAPI {
// Related to ACSP_CAR_INFO // Related to ACSP_CAR_INFO
u_char isConnected; // 1 = connected, 0 = disconnected u_char isConnected; // 1 = connected, 0 = disconnected
u_char isLoading; // 1 = loading, 0 = not isLoading u_char isLoading; // 1 = loading, 0 = not isLoading
char car_model[64]; char car_model[64];
char car_skin[64]; char car_skin[64];
@ -114,21 +117,20 @@ typedef struct carAtributesAPI {
postion velocity; postion velocity;
u_int8_t carGear; u_int8_t carGear;
u_int16_t carRPM; u_int16_t carRPM;
u_int32_t lap_time; u_int32_t lap_time;
u_int32_t cuts; u_int32_t cuts;
u_int32_t total_cuts; u_int32_t total_cuts;
u_int32_t total_cuts_alltime; u_int32_t total_cuts_alltime;
u_int16_t total_laps_completed; u_int16_t total_laps_completed;
u_int16_t contacts; u_int16_t contacts;
u_int16_t total_contacts; u_int16_t total_contacts;
flag current_flag; // TODO: implement flag status updates flag current_flag; // TODO: implement flag status updates
// TAG:3 // TAG:3
float normalizedSplinePos; float normalizedSplinePos;
} __attribute__((packed)) carAtributesAPI; } __attribute__((packed)) carAtributesAPI;
typedef enum SessionType { typedef enum SessionType {
PRACTICE = 0, PRACTICE = 0,
RACE = 1, RACE = 1,
@ -184,15 +186,39 @@ typedef struct trackAtributesAPI {
} __attribute__((packed)) trackAtributesAPI; } __attribute__((packed)) trackAtributesAPI;
typedef struct api_packet { typedef struct api_packet {
u_char message_type; // ACSP_MessageType u_char message_type; // ACSP_MessageType
u_int8_t tracker_id; u_int8_t tracker_id;
u_int8_t connected_players; u_int8_t connected_players;
carAtributesAPI cars[64]; u_int8_t cars_colided[2]; // IDs of cars involved in a collision event IF [1] == 255, [0] is the only car involved (environment collision)
trackAtributesAPI track_info;
carAtributesAPI cars[64];
trackAtributesAPI track_info;
} __attribute__((packed)) api_packet; } __attribute__((packed)) api_packet;
// Telemetry packet structure (lightweight for streaming)
struct telemetry_packet {
u_int8_t server_id;
u_int8_t car_count;
struct car_telemetry {
u_int8_t carID;
char driver_name[64];
char driver_guid[64];
char car_model[64];
postion position;
float normalizedSplinePos;
float speed_kmh;
u_int8_t gear;
u_int16_t rpm;
u_int32_t last_lap_time;
u_int32_t best_lap_time;
u_int16_t current_lap;
u_int8_t position_rank; // RENAME: position -> position_rank to avoid conflict
} __attribute__((packed)) cars[64];
} __attribute__((packed));
enum ACSP_MessageType { enum ACSP_MessageType {
// ============================ // ============================
// PROTOCOL VERSION // PROTOCOL VERSION

View File

@ -21,7 +21,6 @@
const char *API_SOCKET_PATH = "/tmp/ACplayer_socket"; const char *API_SOCKET_PATH = "/tmp/ACplayer_socket";
const int MAX_PLAYERS = 64;
const char *SERVER_OUT_IP = "127.0.0.1"; const char *SERVER_OUT_IP = "127.0.0.1";
u_int8_t SERVER_ID; u_int8_t SERVER_ID;
@ -259,7 +258,13 @@ int main(int argc, char *argv[]) {
trackInfo.session_name = (char *)malloc(64); trackInfo.session_name = (char *)malloc(64);
char message[124] = {0}; // just a place to put info messages from the server itself char message[124] = {0}; // just a place to put info messages from the server itself
u_char update_rate_message[2] = {0};
// EXPERIMENTAL: Send a message to the server to increase update rate - USING ACSP_REALTIMEPOS_INTERVAL
update_rate_message[0] = (u_char)ACSP_REALTIMEPOS_INTERVAL;
update_rate_message[1] = 255; // ms
u_char updateSent = 0;
printf("\n"); printf("\n");
while (1) { while (1) {
offset = 0; offset = 0;
@ -267,7 +272,13 @@ int main(int argc, char *argv[]) {
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
// FIX: Its not garanted to receive a full packet in one recvfrom call, but the error -1 is not handled by a unsigned size_t // FIX: Its not garanted to receive a full packet in one recvfrom call, but the error -1 is not handled by a unsigned size_t
size_t recv_bytes = (size_t)recvfrom(recv_sock_fd, buffer, sizeof(buffer), 0, NULL, NULL); size_t recv_bytes = (size_t)recvfrom(recv_sock_fd, buffer, sizeof(buffer), 0, NULL, NULL);
// Send update rate message to server ONCE
if (updateSent != 1) {
sendto(send_sock_fd, update_rate_message, sizeof(update_rate_message), 0, NULL, 0);
updateSent = 1;
}
// Convert buffer to utf-8 string and print it // Convert buffer to utf-8 string and print it
#if DEBUG_CAR_INFO #if DEBUG_CAR_INFO
@ -613,12 +624,17 @@ int main(int argc, char *argv[]) {
update.cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok); update.cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
update.total_cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok); update.total_cuts = read_uint32((const u_int8_t *)buffer, recv_bytes, &offset, &ok);
current_packet.message_type = ACSP_LAP_COMPLETED;
printf("\tCar ID: %d (%s)\n", update.carID, players[update.carID].driver_name); printf("\tCar ID: %d (%s)\n", update.carID, players[update.carID].driver_name);
printf("\tLap Time: %5d ms\n", update.lap_time); printf("\tLap Time: %5d ms\n", update.lap_time);
printf("\tCuts this lap: %d\n", update.cuts); printf("\tCuts this lap: %d\n", update.cuts);
printf("\tTotal Cuts (this session): %d\n\n", update.total_cuts); printf("\tTotal Cuts (this session): %d\n\n", update.total_cuts);
current_packet.cars_colided[0] = update.carID;
players[update.carID].total_laps_completed++;
update_api_packet(trackInfo, players); update_api_packet(trackInfo, players);
break; break;
@ -650,6 +666,10 @@ int main(int argc, char *argv[]) {
// TODO: Update total contacts for both players in the database // TODO: Update total contacts for both players in the database
// TAG:2 Update total contacts for both players // TAG:2 Update total contacts for both players
current_packet.message_type = ACSP_CE_COLLISION_WITH_CAR;
current_packet.cars_colided[0] = update.carID;
current_packet.cars_colided[1] = event_car_id;
update_api_packet(trackInfo, players); update_api_packet(trackInfo, players);
} break; } break;
@ -663,6 +683,9 @@ int main(int argc, char *argv[]) {
// TODO: Update total contacts for the player in the database // TODO: Update total contacts for the player in the database
// TAG:2 Update total contacts for the player // TAG:2 Update total contacts for the player
current_packet.message_type = ACSP_CE_COLLISION_WITH_ENV;
current_packet.cars_colided[0] = update.carID;
update_api_packet(trackInfo, players); update_api_packet(trackInfo, players);
} break; } break;
} }