Skip to content

Commit

Permalink
Merge commit 'e4044127671db324d052760fad8fcf0ac0914da5'
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremycote committed Sep 24, 2023
2 parents 477abb7 + e404412 commit 115d5de
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 9 deletions.
19 changes: 19 additions & 0 deletions UOSM-Core/Inc/ApplicationTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ typedef struct {
uint8_t data[8];
} iCommsMessage_t;

typedef struct {
float x;
float y;
float z;
} acceleration_t;

typedef struct {
float latitude;
float longitude;
float speed_kmh;
float heading;
float altitude;
} gps_coordinate_t;

typedef struct {
double pressure;
double temp;
} pressure_t;

#ifdef __cplusplus
}
#endif
Expand Down
108 changes: 108 additions & 0 deletions UOSM-Core/Utils/CANLogEntry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// Created by Jeremy Cote on 2023-09-11.
//

#ifndef UOSM_TELEMETRY_CANLOGENTRY_HPP
#define UOSM_TELEMETRY_CANLOGENTRY_HPP

#include "Identifiable.hpp"
#include "CANMessageLookUpModule.h"

enum CANLogEntryFormat {
CAN_DECIMAL,
CAN_HEX
};

/**
* @class CANLogEntry
* @brief Represents a log entry for CAN messages.
*
* An instance of the CANLogEntry class represents a CAN message type
* and their associated data. It formats and stores log messages for further processing and display.
*/
class CANLogEntry: Identifiable {
private:
/**
* The maximum length of the message.
*/
const uint8_t messageLength;

/**
* The formatted message.
*/
char* message;

/**
* The type of the CAN message.
*/
ICommsMessageLookUpIndex type;

public:
/**
* @brief Constructor for a CANLogEntry with single-value data.
* @param type The type of CAN message.
* @param value The value associated with the message.
* @param style The formatting style for the log message (default is 0). 0 is decimal. 1 is hexadecimal.
*/
CANLogEntry(ICommsMessageLookUpIndex type, uint32_t value, CANLogEntryFormat style): messageLength(20), type(type) {
message = new char[messageLength];
const char* format = style == CAN_DECIMAL ? "%s: [%d]" : "%s: [%04x]";
sprintf(message, format, prettyType(), value);
}

/**
* @brief Constructor for a CANLogEntry with two-value data.
* @param type The type of CAN message.
* @param a The first value associated with the message.
* @param b The second value associated with the message.
* @param style The formatting style for the log message (default is 0). 0 is decimal. 1 is hexadecimal.
*/
CANLogEntry(ICommsMessageLookUpIndex type, uint32_t a, uint32_t b, uint8_t style): messageLength(24), type(type) {
message = new char[messageLength];
const char* format = style == CAN_DECIMAL ? "%s: [%d] [%d]" : "%s: [%04x] [%04x]";
sprintf(message, format, prettyType(), a, b);
}

/**
* @brief Copy constructor for creating a copy of a CANLogEntry object.
* @param other The CANLogEntry object to copy.
*/
CANLogEntry(const CANLogEntry& other): messageLength(other.messageLength), type(other.type) {
message = new char[messageLength];
strcpy(message, other.message);
}


/**
* @brief Get a human-readable string representation of the CAN message type.
* @return A string describing the CAN message type.
*/
const char* prettyType() {
switch (type) {
case THROTTLE_DATA_ID:
return "Throttle";
case SPEED_DATA_ID:
return "Speed";
case MOTOR_RPM_DATA_ID:
return "RPM";
case EVENT_DATA_ID:
return "Event";
case ERROR_DATA_ID:
return "Error";
case CURRENT_VOLTAGE_DATA_ID:
return "Cur/Volt";
}

return "ExecEr";
}

/**
* @brief Get the formatted message
* @return the formatted message
*/
const char* getMessage() const {
return message;
}
};

#endif //UOSM_TELEMETRY_CANLOGENTRY_HPP
6 changes: 1 addition & 5 deletions UOSM-Core/Utils/Identifiable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// Created by Jeremy Cote on 2023-07-29.
//

#ifdef UOSM_OBSERVABLES

#include "Identifiable.hpp"

uint32_t Identifiable::nextId = 0;

#endif
uint32_t Identifiable::nextId = 0;
5 changes: 1 addition & 4 deletions UOSM-Core/Utils/Identifiable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Created by Jeremy Cote on 2023-07-29.
//

#ifdef UOSM_OBSERVABLES

#ifndef UOSM_CORE_IDENTIFIABLE_HPP
#define UOSM_CORE_IDENTIFIABLE_HPP

Expand Down Expand Up @@ -46,5 +44,4 @@ class Identifiable {
}
};

#endif //UOSM_CORE_IDENTIFIABLE_HPP
#endif
#endif //UOSM_CORE_IDENTIFIABLE_HPP

0 comments on commit 115d5de

Please sign in to comment.