Unable to update project conf variable in program

51 Views Asked by At

I want to update value of a variable at run time, present in project configuration as per some condition. But currently I am getting this error: error: lvalue required as left operand of assignment

Actual code:

#include "contiki.h"
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/

PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);

static void update_project_conf_value(void)
{
    printf("Original Value: %d\n",TEST_VALUE);
    TEST_VALUE = 0;
    printf("After update: %d\n",TEST_VALUE);
}

/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
    PROCESS_BEGIN();
    update_project_conf_value();
    PROCESS_END();
}
/*---------------------------------------------------------------------------*/

Project configuration:


#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_

#define TEST_VALUE 1
/*---------------------------------------------------------------------------*/
#endif /* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/

Note: I want to update it in one of file as per some condition and then use the updated value in a different file.

1

There are 1 best solutions below

7
John On

First off, TEST_VALUE is a macro. You can read it but you can not write to it. It will also disappear at runtime.

What you really want is a global variable.

In the header put something like this:

#ifndef PROJECT_CONF_H_
#define PROJECT_CONF_H_

int g_TEST_VALUE; // Declaration

/*---------------------------------------------------------------------------*/
#endif /* PROJECT_CONF_H_ */
/*---------------------------------------------------------------------------*/

in your source put something like this:

#include "contiki.h"
#include <stdio.h> /* For printf() */
/*---------------------------------------------------------------------------*/

extern int g_TEST_VALUE = 1; // Definition

PROCESS(hello_world_process, "Hello world process");
AUTOSTART_PROCESSES(&hello_world_process);

static void update_project_conf_value(void)
{
    printf("Original Value: %d\n",TEST_VALUE);
    g_TEST_VALUE = 0;
    printf("After update: %d\n",TEST_VALUE);
}

/*---------------------------------------------------------------------------*/
PROCESS_THREAD(hello_world_process, ev, data)
{
    PROCESS_BEGIN();
    update_project_conf_value();
    PROCESS_END();
}
/*---------------------------------------------------------------------------*/