added logger
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user