Traverse struct with pointer
hi all,
if have struct following...
can set pointer struct can take serial input , put each input byte struct in 1 shot out having refer each of struct's members individually.
i can't seem work.
below doing, seems kinda clunky.
thanks in advance
jeff
if have struct following...
code: [select]
struct config_t
{
byte mac[6];
byte ip[4];
byte subnet[4];
byte gateway[4];
byte server[4];
char path[128];
};
can set pointer struct can take serial input , put each input byte struct in 1 shot out having refer each of struct's members individually.
i can't seem work.
below doing, seems kinda clunky.
code: [select]
void checkserial(){
if (serial.available() > 0){
switch (serial.read()){
case 'w':
{
delay(1000);
int i=0;
while ((serial.available()>0) && i<6) configuration.mac[i++] = serial.read();
serial.println(i);
i=0;
while ((serial.available()>0) && i<4) configuration.ip[i++] = serial.read();
serial.println(i);
i=0;
while ((serial.available()>0) && i<4) configuration.subnet[i++] = serial.read();
serial.println(i);
i=0;
while ((serial.available()>0) && i<4) configuration.gateway[i++] = serial.read();
serial.println(i);
i=0;
while ((serial.available()>0) && i<4) configuration.server[i++] = serial.read();
serial.println(i);
i=0;
while(serial.available() > 0) configuration.path[i++] = serial.read();
configuration.path[i++] = '\0';
serial.println(i);
printconfig();
}
eeprom_writeanything(0, configuration);
//printconfig();
break;
case 'r':
eeprom_readanything(0, configuration);
printconfig();
break;
default:
serial.flush();
}
}
}
thanks in advance
jeff
a union should work. union allows refer section
of memory in multiple ways. if create union between
struct , array of bytes can access memory bytes
or struct fields.
this handy real-time clock library wrote. for
transmitting bytes easier use array. setting values
using field names sec, min. hour easier.
there simpler examples @ rtc library , example code @ http://tinyurl.com/y8exe7k
(* jcl *)
------------------------------------
www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org
of memory in multiple ways. if create union between
struct , array of bytes can access memory bytes
or struct fields.
this handy real-time clock library wrote. for
transmitting bytes easier use array. setting values
using field names sec, min. hour easier.
there simpler examples @ rtc library , example code @ http://tinyurl.com/y8exe7k
(* jcl *)
------------------------------------
www: http://www.wiblocks.com
twitter: http://twitter.com/wiblocks
blog: http://luciani.org
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Traverse struct with pointer
arduino
Comments
Post a Comment