[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to creat good software interface ?

Posted on 2016-08-08
1
Medium Priority
?
115 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 35

Accepted Solution

by:
sarabande earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

650 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