Review at https://gerrit.osmocom.org/3268
lc15: cleanup board parameters reading
* move common code into separate function
* print error similar to parameter reading code
Change-Id: Icf3285d7bb921d212cb8945e835be2c81189fb87
Related: SYS#3679
---
M src/osmo-bts-litecell15/misc/lc15bts_bid.c
1 file changed, 25 insertions(+), 22 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/68/3268/1
diff --git a/src/osmo-bts-litecell15/misc/lc15bts_bid.c
b/src/osmo-bts-litecell15/misc/lc15bts_bid.c
index 06a126a..ba2037a 100644
--- a/src/osmo-bts-litecell15/misc/lc15bts_bid.c
+++ b/src/osmo-bts-litecell15/misc/lc15bts_bid.c
@@ -24,12 +24,13 @@
#include
#include
#include
+#include
#include "lc15bts_bid.h"
#define BOARD_REV_SYSFS"/var/lc15/platform/revision"
#define BOARD_OPT_SYSFS"/var/lc15/platform/option"
-
+
static const int option_type_mask[_NUM_OPTION_TYPES] = {
[LC15BTS_OPTION_OCXO] = 0x07,
[LC15BTS_OPTION_FPGA] = 0x03,
@@ -72,6 +73,21 @@
static int board_rev = -1;
static int board_option = -1;
+static inline bool read_board(const char *src, const char *spec, void *dst)
+{
+ FILE *fp = fopen(src, "r");
+if (!fp) {
+ fprintf(stderr, "Failed to open %s due to '%s' error\n", src,
strerror(errno));
+ return false;
+ }
+
+if (fscanf(fp, spec, dst) != 1) {
+fclose(fp);
+ fprintf(stderr, "Failed to read %s due to '%s' error\n", src,
strerror(errno));
+ return false;
+}
+fclose(fp);
+}
int lc15bts_rev_get(void)
{
@@ -82,14 +98,8 @@
return board_rev;
}
-fp = fopen(BOARD_REV_SYSFS, "r");
-if (fp == NULL) return -1;
-
-if (fscanf(fp, "%c", ) != 1) {
-fclose( fp );
-return -1;
-}
-fclose(fp);
+ if (!read_board(BOARD_REV_SYSFS, "%c", ))
+ return -1;
board_rev = rev;
return board_rev;
@@ -99,22 +109,15 @@
{
FILE *fp;
int opt;
+ bool rc;
+if (board_option != -1)
+ return board_option;
-if (board_option == -1) {
- fp = fopen(BOARD_OPT_SYSFS, "r");
- if (fp == NULL) {
- return -1;
- }
-
- if (fscanf(fp, "%X", ) != 1) {
- fclose( fp );
- return -1;
- }
- fclose(fp);
+ if (!read_board(BOARD_OPT_SYSFS, "%X", ))
+ return -1;
- board_option = opt;
- }
+ board_option = opt;
return board_option;
}
--
To view, visit https://gerrit.osmocom.org/3268
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icf3285d7bb921d212cb8945e835be2c81189fb87
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Max