Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cube++ v0.1.1 (Priority Queue) #4

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/Core/Inc",
"${workspaceFolder}/Drivers/Inc",
"${workspaceFolder}/Libraries/embedded-template-library/include/"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"files.associations": {
"__config": "cpp",
"__hash_table": "cpp",
"__locale": "cpp",
"__split_buffer": "cpp",
"array": "cpp",
"bitset": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"functional": "cpp",
"memory_resource": "cpp",
"initializer_list": "cpp",
"istream": "cpp",
"iterator": "cpp",
"locale": "cpp",
"memory": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"string": "cpp",
"string_view": "cpp",
"unordered_map": "cpp",
"utility": "cpp",
"vector": "cpp"
}
}
7 changes: 5 additions & 2 deletions Core/Command.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/**
******************************************************************************
* File Name : Command.cpp
* Description : Command contains the core component base class for all tasks.
* Description :
*
* Command contains the core event object for tasks.
*
* The order of usage for command memory requires that whenever a command is pulled out from a queue
* you MUST call Reset() on the command. This will free any memory that was allocated for the command if
* it is necessary, the logic is internal.
*
******************************************************************************
*/
#include <Core/Inc/Command.hpp>
#include "Core/Inc/Command.hpp"

#include "CubeDefines.hpp"
#include "SystemDefines.hpp"
Expand Down
48 changes: 41 additions & 7 deletions Core/CubeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @param size: The size of the array
* @return Returns the average as a uint16_t
*/
uint16_t Utils::averageArray(uint16_t array[], int size)
uint16_t Utils::AverageArray(uint16_t array[], int size)
{
uint32_t sum = 0;

Expand All @@ -36,7 +36,7 @@ uint16_t Utils::averageArray(uint16_t array[], int size)
* @param startIndex: The index to start storing the bytes at
* @param value: The int32 to convert
*/
void Utils::writeInt32ToArrayBigEndian(uint8_t* array, int startIndex, int32_t value)
void Utils::WriteInt32ToArrayBigEndian(uint8_t* array, int startIndex, int32_t value)
{
array[startIndex + 0] = (value >> 24) & 0xFF;
array[startIndex + 1] = (value >> 16) & 0xFF;
Expand All @@ -50,7 +50,7 @@ void Utils::writeInt32ToArrayBigEndian(uint8_t* array, int startIndex, int32_t v
* @param startIndex, where the data field starts in the array
* @return The value read from the array in big endian format
*/
int32_t Utils::readInt32FromArrayBigEndian(uint8_t* array, int startIndex)
int32_t Utils::ReadInt32FromArrayBigEndian(uint8_t* array, int startIndex)
{
int32_t temp = 0;
temp += (array[startIndex + 0] << 24); // eeprom reads little or big endian?
Expand All @@ -65,7 +65,7 @@ int32_t Utils::readInt32FromArrayBigEndian(uint8_t* array, int startIndex)
* @param data The data to generate the checksum for
* @param size The size of the data array in uint8_t
*/
uint32_t Utils::getCRC32Aligned(uint8_t* data, uint32_t size)
uint32_t Utils::GetCRC32Aligned(uint8_t* data, uint32_t size)
{
// Figure out the number of bytes to pad by
uint8_t pad = 0;
Expand All @@ -92,7 +92,7 @@ uint32_t Utils::getCRC32Aligned(uint8_t* data, uint32_t size)
* @param size The size of the data array in uint8_t
* @return The CRC16 checksum
*/
uint16_t Utils::getCRC16(uint8_t* data, uint16_t size)
uint16_t Utils::GetCRC16(uint8_t* data, uint16_t size)
{
// ETL CRC16 object
etl::crc16_xmodem crc;
Expand All @@ -117,7 +117,7 @@ uint16_t Utils::getCRC16(uint8_t* data, uint16_t size)
bool Utils::IsCrc16Correct(uint8_t* data, uint16_t size, uint16_t crc)
{
// First we calculate the crc16 for the buffer
uint16_t calculatedCrc = getCRC16(data, size);
uint16_t calculatedCrc = GetCRC16(data, size);

return (calculatedCrc == crc);
}
Expand All @@ -127,7 +127,7 @@ bool Utils::IsCrc16Correct(uint8_t* data, uint16_t size, uint16_t crc)
* @param str The string to convert, must be null terminated
* @return The converted int32_t, or ERRVAL on an error
*/
int32_t Utils::stringToLong(const char* str)
int32_t Utils::StringToLong(const char* str)
{
int32_t result = 0;
const uint8_t size = (strlen(str) < 255) ? strlen(str) : 255;
Expand All @@ -147,5 +147,39 @@ int32_t Utils::stringToLong(const char* str)
}

return result;
}

/**
* @brief Extracts an integer parameter from a string
* @brief msg Message to extract from, MUST be at least identifierLen long, and properly null terminated
* @brief identifierLen Length of the identifier eg. 'rsc ' (Including the space) is 4
*
* @example if (strncmp(msg, "rsc ", 4) == 0) { // Notice the 4 here coresponds to the 4 in ExtractIntParameter
* // Get parameter
* int32_t state = ExtractIntParameter(msg, 4);
*
* // Error check the state variable (confine to parameters)
* if (state != ERRVAL && state > 0 && state < UINT16_MAX) {
* // Do something with the 'state' variable
* }
* }
*
* @return ERRVAL on failure, otherwise the extracted value
*/
int32_t Utils::ExtractIntParameter(const char* msg, uint16_t identifierLen)
{
// Handle a command with an int parameter at the end
if (static_cast<uint16_t>(strlen(msg)) < identifierLen+1) {
CUBE_PRINT("Int parameter insufficient length\r\n");
return ERRVAL;
}

// Extract the value and attempt conversion to integer
const int32_t val = Utils::StringToLong(&msg[identifierLen]);
if (val == ERRVAL) {
CUBE_PRINT("Int parameter invalid value\r\n");
}

return val;
}

19 changes: 11 additions & 8 deletions Core/Inc/CubeUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ constexpr double MATH_PI = 3.14159265358979323846;
#define GET_COBS_MAX_LEN(len) (((len) + ((len) / 254) + 1) + 1) // Get the max length of a COBS encoded string, we add 1 for the 0x00 delimiter

// Conversion macros (SYSTEM)
#define TICKS_TO_MS(time_ticks) ((time_ticks) * 1000 / osKernelSysTickFrequency) // System ticks to milliseconds
#define MS_TO_TICKS(time_ms) ((time_ms) * osKernelSysTickFrequency / 1000) // Milliseconds to system ticks
#define TICKS_TO_MS(time_ticks) ((time_ticks) * (1000 / osKernelSysTickFrequency)) // System ticks to milliseconds
#define MS_TO_TICKS(time_ms) ((time_ms) * (osKernelSysTickFrequency / 1000)) // Milliseconds to system ticks

// System Time Macros
constexpr uint32_t MAX_DELAY_MS = TICKS_TO_MS(portMAX_DELAY);
Expand All @@ -39,13 +39,13 @@ constexpr uint32_t MAX_DELAY_TICKS = portMAX_DELAY;
namespace Utils
{
// Arrays
uint16_t averageArray(uint16_t array[], int size);
void writeInt32ToArrayBigEndian(uint8_t* array, int startIndex, int32_t value);
int32_t readInt32FromArrayBigEndian(uint8_t* array, int startIndex);
uint16_t AverageArray(uint16_t array[], int size);
void WriteInt32ToArrayBigEndian(uint8_t* array, int startIndex, int32_t value);
int32_t ReadInt32FromArrayBigEndian(uint8_t* array, int startIndex);

// CRC
uint32_t getCRC32Aligned(uint8_t* data, uint32_t size);
uint16_t getCRC16(uint8_t* data, uint16_t size);
uint32_t GetCRC32Aligned(uint8_t* data, uint32_t size);
uint16_t GetCRC16(uint8_t* data, uint16_t size);

bool IsCrc16Correct(uint8_t* data, uint16_t size, uint16_t crc);

Expand All @@ -55,7 +55,10 @@ namespace Utils
inline bool IsAsciiLowercase(uint8_t c) { return (c >= 'a' && c <= 'z'); }

// String to number conversion
int32_t stringToLong(const char* str);
int32_t StringToLong(const char* str);

// Debug functionality
int32_t ExtractIntParameter(const char* msg, uint16_t identifierLen);


}
Expand Down
Loading