CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to implement a device with AT command interface

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

how to implement a device with AT command interface
PostPosted: Fri Nov 21, 2008 4:35 pm     Reply with quote

Hello,
my intent is to develop a device which responds to sort of AT-commands via its serial line. I would like to set and get settings which will be stored in internal EEPROM with the help of those commands.

Example:
1) I want to set the attribute "speed" to the value of 10 by sending "speed 10\n" to the device.
2) I want to get the same attribute by sending (speed\n), the device should reply "speed=10\n"
3) all values will be stored in internal eeprom when "write\n" command has been issued.

Basically, I will do something like this:
Code:
#int_rda
void serreceive()
{
 char c;
 c=getc();
 if(c=='\n')ProcessBuffer();
 else
 {
  // fill the buffer and overflow protection....
 }

}

My question is what is the easiest way how to deal with the incoming buffer?
Is the only way using strcmp(parsed_buf,"speed")? I would take too many "if, else if" etc.

For saving entire "configuration" into the internal eeprom - is there any way how to make it "automatic". I mean to write/read those values in a "for" loop? Majority of them will be int8 and int16. Or would it ease it up by using structures?

Thank you for any help,
meereck
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 21, 2008 5:03 pm     Reply with quote

Quote:

My question is what is the easiest way how to deal with the incoming buffer?
Is the only way using strcmp(parsed_buf,"speed")? I would take too many "if, else if" etc.

Look at Ttelmah's method for detecting a match between incoming
commands and strings stored in a table:
http://www.ccsinfo.com/forum/viewtopic.php?t=31144
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sun Nov 23, 2008 4:24 am     Reply with quote

Hello, thank you. It looks straight-forward.
Any idea about saving plenty of variables into EEPROM memory? I was thinking about an array and variables in "union" . The array would be used for cyclic reading/writing into the EEPROM. Is it feasible this way? I dont know much about union type.

have a nice weekend,
M.
Ttelmah
Guest







PostPosted: Sun Nov 23, 2008 3:46 pm     Reply with quote

A union, allows two different variables to reside in the same RAM space.
You could (for instance), have a declaration like:
Code:

struct data_layout {
   int8 avalue[2];
   int16 a16bitvalue;
   float afloatvalue;
   int16 anothervalue;
   float asecondfloat;
   int16 afinal16bitvalue;
};

union {
   int8 b[16];
   int16 i[8]
   float vals[4];
   struct data_layout d;
} fred;

Then talk to the four floating point numbers 'fred.vals[0..3]', or to the bytes representing these numbers as 'fred.b[0..15]'. Also though, to the parts of the 'data_layout' structure, as: 'fred.d.afloatvalue' for example.
It is 'great' for sending numbers of one type across RS232 for example, and then re-assembling them into a different type (send fred.b[0...15], but access the floats locally for example).

However, for simply storing a data structure into/out of the EEPROM, an integer pointer is probably simpler.
So [for instance]:
Code:

void EEPROM_GET(int *ptr,int num,int addr) {
   int count;
   for (count=0;count<num;count++)
   {
      ptr[count]=READ_EEPROM(addr+count);
   }
}

void EEPROM_PUT(int *ptr,int num,int addr) {
   int count;
   for (count=0;count<num;count++)
   {
      WRITE_EEPROM(addr+count,ptr[count]);
   }
}

Then if you have a data structure containing your configuration information, called 'config', you can write this to the start of the EEPROM, using:

EEPROM_PUT(&config,sizeof(config),0);

and load it with the equivalent 'get'.
If you want to load a second structure, the same call, but with the last number (the EEPROM start address), set to the 'sizeof' the first stucture, handles this.
I don't really think a union 'helps' for this.

Best Wishes
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Sun Nov 23, 2008 5:06 pm     Reply with quote

If I could, I would issue Ttelmah.Karma=KARMA_MAX
Thanks a lot for the explanation. It is crystal clear now.
I will post my entire source code once it has been finished and debugged.
Meereck
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Dec 03, 2008 10:20 am     Reply with quote

Hello again, I tried that "union" stuff (Intending to send that VehicleBuffer array over RS-232 (I hope that "BinarySendVehicle" is ok)), but it does not work as you wrote:
Code:

struct _Vehicle{
unsigned int32 DateTime;
unsigned int16 LaneLength;
char Speed;
};
union Veh{
   int8 bytes[7];
   struct _Vehicle vehicle;
};

Veh VehicleBuffer[VEHICLE_BUFFER_LENGTH]; // i get error : expecting a (

void BinarySendVehicle(unsigned int16 index)
{
   char i;
   for(i=0;i<7;i++)fputc(VehicleBuffer[index].bytes[i],RS232);
}



EDIT: I was seaching the forum, and found some source codes with "typedef". The following gets compiled without any errors (though dont understand why typedef helps)
Code:
typedef union {
   int8 bytes[7];
   struct {
      unsigned int32 DateTime;
      unsigned int16 LaneLength; // lower 12 bits = length in cm, higher 4 bits=lane
      char Speed;
   } vehicle;
} Vehicle;

//Now declare the array
Vehicle VehicleBuffer[VEHICLE_BUFFER_LENGTH];
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group