首页 > 解决方案 > Accessing enum value in memcpy

问题描述

I am trying to copy the value of enum to some array through memcpy. Before this i will be doing a state change of enum from 0 to 1. Then i am copying this enum value to my array. I observed that there is state change but the value is not copied into array. Initial enum value is 0 i.e., INIT_STATE, then i change the value to DISASSOCIATE_STATE.

My array is data[9], where 0-7 bytes is the device_id and 8 is the tag_state. State is when BLE communication happens between tag and mobile app, i give 1 in the custom characteristics from nRF connect app, the state should change to DISASSOCIATE. This is happening that i can check in switch case.

So, When that changes, i should update the state in array. For that i'm using memcpy.

memcpy should update the tag state i.e., 8th byte of data[9].

My enum is

typedef enum {
    INIT_STATE,
    DISASSOCIATE_STATE,
    ASSOCIATE_STATE,
    SET_CONFIG_STATE
}cmd_type;

This is defined in one file. I am accessing it using cmd_type state; This is the memcpy command I'm using,

memcpy(data[8],state+1, 1);

Why the value is not getting copied?

标签: c

解决方案


推荐阅读