Code Monkey home page Code Monkey logo

Comments (3)

michael-hillmann avatar michael-hillmann commented on July 24, 2024

Hi, thank you for your enhancement idea!
Can you explain to me more, what data you intend to store in the external database? I have the impression, you want to replace the object dictionary with an external database. This is really difficult, because the read and write activities triggers at some object entries actions (these are managed with the CO_TYPE functions).

The NVM drivers are responsible for saving the current value of a collection of object entries from the dynamic runtime area (RAM) into a persistent area (FLASH, EEPROM, or anything other). These values are used as start values after a restart of the node. If you consider an external database for this kind of persistent storage we could use the argument start in the NVM interface as a selector for the given collection of object entries:

Let's try to brainstorm this kind of use-case:

Assuming you have two parameter groups. One with data for the NMT heartbeat configuration and another for the ADC calibration values:

struct NMT_PARA_T {
  uint16_t Obj_1017_0_Heartbeat;
} NmtParaMem;

struct ADC_PARA_T {
  uint8_t Obj_2100_0_AdcFactor;
  uint8_t Obj_2100_1_AdcOffset;
} AdcParaMem;

Then we prepare the configuration for save, restore and reset behavior, factory settings, and the offset (typical placement in non-volatile memory - for us we could use this as the identifier of the collection queries.

const CO_PARA {
  0L,   /* query-id for this parameter group */
  sizeof(NmtParaMem),
  &NmtParaMem,
   :
} NmtParaObj;

const CO_PARA {
  1L,   /* query-id for this parameter group */
  sizeof(AdcParaMem),
  &AdcParaMem,
   :
} AdcParaObj;

Note: these parameter group configurations are placed in the object entries 1010h and 1011h.

Now, instead of placing the NvmParaMem and AdcParaMem with the NVM drivers somewhere in NVM memory, we could store the contained object entries in an external database. First, we need to manage the queries for each entry in the parameter groups:

/* structures to support the query management: */

typedef struct PARA_QUERY_T {   /* data for a single query */
  uint16_t Index;               /* all data we need to access database */
  uint8_t  Subindex;
  uint8_t  Size;
} PARA_QUERY;

typedef struct PG_QUERY_T {   /* structure for a collection of queries */
  PARA_QUERY *Query;          /* start of para query array */
  uint8_t Length;             /* number of para queries */
} PG_QUERY;

/* definition of queries (I would place them near the parameter group definitions): */

PARA_QUERY NmtQueries[1] = {
  { 0x1017, 0x00, 0x2 } /* heartbeat (word) */
};
PARA_QUERY AdcQueries[2] = {
  { 0x2100, 0x00, 0x1 }, /* adc factor (byte) */
  { 0x2100, 0x01, 0x1 }  /* adc offset (byte) */
};

PG_QUERY PgDb[2] = {
  { NmtQueries, 1 },
  { AdcQueries, 2 }
};

With the definitions in place, we can prepare the NVM driver for the external database (here only write as an idea):

uint32_t DrvNvmWrite (uint32_t start, uint8_t *buffer, uint32_t size)
{
  uint8_t  idx;
  uint8_t *value = buffer;
  uint8_t  bytes = 0;

  /* loop through addressed query collection and perform database action */
  for (idx = 0; idx < PgDb[start].Len; idx++) {
    pq = PgDb[start].Queries[idx];

    /* place your database query here, e.g.:  */
    ExtDatabaseQuery (pq->Index, pq->Subindex, value, pq->Length);

    /* navigate to next value in parameter memory */
    value += pq->Length;

    /* count all processed bytes */
    bytes += pq->Length;
  }
  return (bytes);
}

!! Note: this is only typed in this issue - never compiled nor tested. I never did this in a real project. It is just the try to investigate, how we can achieve your use-case !!

from canopen-stack.

amorniroli avatar amorniroli commented on July 24, 2024

Hi @michael-hillmann,

I have the impression, you want to replace the object dictionary with an external database

Exactly!

First of all, thanks for your answer: I've just started to use the stack, so I'm still in "learning" phase. I will answer to your in detail next week!

from canopen-stack.

michael-hillmann avatar michael-hillmann commented on July 24, 2024

Closed due to inactivity, the question is answered.

from canopen-stack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.