About the Mesh Config Entry  occupies too much ram

I‘m developing a light dimmer, I use Mesh Config Entry 

to save light state as 16 scene in persistent storage, because the size of each state is 1024 byte, so the live value dmx_scene occupies 16k ram, how can I reduce the memory usage?

nRF SDK FOR Mesh V5.0.0

nRF SDK 17.02

nRF52832

#include <stdint.h>
#include <stdlib.h>

#include "app_config.h"

#if (SCENE_ARRAY_SIZE>0) 

#include "dmx_mc.h"
#include "scene_server.h"
#include "access_config.h"
#include "mesh_config_entry.h"
#include "cc_define.h"
#include "log.h"


#define SCENE_ARRAY_SIZE 16

static uint16_t current_scene_number=0;

typedef struct{
  uint8_t dmx1[512];
  uint8_t dmx2[512]
}dmx_scene_t;

static dmx_scene_t  dmx_scene[SCENE_ARRAY_SIZE];

static dmx_scene_t store_entry_scene;


uint32_t dmx_mc_scene_store(const void *p_server , const scene_store_params_t *params,uint16_t transition_100ms,uint16_t model_id){

        
      dmx_status_t  *status=dmx_get_status();

      store_entry_scene.scene_number=params->scene_number;
      store_entry_scene.status=*status;
     
     //save
      mesh_config_entry_id_t id = APP_ENTRY_DMX_SCENE_ID;
      id.record += (uint16_t) params->position;
      uint32_t ret= mesh_config_entry_set(id, &store_entry_scene);

      return ret;
      
    
}

uint32_t dmx_mc_scene_recall(const void *p_server , const scene_recall_params_t *params){

 
    if(params->scene_number==0 ){     
      return NRF_ERROR_INVALID_PARAM;
    }
    

    
    for(uint8_t i=0;i<SCENE_ARRAY_SIZE;i++){
     
      dmx_scene_t *a_scene=&dmx_scene[i];
      if(a_scene->scene_number == params->scene_number){

        current_scene_number=params->scene_number;

        dmx_set_setting(&a_scene->setting,&a_scene->status,a_scene->transition_100ms);//
 
        return NRF_SUCCESS;
      }
      

    }
  
      
    return NRF_ERROR_NOT_FOUND;
}








//---------------- Config Entry ------------------------------------------------------------------------

static uint32_t dmx_entry_scene_setter(mesh_config_entry_id_t id, const void *p_entry)
{
  

    const dmx_scene_t * value = (const dmx_scene_t *) p_entry;
    dmx_scene[(uint8_t)(id.record-APP_ENTRY_DMX_SCENE_ID.record)]=*value;

    return NRF_SUCCESS;

}
static void dmx_entry_scene_getter(mesh_config_entry_id_t id, void *p_entry)
{

    dmx_scene_t *value=(dmx_scene_t *)p_entry;
    *value=dmx_scene[id.record-APP_ENTRY_DMX_SCENE_ID.record];
    
}



//---------- Config Stroe ---------------
MESH_CONFIG_ENTRY(dmx_scene_entry,
    APP_ENTRY_DMX_SCENE_ID,
    SCENE_ARRAY_SIZE,    
    sizeof(dmx_scene_t),
    dmx_entry_scene_setter,
    dmx_entry_scene_getter,    
    NULL);

 

#endif

Parents
  • Hi,

    The DMX is defined to have 512 channels of 8 byte in series corresponding to the light setting you want for your scene configuration. Each channel corresponds to 1 light and you will only transmit one channel per light you have in your network per frame, which means that you will only send information up to the amount of lights you have in your network. The DMX transmits synchronous with a long start bit, followed by the 1st to 512th bytes, and finished with a stop bit. Worst case this will be 512 bytes per channel.

    If you control the entire process yourself, you're free to program it as you see fit, however if you want to have 2 universes/configuration of lights of 512 devices per DMX  you will have 1024 bytes which will be around 16k of RAM if everything is being used in your controller. The same goes for a wireless connection - you will have to account for all of the channels resulting in the same memory requirements.

    It is also worth mention that this is an open ticket so users with experience with DMX , feel free to chime in. 

    Kind regards,
    Andreas

  • Hi Andreas

    Thank for your answer.

    Actually, my question is about the  mesh config entry, my light data is 1024 byte, it mean 1024 byte for each config entry,   When I use the mesh config entry, it must create a live value(dmx_scene) include 16 entry, the size is 16k, it  occupies too much ram,  my question is  can I just  create  the value for one entry and  can  store or load the required entry into the value? I mean I don’t need all the scene data in RAM, I just want load the one I need.

Reply
  • Hi Andreas

    Thank for your answer.

    Actually, my question is about the  mesh config entry, my light data is 1024 byte, it mean 1024 byte for each config entry,   When I use the mesh config entry, it must create a live value(dmx_scene) include 16 entry, the size is 16k, it  occupies too much ram,  my question is  can I just  create  the value for one entry and  can  store or load the required entry into the value? I mean I don’t need all the scene data in RAM, I just want load the one I need.

Children
Related