Hi everybody,
it took me some time to know how to deal with strings and arrays
I have defined struct for onewire-temperature-sensors
typedef struct DS18B20_Label_t {
DeviceAddress Adress;
char Name[128];
char Acronym_AoC[17];
} DS18B20_Label_t;
and then an array of this structured type
DS18B20_Label_t DS18B20_Label[NoOfoneWireDevices];
As it is an array of struct assignind string-constants / byte-constants like at initialising seems not possible. Or if it is poosible I don't know yet.
DS18B20_Label.Name[0] = {"Sensor placed at ..."}
So I assign the stringconstants by using the strncpy-function
void initialiseDS18B20_Labels() {
int i = 0;
strncpy(DS18B20_Label[i].Name ,"Pufferspeicher unten",sizeof(DS18B20_Label[i].Name));
strncpy(DS18B20_Label[i].Acronym_AoC ,"PuffFB",sizeof(DS18B20_Label[i].Acronym_AoC));
Store8ByteAdress(DS18B20_Label[i].Adress, 0x28, 0xB2, 0xCB, 0x5A, 0x08, 0x00, 0x00, 0xC3);
i++;
strncpy(DS18B20_Label[i].Name ,"Pufferspeicher 20 cm ",sizeof(DS18B20_Label[i].Name));
strncpy(DS18B20_Label[i].Acronym_AoC ,"Puff1OG", sizeof(DS18B20_Label[i].Acronym_AoC));
Store8ByteAdress(DS18B20_Label[i].Adress, 0x28, 0xFC, 0xD1, 0x36, 0x06, 0x00, 0x00, 0x12);
similar thing with the sensor-adresses which are an 8 element array of byte
I wrote a little function to be able to assign it in one line of code
void Store8ByteAdress(uint8_t* deviceAddress, byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7) {
deviceAddress[0] = b0;
deviceAddress[1] = b1;
deviceAddress[2] = b2;
deviceAddress[3] = b3;
deviceAddress[4] = b4;
deviceAddress[5] = b5;
deviceAddress[6] = b6;
deviceAddress[7] = b7;
}
//call:
Store8ByteAdress(DS18B20_Label[i].Adress, 0x28, 0xB2, 0xCB, 0x5A, 0x08, 0x00, 0x00, 0xC3);
The strings and adresses are defined at compile-time.
Is there a even more compact way to assign the strings and the onewire-adresses?
best regards Stefan