generated from AfonsoCMSousa/CPP-Template
Feature: Sends request to increase update rate
This commit is contained in:
parent
32b496b596
commit
8c6577bb2e
BIN
PlayerTracker
BIN
PlayerTracker
Binary file not shown.
@ -4,6 +4,9 @@
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAX_PLAYERS 64
|
||||
const int MAX_TELEMETRY_CLIENTS = 128;
|
||||
|
||||
typedef struct handshake {
|
||||
// [not used in the current Remote Telemtry version by AC]
|
||||
// In future versions it will identify the platform type of the client.
|
||||
@ -59,17 +62,17 @@ typedef struct postion {
|
||||
} __attribute__((packed)) postion;
|
||||
|
||||
typedef enum flag {
|
||||
NO_FLAG = 0,
|
||||
YELLOW_FLAG = 1,
|
||||
BLUE_FLAG = 2,
|
||||
BLACK_FLAG = 3,
|
||||
CHECKERED_FLAG = 4,
|
||||
NO_FLAG = 0,
|
||||
YELLOW_FLAG = 1,
|
||||
BLUE_FLAG = 2,
|
||||
BLACK_FLAG = 3,
|
||||
CHECKERED_FLAG = 4,
|
||||
} __attribute__((packed)) flag;
|
||||
|
||||
typedef struct carAtributes {
|
||||
// Related to ACSP_CAR_INFO
|
||||
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_skin;
|
||||
@ -83,16 +86,16 @@ typedef struct carAtributes {
|
||||
postion velocity;
|
||||
u_int8_t carGear;
|
||||
u_int16_t carRPM;
|
||||
u_int32_t lap_time;
|
||||
u_int32_t cuts;
|
||||
u_int32_t total_cuts;
|
||||
u_int32_t total_cuts_alltime;
|
||||
u_int16_t total_laps_completed;
|
||||
u_int16_t contacts;
|
||||
u_int16_t total_contacts;
|
||||
u_int32_t lap_time;
|
||||
u_int32_t cuts;
|
||||
u_int32_t total_cuts;
|
||||
u_int32_t total_cuts_alltime;
|
||||
u_int16_t total_laps_completed;
|
||||
u_int16_t contacts;
|
||||
u_int16_t total_contacts;
|
||||
|
||||
flag current_flag; // TODO: implement flag status updates
|
||||
// TAG:3
|
||||
flag current_flag; // TODO: implement flag status updates
|
||||
// TAG:3
|
||||
|
||||
float normalizedSplinePos;
|
||||
} __attribute__((packed)) carAtributes;
|
||||
@ -100,7 +103,7 @@ typedef struct carAtributes {
|
||||
typedef struct carAtributesAPI {
|
||||
// Related to ACSP_CAR_INFO
|
||||
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_skin[64];
|
||||
@ -114,21 +117,20 @@ typedef struct carAtributesAPI {
|
||||
postion velocity;
|
||||
u_int8_t carGear;
|
||||
u_int16_t carRPM;
|
||||
u_int32_t lap_time;
|
||||
u_int32_t cuts;
|
||||
u_int32_t total_cuts;
|
||||
u_int32_t total_cuts_alltime;
|
||||
u_int16_t total_laps_completed;
|
||||
u_int16_t contacts;
|
||||
u_int16_t total_contacts;
|
||||
u_int32_t lap_time;
|
||||
u_int32_t cuts;
|
||||
u_int32_t total_cuts;
|
||||
u_int32_t total_cuts_alltime;
|
||||
u_int16_t total_laps_completed;
|
||||
u_int16_t contacts;
|
||||
u_int16_t total_contacts;
|
||||
|
||||
flag current_flag; // TODO: implement flag status updates
|
||||
// TAG:3
|
||||
flag current_flag; // TODO: implement flag status updates
|
||||
// TAG:3
|
||||
|
||||
float normalizedSplinePos;
|
||||
} __attribute__((packed)) carAtributesAPI;
|
||||
|
||||
|
||||
typedef enum SessionType {
|
||||
PRACTICE = 0,
|
||||
RACE = 1,
|
||||
@ -184,15 +186,39 @@ typedef struct trackAtributesAPI {
|
||||
} __attribute__((packed)) trackAtributesAPI;
|
||||
|
||||
typedef struct api_packet {
|
||||
u_char message_type; // ACSP_MessageType
|
||||
u_int8_t tracker_id;
|
||||
u_int8_t connected_players;
|
||||
u_char message_type; // ACSP_MessageType
|
||||
u_int8_t tracker_id;
|
||||
u_int8_t connected_players;
|
||||
|
||||
carAtributesAPI cars[64];
|
||||
trackAtributesAPI track_info;
|
||||
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)
|
||||
|
||||
carAtributesAPI cars[64];
|
||||
trackAtributesAPI track_info;
|
||||
|
||||
} __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 {
|
||||
// ============================
|
||||
// PROTOCOL VERSION
|
||||
|
||||
@ -21,7 +21,6 @@
|
||||
|
||||
const char *API_SOCKET_PATH = "/tmp/ACplayer_socket";
|
||||
|
||||
const int MAX_PLAYERS = 64;
|
||||
const char *SERVER_OUT_IP = "127.0.0.1";
|
||||
|
||||
u_int8_t SERVER_ID;
|
||||
@ -259,7 +258,13 @@ int main(int argc, char *argv[]) {
|
||||
trackInfo.session_name = (char *)malloc(64);
|
||||
|
||||
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");
|
||||
while (1) {
|
||||
offset = 0;
|
||||
@ -267,7 +272,13 @@ int main(int argc, char *argv[]) {
|
||||
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
|
||||
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
|
||||
#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.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("\tLap Time: %5d ms\n", update.lap_time);
|
||||
printf("\tCuts this lap: %d\n", update.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);
|
||||
break;
|
||||
|
||||
@ -650,6 +666,10 @@ int main(int argc, char *argv[]) {
|
||||
// TODO: Update total contacts for both players in the database
|
||||
// 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);
|
||||
} break;
|
||||
|
||||
@ -663,6 +683,9 @@ int main(int argc, char *argv[]) {
|
||||
// TODO: Update total contacts for the player in the database
|
||||
// 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);
|
||||
} break;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user