updated the logger for static use without a static interface
added the RGB sensor isl29125 added WIFI
This commit is contained in:
@@ -9,8 +9,9 @@ idf_component_register(
|
||||
"hal/src/gpio.cpp"
|
||||
"hal/src/uart.cpp"
|
||||
|
||||
"platform/src/isl29125.cpp"
|
||||
"platform/src/logger.cpp"
|
||||
# "old/src/wifi.cpp"
|
||||
"platform/src/wifi.cpp"
|
||||
# "old/src/led_strip_encoder.c"
|
||||
# "old/src/ledmatrix.cpp"
|
||||
# "old/src/clock.cpp"
|
||||
|
||||
+26
-9
@@ -33,7 +33,9 @@
|
||||
#include "uart.h"
|
||||
|
||||
// Platform includes
|
||||
#include "isl29125.h"
|
||||
#include "logger.h"
|
||||
#include "Wifi.h"
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
@@ -48,6 +50,7 @@
|
||||
// File-scope variables
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
static TaskHandle_t loggerTaskHandle;
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
@@ -84,13 +87,14 @@ extern "C" void app_main(void)
|
||||
.rx_flow_ctrl_thresh = 0,
|
||||
.source_clk = UART_SCLK_DEFAULT
|
||||
};
|
||||
static uart_port_t debugUart = UART_NUM_0;
|
||||
uart_port_t debugUart = UART_NUM_0;
|
||||
ESP_ERROR_CHECK(uart_param_config(debugUart, &uartConfig));
|
||||
ESP_ERROR_CHECK(uart_set_pin(debugUart, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
|
||||
ESP_ERROR_CHECK(uart_driver_install(debugUart, 1024, 1024, 0, NULL, 0));
|
||||
|
||||
uart uartDebug = uart(&debugUart);
|
||||
uartDebug.open();
|
||||
uartDebug.write(255, 255, (uint8_t*)"START", 5);
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// System-wide Debug Logger
|
||||
@@ -114,8 +118,8 @@ extern "C" void app_main(void)
|
||||
|
||||
i2c_config_t i2cConfig = {
|
||||
.mode = I2C_MODE_MASTER,
|
||||
.sda_io_num = (int)4,
|
||||
.scl_io_num = (int)5,
|
||||
.sda_io_num = (int)2,
|
||||
.scl_io_num = (int)3,
|
||||
.sda_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.scl_pullup_en = GPIO_PULLUP_ENABLE,
|
||||
.master = 400000,
|
||||
@@ -127,19 +131,32 @@ extern "C" void app_main(void)
|
||||
|
||||
i2c i2cSensor = i2c(&i2c_master_port);
|
||||
i2cSensor.open();
|
||||
uint8_t i2cData[2] = {0x12, 0x34};
|
||||
i2cSensor.write(0x40, 0x00, i2cData, 2);
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// I2C RGB Sensor on I2C MasterBus for sensors
|
||||
//
|
||||
isl29125 rgbSensor = isl29125(0x44, i2cSensor);
|
||||
rgbSensor.initialize();
|
||||
vTaskDelay(100);
|
||||
rgbSensor.setMode(isl29125::RGB);
|
||||
rgbSensor.setRange(isl29125::HIGH);
|
||||
rgbSensor.setResolution(isl29125::RES_16BIT);
|
||||
vTaskDelay(100);
|
||||
struct isl29125::rgb_t rgbValue;
|
||||
rgbSensor.getRGB(&rgbValue);
|
||||
|
||||
gpio debugIO = gpio(19, gpio::Direction_t::GPIO_DIRECTION_OUTPUT, gpio::Value_t::GPIO_VALUE_LOW);
|
||||
|
||||
gpio debugIO = gpio(2, gpio::Direction_t::GPIO_DIRECTION_OUTPUT, gpio::Value_t::GPIO_VALUE_LOW);
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Wifi create and connect
|
||||
//
|
||||
Wifi wifi;
|
||||
wifi.start_client();
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
vTaskDelay(100);
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file isl29125.h
|
||||
/// \brief File description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef MAIN_PLATFORM_INC_ISL29125_H_
|
||||
#define MAIN_PLATFORM_INC_ISL29125_H_
|
||||
|
||||
/**
|
||||
* isl29125 implementation
|
||||
* \defgroup isl29125
|
||||
* \brief {group_description}
|
||||
* \addtogroup {Layer}
|
||||
*
|
||||
* Detailed description
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// CompilerIncludes
|
||||
// All include files that are provided by the compiler directly
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
// ProjectIncludes
|
||||
// All include files that are provided by the project
|
||||
#include "ISerialBus.h"
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
class isl29125
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Public Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
public:
|
||||
|
||||
struct rgb_t
|
||||
{
|
||||
uint16_t red;
|
||||
uint16_t green;
|
||||
uint16_t blue;
|
||||
} RGB_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
POWER_DOWN = 0,
|
||||
GREEN = 1,
|
||||
RED = 2,
|
||||
BLUE = 3,
|
||||
STANDBY = 4,
|
||||
RGB = 5,
|
||||
GREEN_RED = 6,
|
||||
GREEN_BLUE = 7
|
||||
} Mode_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LOW = 0,
|
||||
HIGH = 1
|
||||
} Range_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
RES_12BIT = 0,
|
||||
RES_16BIT = 1
|
||||
} Resolution_t;
|
||||
|
||||
const uint8_t deviceID = 0x7D;
|
||||
|
||||
// Class Constructor
|
||||
isl29125(uint8_t slaveAddress, ISerialBus<uint8_t>& serialPort);
|
||||
FunctionStatus initialize(void);
|
||||
|
||||
FunctionStatus setMode(Mode_t mode);
|
||||
FunctionStatus setRange(Range_t range);
|
||||
FunctionStatus setResolution(Resolution_t resolutionß);
|
||||
|
||||
FunctionStatus getRGB(struct rgb_t* rgb);
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Protected Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
protected:
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
// Private Section
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
private:
|
||||
|
||||
struct __attribute__ ((packed)) memorymap
|
||||
{
|
||||
uint8_t device_id;
|
||||
struct
|
||||
{
|
||||
uint8_t mode :3;
|
||||
uint8_t range :1;
|
||||
uint8_t bits :1;
|
||||
uint8_t sync :1;
|
||||
uint8_t RESERVERED :2;
|
||||
} configuration1;
|
||||
struct
|
||||
{
|
||||
uint8_t alscc :6;
|
||||
uint8_t RESERVED :1;
|
||||
uint8_t ircom :1;
|
||||
} configuration2;
|
||||
struct
|
||||
{
|
||||
uint8_t intsel :2;
|
||||
uint8_t prst :2;
|
||||
uint8_t conven :1;
|
||||
uint8_t RESERVED :3;
|
||||
} configuration3;
|
||||
struct
|
||||
{
|
||||
uint8_t lowByte;
|
||||
uint8_t highByte;
|
||||
} lowThreshold;
|
||||
struct
|
||||
{
|
||||
uint8_t lowByte;
|
||||
uint8_t highByte;
|
||||
} highThreshold;
|
||||
struct
|
||||
{
|
||||
uint8_t RESERVED1 :2;
|
||||
uint8_t grbcf :2;
|
||||
uint8_t RESERVED2 :1;
|
||||
uint8_t boutf :1;
|
||||
uint8_t convenf :1;
|
||||
uint8_t rgbthf :1;
|
||||
} statusFlags;
|
||||
union
|
||||
{
|
||||
uint16_t word;
|
||||
struct
|
||||
{
|
||||
uint8_t lowByte;
|
||||
uint8_t highByte;
|
||||
};
|
||||
} greenData;
|
||||
union
|
||||
{
|
||||
uint16_t word;
|
||||
struct
|
||||
{
|
||||
uint8_t lowByte;
|
||||
uint8_t highByte;
|
||||
};
|
||||
} redData;
|
||||
union
|
||||
{
|
||||
uint16_t word;
|
||||
struct
|
||||
{
|
||||
uint8_t lowByte;
|
||||
uint8_t highByte;
|
||||
};
|
||||
} blueData;
|
||||
};
|
||||
|
||||
struct memorymap memorymap;
|
||||
|
||||
uint8_t slaveAddress;
|
||||
ISerialBus<uint8_t>& bus;
|
||||
bool initialized;
|
||||
|
||||
// Reads the device ID directly into the memory map
|
||||
FunctionStatus getDeviceID(void);
|
||||
// Reads all configuration registers into the memory map
|
||||
FunctionStatus getConfiguration(void);
|
||||
// Reads all Threshold registers into the memory map
|
||||
FunctionStatus getTheshold(void);
|
||||
// Reads the status register into the memory map
|
||||
FunctionStatus getStatusFlags(void);
|
||||
// Reads the RGB data registers into the memory map
|
||||
FunctionStatus getRGBRegisters(void);
|
||||
// Read the full memory map from device into the local memory map, which creates a perfect memory copy
|
||||
FunctionStatus getCompleteRegisterMap(void);
|
||||
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
#endif /* MAIN_PLATFORM_INC_ISL29125_H_ */
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
#if defined(ENABLE_SERIAL_LOGGING)
|
||||
#define LOGGER_LOG(severity,...) \
|
||||
debugLogger.log(__FILE__, __func__, __LINE__, severity, ##__VA_ARGS__)
|
||||
logger::log(__FILE__, __func__, __LINE__, severity, ##__VA_ARGS__)
|
||||
#else
|
||||
#define LOGGER_LOG(severity, message)
|
||||
#endif
|
||||
@@ -98,9 +98,8 @@
|
||||
// Type definitions.
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class logger;
|
||||
extern logger debugLogger;
|
||||
//class logger;
|
||||
//extern logger debugLogger;
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
@@ -126,7 +125,7 @@ class logger
|
||||
// Class Constructor
|
||||
logger(uint32_t queuesize, ISerialBus<uint8_t>& serialPort);
|
||||
|
||||
FunctionStatus log(const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* format, ...);
|
||||
static FunctionStatus log(const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* format, ...);
|
||||
|
||||
// The Logger task - should be called by the system scheduler regularly
|
||||
void task();
|
||||
@@ -160,18 +159,20 @@ class logger
|
||||
|
||||
void composeTypeParameterList(void);
|
||||
|
||||
void composeLogQueueItem(struct LogQueueItem* logQueueItem, std::string fileName, std::string functionName,
|
||||
int lineNumber, LogType logType, std::string context);
|
||||
static void composeLogQueueItem(struct LogQueueItem* logQueueItem, const std::string& fileName, const std::string& functionName,
|
||||
int lineNumber, LogType logType, const std::string& context);
|
||||
|
||||
std::list<struct typeParameters> typeParameterList;
|
||||
|
||||
std::list<struct LogQueueItem> queue;
|
||||
static std::list<struct LogQueueItem> queue;
|
||||
ISerialBus<uint8_t>& port;
|
||||
uint32_t queuesize;
|
||||
uint32_t numberOfLostMessages;
|
||||
static uint32_t queuesize;
|
||||
static uint32_t numberOfLostMessages;
|
||||
static bool overflowRecovery;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@
|
||||
|
||||
// CompilerIncludes
|
||||
// All include files that are provided by the compiler directly
|
||||
#include "esp_system.h"
|
||||
//#include "esp_system.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
//#include "esp_log.h"
|
||||
//
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
//#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// \file isl29125.cpp
|
||||
/// \brief Description
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// vbchaos software design
|
||||
//
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
/// $Revision: $
|
||||
/// $Author: $
|
||||
/// $Date: $
|
||||
// (c) 2023 vbchaos
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Include files
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
#include <isl29125.h>
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
isl29125::isl29125(uint8_t slaveAddress, ISerialBus<uint8_t>& serialPort) : slaveAddress {slaveAddress}, bus {serialPort}
|
||||
{
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::initialize(void)
|
||||
{
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
|
||||
// Get the Device ID
|
||||
returnValue = getDeviceID();
|
||||
|
||||
if (returnValue == FUNCTION_STATUS_OK)
|
||||
{
|
||||
// Verify the Device ID against the default known ID
|
||||
if (memorymap.device_id != deviceID)
|
||||
{
|
||||
returnValue = FUNCTION_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (returnValue == FUNCTION_STATUS_OK)
|
||||
{
|
||||
// Fetch the complete register map for an initial copy
|
||||
returnValue = getCompleteRegisterMap();
|
||||
}
|
||||
|
||||
if (returnValue == FUNCTION_STATUS_OK)
|
||||
{
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::setMode(Mode_t mode)
|
||||
{
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
if (!initialized)
|
||||
{
|
||||
returnValue = FUNCTION_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
else
|
||||
{
|
||||
memorymap.configuration1.mode = mode;
|
||||
returnValue = bus.write(slaveAddress, 0x01, (uint8_t*)&memorymap.configuration1, 1);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::setRange(Range_t range)
|
||||
{
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
if (!initialized)
|
||||
{
|
||||
returnValue = FUNCTION_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
else
|
||||
{
|
||||
memorymap.configuration1.range = range;
|
||||
returnValue = bus.write(slaveAddress, 0x01, (uint8_t*)&memorymap.configuration1, 1);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::setResolution(Resolution_t resolution)
|
||||
{
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
if (!initialized)
|
||||
{
|
||||
returnValue = FUNCTION_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
else
|
||||
{
|
||||
memorymap.configuration1.bits = resolution;
|
||||
returnValue = bus.write(slaveAddress, 0x01, (uint8_t*)&memorymap.configuration1, 1);
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
FunctionStatus isl29125::getRGB(struct rgb_t* rgb)
|
||||
{
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
if (!initialized)
|
||||
{
|
||||
returnValue = FUNCTION_STATUS_NOT_INITIALIZED;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = getRGBRegisters();
|
||||
}
|
||||
if (returnValue == FUNCTION_STATUS_OK)
|
||||
{
|
||||
rgb->blue = memorymap.blueData.word;
|
||||
rgb->green = memorymap.greenData.word;
|
||||
rgb->red = memorymap.redData.word;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::getDeviceID(void)
|
||||
{
|
||||
uint32_t actualLength;
|
||||
return bus.read(slaveAddress, 0x00, (uint8_t*)&memorymap, 1, &actualLength);
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::getConfiguration(void)
|
||||
{
|
||||
uint32_t actualLength;
|
||||
return bus.read(slaveAddress, 0x01, (uint8_t*)&memorymap, 3, &actualLength);
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::getTheshold(void)
|
||||
{
|
||||
uint32_t actualLength;
|
||||
return bus.read(slaveAddress, 0x04, (uint8_t*)&memorymap, 4, &actualLength);
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::getStatusFlags(void)
|
||||
{
|
||||
uint32_t actualLength;
|
||||
return bus.read(slaveAddress, 0x08, (uint8_t*)&memorymap, 1, &actualLength);
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::getRGBRegisters(void)
|
||||
{
|
||||
uint32_t actualLength;
|
||||
return bus.read(slaveAddress, 0x09, (uint8_t*)&memorymap, 6, &actualLength);
|
||||
}
|
||||
|
||||
|
||||
FunctionStatus isl29125::getCompleteRegisterMap(void)
|
||||
{
|
||||
uint32_t actualLength;
|
||||
return bus.read(slaveAddress, 0x00, (uint8_t*)&memorymap, 1, &actualLength);
|
||||
}
|
||||
@@ -49,8 +49,12 @@
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
std::list<struct logger::LogQueueItem> logger::queue;
|
||||
uint32_t logger::queuesize = 16;
|
||||
uint32_t logger::numberOfLostMessages = 0;
|
||||
bool logger::overflowRecovery = false;
|
||||
|
||||
logger::logger(uint32_t queuesize, ISerialBus<uint8_t>& serialPort) : port {serialPort}, queuesize {queuesize}
|
||||
logger::logger(uint32_t queuesize, ISerialBus<uint8_t>& serialPort) : port {serialPort}
|
||||
{
|
||||
numberOfLostMessages = 0;
|
||||
// Compose the debug type level list
|
||||
@@ -63,14 +67,13 @@ FunctionStatus logger::log(const char* fileName, const char* functionName, int l
|
||||
FunctionStatus returnValue = FUNCTION_STATUS_OK;
|
||||
|
||||
#if defined(ENABLE_SERIAL_LOGGING)
|
||||
bool overflowRecovery = false;
|
||||
int nrOfMessages;
|
||||
struct LogQueueItem logQueueItem;
|
||||
va_list ap;
|
||||
|
||||
nrOfMessages = queue.size();
|
||||
|
||||
if((nrOfMessages == queuesize - 1) && !overflowRecovery)
|
||||
if((nrOfMessages >= queuesize - 1) && !overflowRecovery)
|
||||
{
|
||||
// Queue almost full, only one entry left. Log a warning instead
|
||||
composeLogQueueItem(&logQueueItem, __FILE__, __func__, __LINE__, LOGTYPE_WARNING, "Log queue overflow");
|
||||
@@ -82,8 +85,7 @@ FunctionStatus logger::log(const char* fileName, const char* functionName, int l
|
||||
else if((nrOfMessages == 0) && overflowRecovery)
|
||||
{
|
||||
// Queue empty again after an overflow
|
||||
char str[128];
|
||||
snprintf(str, sizeof(str) / sizeof(str[0]), "%d messages lost", (unsigned int)numberOfLostMessages);
|
||||
std::string str = std::to_string(numberOfLostMessages) + " messages were lost in the logger due to QUEUE overflow";
|
||||
composeLogQueueItem(&logQueueItem, __FILE__, __func__, __LINE__, LOGTYPE_WARNING, str);
|
||||
queue.push_back(logQueueItem);
|
||||
|
||||
@@ -130,46 +132,16 @@ void logger::composeTypeParameterList(void)
|
||||
|
||||
|
||||
#if defined(ENABLE_SERIAL_LOGGING)
|
||||
void logger::composeLogQueueItem(struct LogQueueItem* logQueueItem, std::string fileName, std::string functionName,
|
||||
int lineNumber, LogType logType, std::string context)
|
||||
void logger::composeLogQueueItem(struct LogQueueItem* logQueueItem, const std::string& fileName, const std::string& functionName,
|
||||
int lineNumber, LogType logType, const std::string& context)
|
||||
{
|
||||
|
||||
logQueueItem->logType = logType;
|
||||
logQueueItem->context = context;
|
||||
// strncpy((char*)&(logQueueItem->context[0]), context, contextSize);
|
||||
// logQueueItem->context[contextSize - 1] = '\0';
|
||||
|
||||
if(logType != LOGTYPE_PRINT)
|
||||
{
|
||||
int fileNameIndex = 0;
|
||||
|
||||
// If filename starts with "src/", strip this part
|
||||
if((fileName[0] == 's') &&
|
||||
(fileName[1] == 'r') &&
|
||||
(fileName[2] == 'c') &&
|
||||
(fileName[3] == '/'))
|
||||
{
|
||||
fileNameIndex = 4;
|
||||
}
|
||||
|
||||
// It is known that the strncpy use can potentially truncate the source string, meaning
|
||||
// that the target string size is smaller then the original string
|
||||
// This is not a problem in this particular case, so the compiler warning is disabled
|
||||
// for this situation
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
// All logtypes except LOGTYPE_PRINT need filename, functionname and linenumber.
|
||||
logQueueItem->fileName = fileName;
|
||||
logQueueItem->functionName = functionName;
|
||||
// strncpy((char*)&(logQueueItem->fileName[0]), &fileName[fileNameIndex], fileNameSize);
|
||||
// strncpy((char*)&(logQueueItem->functionName[0]), functionName, functionNameSize);
|
||||
#pragma GCC diagnostic pop
|
||||
logQueueItem->lineNumber = lineNumber;
|
||||
|
||||
// Fix terminating null byte in strncpy in case string to be copied is too long
|
||||
// logQueueItem->fileName[fileNameSize - 1] = '\0';
|
||||
// logQueueItem->functionName[functionNameSize - 1] = '\0';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -186,7 +158,7 @@ void logger::task()
|
||||
// Get the first log item from queue
|
||||
logQueueItem = queue.front();
|
||||
// Remove the item from the queue
|
||||
this->queue.pop_front();
|
||||
queue.pop_front();
|
||||
|
||||
|
||||
if(logQueueItem.logType == LOGTYPE_PRINT)
|
||||
@@ -194,7 +166,7 @@ void logger::task()
|
||||
// Raw print
|
||||
#if defined(ENABLE_SERIAL_LOGGING)
|
||||
|
||||
port.write(NO_DEVICE_ADDRESS, NO_REGISTER_ADDRESS, (uint8_t*)logQueueItem.context.c_str(), logQueueItem.context.length() + 1);
|
||||
port.write(NO_DEVICE_ADDRESS, NO_REGISTER_ADDRESS, (uint8_t*)logQueueItem.context.c_str(), logQueueItem.context.length());
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -208,7 +180,8 @@ void logger::task()
|
||||
// Find the correct Log level type
|
||||
auto it = std::find_if(typeParameterList.begin(), typeParameterList.end(), [&logQueueItem](const struct typeParameters& obj) {return obj.logType == logQueueItem.logType;});
|
||||
|
||||
std::string outputString = it->vt100Prefix + " "
|
||||
std::string outputString = "\n\r"
|
||||
+ it->vt100Prefix + " "
|
||||
+ it->vt100Prefix + " "
|
||||
+ std::to_string(seconds) + " "
|
||||
+ logQueueItem.fileName + " "
|
||||
|
||||
@@ -63,15 +63,13 @@ static const char* pass = "madagascar";
|
||||
// Function definitions
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int Wifi::s_retry_num = 0;
|
||||
const char* Wifi::TAG = "wifi station";
|
||||
EventGroupHandle_t Wifi::s_wifi_event_group = xEventGroupCreate();
|
||||
int Wifi::s_retry_num = 0;
|
||||
const char* Wifi::TAG;
|
||||
|
||||
Wifi::Wifi()
|
||||
{
|
||||
|
||||
|
||||
TAG = "wifi station";
|
||||
}
|
||||
|
||||
void Wifi::event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
Binary file not shown.
Reference in New Issue
Block a user