I'm having some problems with pointers in a school task, since I haven't programmed in C in a long time. I'm trying to store a value called rssi on a device running Contiki-NG which is like an OS for IOT devices.
I initialized the variable rssi in the beginning of the code:
static int8_t *rssi;
Then, in a function called on_reception, I'm updating the variable:
void on_reception(const void *data,
uint16_t len,
const linkaddr_t *src,
const linkaddr_t *dest)
{
....
// Update variable
rssi = &packetbuf_attr(PACKETBUF_ATTR_RSSI);
}
And then in the main loop I'm trying to store this value using a provided cfs_write function:
PROCESS_THREAD(receiver_process, ev, data)
{
PROCESS_BEGIN();
....
while(1) {
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&periodic_timer));
etimer_reset(&periodic_timer);
entry = akes_nbr_head();
if(entry && entry->permanent) {
akes_trickle_stop();
break;
}
// Store rssi value
r = cfs_write(fd, &rssi, sizeof(rssi));
}
}
However I'm getting problems like:
"lvalue required as unary '&' operand"
I've tried using '*' instead of '&' and what not but I can't seem to get it to work. Could anyone point me in the right direction?
EDIT: PACKETBUF_ATTR is a struct that contains a value according to the header file:
typedef uint16_t packetbuf_attr_t;
struct packetbuf_attr {
packetbuf_attr_t val;
};
They gave me an example of printing the values:
memcpy(&counter, data, sizeof(counter));
printf("B,PING,%lu,%u,%lu,%i,0\n",
clock_time(),
(uint8_t)packetbuf_attr(PACKETBUF_ATTR_CHANNEL),
counter,
(int8_t)packetbuf_attr(PACKETBUF_ATTR_RSSI));
static int8_t *rssi = calloc(1, sizeof(int8_t));packetbuf_attr? -- "I updated the answer." Do you mean the question?