Skip to content

Commit

Permalink
Expand SN to 8 digits
Browse files Browse the repository at this point in the history
Add padding for struct alignment
  • Loading branch information
linuxianer99 committed Mar 17, 2022
1 parent 8ed0397 commit f3d34d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
9 changes: 7 additions & 2 deletions 24c16.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

#define EEPROM_DATA_VERSION 1

#define SN_LENGTH 8

// define struct for MS5611 sensor
typedef struct {
int fd;
unsigned char address;
} t_24c16;

typedef struct __attribute__((packed)){
typedef struct {
char header[3];
char data_version;
char serial[6];
float zero_offset;
char serial[SN_LENGTH];
char padding[3];
char checksum;
} t_eeprom_data;



// prototypes
int eeprom_open(t_24c16 *, unsigned char);
char eeprom_write(t_24c16 *, char *, unsigned char, unsigned char);
Expand Down
13 changes: 7 additions & 6 deletions sensorcal.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int main (int argc, char **argv) {
int result;
int c;
int i;
char sn[7];
char sn[SN_LENGTH];
char zero[1]={0x00};


Expand Down Expand Up @@ -128,8 +128,9 @@ int main (int argc, char **argv) {
}
strcpy(data.header, "OV");
data.data_version = EEPROM_DATA_VERSION;
memset(data.serial,'0',6);
memset(data.serial,'0',SN_LENGTH);
data.zero_offset=0.0;
memset(data.padding,'0',3);
update_checksum(&data);
printf("Writing data to EEPROM ...\n");
result = eeprom_write(&eeprom, (char*)&data, 0x00, sizeof(data));
Expand Down Expand Up @@ -171,7 +172,7 @@ int main (int argc, char **argv) {
printf("Reading EEPROM values ...\n\n");
if( eeprom_read_data(&eeprom, &data) == 0)
{
memcpy(sn,data.serial,6);
memcpy(sn,data.serial,SN_LENGTH);
printf("Actual EEPROM values:\n");
printf("---------------------\n");
printf("Serial: \t\t\t%s\n", sn);
Expand All @@ -189,12 +190,12 @@ int main (int argc, char **argv) {
break;

case 's':
if( strlen(optarg) == 6)
if( strlen(optarg) == SN_LENGTH)
{
// read actual EEPROM values
if( eeprom_read_data(&eeprom, &data) == 0)
{
for(i=0; i<6;i++)
for(i=0; i<SN_LENGTH;i++)
{
sn[i]=data.serial[i]=*optarg;
optarg++;
Expand All @@ -214,7 +215,7 @@ int main (int argc, char **argv) {
}
else
{
printf("ERROR: Serialnumber has to have exactly 6 characters !!\n");
printf("ERROR: Serialnumber has to have exactly 8 characters !!\n");
exit_code=1;
break;
}
Expand Down

0 comments on commit f3d34d3

Please sign in to comment.