2010-03-01 20:58:31 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
2010-03-25 03:37:04 +00:00
|
|
|
#include <stdio.h>
|
2010-03-01 20:58:31 +00:00
|
|
|
|
|
|
|
#include <osmocore/utils.h>
|
|
|
|
|
2010-03-25 03:37:04 +00:00
|
|
|
static char namebuf[255];
|
2010-03-01 20:58:31 +00:00
|
|
|
const char *get_value_string(const struct value_string *vs, uint32_t val)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0;; i++) {
|
|
|
|
if (vs[i].value == 0 && vs[i].str == NULL)
|
|
|
|
break;
|
|
|
|
if (vs[i].value == val)
|
|
|
|
return vs[i].str;
|
|
|
|
}
|
2010-03-25 03:37:04 +00:00
|
|
|
|
|
|
|
snprintf(namebuf, sizeof(namebuf), "unknown 0x%x", val);
|
|
|
|
return namebuf;
|
2010-03-01 20:58:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int get_string_value(const struct value_string *vs, const char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0;; i++) {
|
|
|
|
if (vs[i].value == 0 && vs[i].str == NULL)
|
|
|
|
break;
|
|
|
|
if (!strcasecmp(vs[i].str, str))
|
|
|
|
return vs[i].value;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-03-04 09:50:32 +00:00
|
|
|
|
|
|
|
char bcd2char(uint8_t bcd)
|
|
|
|
{
|
|
|
|
if (bcd < 0xa)
|
|
|
|
return '0' + bcd;
|
|
|
|
else
|
|
|
|
return 'A' + (bcd - 0xa);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only works for numbers in ascci */
|
|
|
|
uint8_t char2bcd(char c)
|
|
|
|
{
|
|
|
|
return c - 0x30;
|
|
|
|
}
|