Solved

How to creat good software interface ?

Posted on 2016-08-08
1
70 Views
Last Modified: 2016-08-08
/*  Our embedded target board is based on Renesas RH850F1L Microcontroller.  Our language is 'C'. */
/* A software library creates a instance of this structure and provides me a pointer to this structure.   What is a good application interface that can be used to provide d0.Fact and d1.Fact to application periodically? */
typedef struct {
               unsigned short  count;
               unsigned short  hold;
               unsigned char    Fact;
} LtRXData;

typedef struct {
   unsigned short  speed;
   LtRXData  d0;
   LtRXData  d1;
} LtRData;

Open in new window



/* A software library creates instance of this structure and provides me pointer to the structure.  What is a good application interface that can be used to provide d0_s1.Fact, d0_s2.Fact, d0_s3.Fact, d1_s1.Fact, d1_s2.Fact, and d1_s3.Fact to application periodically? */
typed struct {
   unsigned short  count;
   unsigned short  hold;
   unsigned char   Fact;
} LtSXData;

typedef struct {
   unsigned short speed;
   LtSXData  d0_s1;
   LtSXData  d0_s2;
   LtSXData  d0_s3;
   LtSXData  d1_s1;
   LtSXData  d1_s2;
   LtSXData  d1_s3;
} LtSData;

Open in new window

0
Comment
Question by:naseeam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 41747705
library creates instance of this structure and provides me pointer to the structure

assume there is no foreign library but you have some fixed initial "records" of LtRData (same applies for LtSData).

then you could do:

#define MAX_LTR 100
#define LTR_INIT 3


LtRData rdata[MAX_LTR] = 
{
     {     10, { 0, 0, 'F' }, { 1, 2, 'P' }, }, 
     {   100, { 7, 8, 'A' }, { 2, 1, 'N' }, }, 
     {  1000, { 99, 0, 'A' }, { 1, 1, 'L' }, }, 
};
static int maxidx = LTR_INIT;

Open in new window


you see the 'table' of records initially is sorted by speed,

you easily can write a function to get d0.Fact of a given "row" of the table.

char LTR_GetD0FactByIndex(int idx)
{
      if (idx < 0 || idx >= maxidx) return ' ';

      return rdata[idx].d0.Fact;
}

Open in new window



you also can search for a given speed.

char LTR_GetD0FactBySpeed(int speed)
{
      int i;

      for (i = 0; i < maxidx; ++i) 
            if (speed == rdata[i].speed)
                 return rdata[i].d0.Fact;
      return ' ';
}

Open in new window



if you get new LTR records you may add them to the table:

int RDataCompare(void * pLeft, void * pRight)
{
      if (((LtRData *)pLeft)->speed < ((LtRData *)pRight)->speed)
          return -1;
      else if  (((LtRData *)pLeft)->speed > ((LtRData *)pRight)->speed)
          return 1;
      return 0;
}

int LTR_AddRecord(LtRData * pLtR)
{
       if (pLtR == NULL || maxidx == MAX_LTR) return -1;
       
       rdata[maxidx++] = *pLtR;
       qsort(rdata, maxidx, sizeof(LtRData), RDataCompare);

       return 0;
};

Open in new window


Sara
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question