Skip to content
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
8 changes: 4 additions & 4 deletions src/DeviceInfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
#define LWM2M_MAX_ID (65535)

typedef enum {
MandatoryEnum_OPTIONAL = 0,
MandatoryEnum_MANDATORY = 1,
MandatoryEnum_OPTIONAL,
MandatoryEnum_MANDATORY,
} MandatoryEnum;

typedef enum {
Expand All @@ -58,7 +58,7 @@ static void RebootExecuteCallback(const AwaExecuteArguments* arguments, void * c
exit(0);
}

static void FactoryRestetExecuteCallback(const AwaExecuteArguments* arguments, void * context) {
static void FactoryResetExecuteCallback(const AwaExecuteArguments* arguments, void * context) {
const char* userData = (const char*) context;
LOG(LOG_WARN, "Request for Factory Reset from context: %s", userData);
LOG(LOG_ERR, "At this moment it just do this same as reset, add implementation you need here!");
Expand Down Expand Up @@ -167,7 +167,7 @@ static void SubscribeToChanges(AwaClientSession* session) {
AwaClientExecuteSubscription* subscription = AwaClientExecuteSubscription_New(REBOOT, RebootExecuteCallback, NULL);
AwaClientSubscribeOperation_AddExecuteSubscription(subscribeOperation, subscription);

subscription = AwaClientExecuteSubscription_New(FACTORY_RESET, FactoryRestetExecuteCallback, NULL);
subscription = AwaClientExecuteSubscription_New(FACTORY_RESET, FactoryResetExecuteCallback, NULL);
AwaClientSubscribeOperation_AddExecuteSubscription(subscribeOperation, subscription);

//Changes callback
Expand Down
2 changes: 1 addition & 1 deletion src/DeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#define OBJECT_INSTANCE(obj, inst) "/" obj "/" #inst

typedef enum{
INSTANCE_0 = 0,
INSTANCE_0,
INSTANCE_1,
INSTANCE_2,
INSTANCE_3,
Expand Down
16 changes: 11 additions & 5 deletions src/InfoDaemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
#include "Log.h"
#include "DeviceInfo.h"

FILE* g_debugStream = NULL;
FILE* g_debugStream;
int g_debugLevel = LOG_INFO;
sem_t g_debugSemapthore;
bool g_running;
static volatile bool g_running = true;

static void ExitApp(int ignore) {
printf("Exiting...\n");
Expand Down Expand Up @@ -84,7 +84,7 @@ static void GetSerialNumber(char* buffer, int bufferSize) {
pclose(fp);
}

static void LoadDeviceData() {
static void LoadDeviceData(void) {

struct utsname unameData;
uname(&unameData);
Expand All @@ -98,9 +98,15 @@ static void LoadDeviceData() {
}

int main(int argc, char **argv) {
struct sigaction action = {
.sa_handler = ExitApp,
.sa_flags = 0
};
g_debugStream = stdout;
sem_init(&g_debugSemapthore, 0, 1);
signal(SIGINT, ExitApp);
g_running = true;

sigemptyset(&action.sa_mask);
sigaction (SIGINT, &action, NULL);

AwaClientSession * session = AwaClientSession_New();
AwaClientSession_Connect(session);
Expand Down
47 changes: 23 additions & 24 deletions src/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,31 @@

/** Macro for printing logging message with current time, function and line no. DOn't use directly*/
#define DEBUG_PRINT \
do { \
time_t currentTime = time(NULL); \
char buffer[TIME_BUFFER_SIZE] = {0}; \
strftime(buffer, TIME_BUFFER_SIZE, "%x %X", localtime(&currentTime)); \
fprintf(g_debugStream,"[%s] %s:%d: ", buffer, __FILENAME__, __LINE__); \
} while (0)
do { \
time_t currentTime = time(NULL); \
char buffer[TIME_BUFFER_SIZE] = {0}; \
strftime(buffer, TIME_BUFFER_SIZE, "%x %X", localtime(&currentTime)); \
fprintf(g_debugStream,"[%s] %s:%d: ", buffer, __FILENAME__, __LINE__); \
} while (0)

/** Macro for logging message at the specified level. */
#define LOG(level, ...) \
do { \
if (level <= g_debugLevel) \
{ \
sem_wait(&g_debugSemapthore); \
if (g_debugStream == NULL) \
g_debugStream = stdout; \
fprintf(g_debugStream, "\n"); \
if (g_debugLevel == LOG_DBG) \
{ \
DEBUG_PRINT; \
} \
fprintf(g_debugStream, __VA_ARGS__); \
fprintf(g_debugStream, "\n"); \
fflush(g_debugStream); \
sem_post(&g_debugSemapthore); \
} \
} while (0)
do { \
if (level <= g_debugLevel) \
{ \
if (g_debugStream == NULL) \
break; \
sem_wait(&g_debugSemapthore); \
g_debugStream = stdout; \
fprintf(g_debugStream, "\n"); \
if (g_debugLevel == LOG_DBG) \
DEBUG_PRINT; \
fprintf(g_debugStream, __VA_ARGS__); \
fprintf(g_debugStream, "\n"); \
fflush(g_debugStream); \
sem_post(&g_debugSemapthore); \
} \
} while (0)

/** Output stream to dump logs. */
extern FILE *g_debugStream;
Expand All @@ -88,4 +87,4 @@ extern int g_debugLevel;

extern sem_t g_debugSemapthore;

#endif /* LOG_H */
#endif /* LOG_H */