added logger

This commit is contained in:
Dennis Gunia
2025-10-19 17:59:59 +02:00
parent dbb3f1c868
commit 9a5f18979a
10 changed files with 176 additions and 85 deletions

View File

@@ -8,11 +8,14 @@
*/
#include "sfbus-util.h"
#include "logging/logger.h"
int sfbusu_write_address(int fd, u_int16_t current, u_int16_t new)
{
log_message(LOG_INFO, "Writing new address 0x%04X to device with current address 0x%04X", new, current);
if (new < 1)
{
printf("Please specify new address > 0 with -d\n");
log_message(LOG_ERROR, "Cannot write address: Please specify new address > 0 with -d");
return -1;
}
// read current eeprom status
@@ -20,7 +23,7 @@ int sfbusu_write_address(int fd, u_int16_t current, u_int16_t new)
char *buffer_r = malloc(64);
if (sfbus_read_eeprom(fd, current, buffer_w) < 0)
{
fprintf(stderr, "Error reading eeprom\n");
log_message(LOG_ERROR, "Cannot write address: Error reading eeprom");
return 1;
}
// modify current addr
@@ -28,28 +31,28 @@ int sfbusu_write_address(int fd, u_int16_t current, u_int16_t new)
memcpy(buffer_w, &n_addr_16, 2);
if (sfbus_write_eeprom(fd, current, buffer_w, buffer_r) < 0)
{
fprintf(stderr, "Error writing eeprom\n");
log_message(LOG_ERROR, "Cannot write address: Error writing eeprom");
return 1;
}
return 0;
}
int sfbusu_write_calibration(int fd, u_int16_t address, u_int16_t data)
{
log_message(LOG_INFO, "Writing new calibration 0x%04X to device at address 0x%04X", data, address);
// read current eeprom status
char *buffer_w = malloc(64);
char *buffer_r = malloc(64);
if (sfbus_read_eeprom(fd, address, buffer_w) < 0)
{
fprintf(stderr, "Error reading eeprom\n");
log_message(LOG_ERROR, "Cannot write calibration: Error reading eeprom");
return 1;
}
// modify current calibration
memcpy(buffer_w + 2, &data, 2);
if (sfbus_write_eeprom(fd, address, buffer_w, buffer_r) < 0)
{
fprintf(stderr, "Error writing eeprom\n");
log_message(LOG_ERROR, "Cannot write address: Error writing eeprom");
return 1;
}