Feature: Better log printind and lots more of parsing

This commit is contained in:
2025-10-17 15:32:35 +01:00
parent 529469e2e3
commit 1fe0452ad6
5 changed files with 144 additions and 62 deletions
+12
View File
@@ -49,6 +49,18 @@ int32_t read_int32(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok
return (int32_t)ntohl(v);
}
void read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, float *out, int *ok) {
if (!ensure(recv_len, *offset, sizeof(float))) {
*ok = 0;
return;
}
uint32_t v;
memcpy(&v, buf + *offset, sizeof(v));
*offset += sizeof(v);
v = ntohl(v);
memcpy(out, &v, sizeof(float));
}
void read_bytes(const u_int8_t *buf, size_t recv_len, size_t *offset, u_int8_t *out, size_t len, int *ok) {
if (!ensure(recv_len, *offset, len)) {
*ok = 0;
+4
View File
@@ -33,6 +33,10 @@ u_int32_t read_uint32(const u_int8_t *buf, size_t recv_len, size_t *offset, int
// Advances the offset by 4 bytes.
int32_t read_int32(const u_int8_t *buf, size_t recv_len, size_t *offset, int *ok);
// Reads a 32-bit float from the buffer in network byte order.
// Advances the offset by 4 bytes.
void read_float(const u_int8_t *buf, size_t recv_len, size_t *offset, float *out, int *ok);
// Reads a fixed number of bytes into the output buffer.
// The output buffer must be at least 'len' bytes long.
void read_bytes(const u_int8_t *buf, size_t recv_len, size_t *offset, u_int8_t *out, size_t len, int *ok);
+7 -1
View File
@@ -62,6 +62,8 @@ struct postion {
struct carAtributes {
// Related to ACSP_CAR_INFO
u_char isConnected; // 1 = connected, 0 = disconnected
u_char isLoading; // 1 = loading, 0 = not loading
char *car_model;
char *car_skin;
char *driver_name;
@@ -74,6 +76,10 @@ 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;
float_t normalizedSplinePos;
} __attribute__((packed));
@@ -104,7 +110,7 @@ struct trackAtributes {
u_int8_t road_temp;
char *weather_graphics;
int32_t elapsed_ms;
u_int32_t elapsed_ms;
} __attribute__((packed));
enum ACSP_MessageType {