Commit e5af8581 authored by Dimitris Lampridis's avatar Dimitris Lampridis

[sw] add functions to detect MT IDs and rework config tool

parent 49057cee
Subproject commit b07df87ad36d963beb7d7596b3dffa4221d6bd58
Subproject commit add8319c68770cd2dac9c10842aad8487aeb1717
......@@ -20,17 +20,96 @@
* @{
*/
wrtd_status wrtd_get_node_count(uint32_t *count)
{
int i;
uint32_t dev_count = 0;
struct trtl_dev *trtl;
const struct trtl_config_rom *cfgrom;
char **dev_list = trtl_list();
if (!dev_list)
return WRTD_ERROR_INTERNAL;
for (i = 0; dev_list[i]; i++) {
trtl = trtl_open(dev_list[i]);
if (trtl == NULL) {
trtl_list_free(dev_list);
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
cfgrom = trtl_config_get(trtl);
/* WRTD = 0x57525444 */
if (cfgrom->app_id == 0x57525444)
dev_count++;
trtl_close(trtl);
}
trtl_list_free(dev_list);
*count = dev_count;
return WRTD_SUCCESS;
}
wrtd_status wrtd_get_node_id(uint32_t index, uint32_t *node_id)
{
int i;
uint32_t dev_count = 0;
struct trtl_dev *trtl;
const struct trtl_config_rom *cfgrom;
char **dev_list = trtl_list();
if (!dev_list)
return WRTD_ERROR_INTERNAL;
*node_id = 0;
for (i = 0; dev_list[i]; i++) {
trtl = trtl_open(dev_list[i]);
if (trtl == NULL) {
trtl_list_free(dev_list);
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
cfgrom = trtl_config_get(trtl);
/* WRTD = 0x57525444 */
if (cfgrom->app_id == 0x57525444)
dev_count++;
if (dev_count == index) {
char *eptr;
/* expecting string in the form of "trtl-xxxx, where
xxxx is a hex integer */
*node_id = strtoul(dev_list[i]+5, &eptr, 16);
if (*eptr != 0) {
trtl_list_free(dev_list);
trtl_close(trtl);
return WRTD_ERROR_INTERNAL;
}
}
trtl_close(trtl);
}
trtl_list_free(dev_list);
if (*node_id == 0)
return WRTD_ERROR_RESOURCE_UNKNOWN;
return WRTD_SUCCESS;
}
/**
* Initialize the WRTD Node and obtain the WRTD device token.
*
* @param[in] resource_name Underlying MockTurtle device ID in
* the form of **MTxxx** or **trtl-xxxx**.
* @param[in] node_id WRTD Node ID
* @param[in] reset Reserved for future use.
* @param[in] options_str Reserved for future use.
* @param[out] wrtd Pointer to WRTD device token.
* @return #wrtd_status
*/
wrtd_status wrtd_init(const char *resource_name,
wrtd_status wrtd_init(uint32_t node_id,
bool reset,
const char *options_str,
wrtd_dev **wrtd)
......@@ -41,35 +120,12 @@ wrtd_status wrtd_init(const char *resource_name,
struct wrtd_config_msg msg;
wrtd_status status;
static int initialized;
/* In case of error... */
*wrtd = NULL;
/* Initialize (only once).*/
if (!initialized) {
initialized = 1;
trtl_init();
}
trtl = trtl_open_by_id(node_id);
/* Resource is MTxxx where xxx is the mock-turtle device id. */
if (resource_name[0] == 'M' && resource_name[1] == 'T') {
unsigned long dev_id;
char *eptr;
dev_id = strtoul(resource_name + 2, &eptr, 0);
if (*eptr != 0) {
/* Invalid characters. */
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
trtl = trtl_open_by_id(dev_id);
}
else if (strncmp(resource_name, "trtl-", 5) == 0) {
trtl = trtl_open(resource_name);
}
else {
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
if (trtl == NULL)
if (trtl == NULL)
return WRTD_ERROR_RESOURCE_UNKNOWN;
wrtd_dev *res;
......
......@@ -242,7 +242,11 @@ typedef enum wrtd_attr {
/* Initialisation */
wrtd_status wrtd_init(const char *resource_name,
wrtd_status wrtd_get_node_count(uint32_t *count);
wrtd_status wrtd_get_node_id(uint32_t index, uint32_t *node_id);
wrtd_status wrtd_init(uint32_t node_id,
bool reset,
const char *options_str,
wrtd_dev **wrtd);
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment