Пример #1
0
bool tlm_variable_get_value(const char *comp_name, const char *name, char *buffer, int len)
{
    const tlm_reg_var_type *reg_var = tlm_variable_get_by_comp_and_name(comp_name, name);
    bool success = false;

    if (NULL != reg_var) {
        success = tlm_variable_print_value(reg_var, buffer, len);
    }

    return success;
}
Пример #2
0
/**
 * Callback function for each component's variables
 */
static bool tlm_stream_for_each_component_var(void *elm_ptr, void *arg1, void *arg2, void *print_ascii)
{
    char buff[256];
    tlm_reg_var_type *var = elm_ptr;
    stream_callback_type stream = arg1;
    void *stream_arg = arg2;
    char *p = (char*)(var->data_ptr);
    uint32_t i = 0;

    if (NULL == stream || NULL == var) {
        return false;
    }

    stream((var->name), stream_arg);
    stream(":", stream_arg);
    sprintf(buff, "%" PRIi32 ":", var->elm_size_bytes);
    stream(buff, stream_arg);
    sprintf(buff, "%" PRIi32 ":", var->elm_arr_size);
    stream(buff, stream_arg);
    sprintf(buff, "%i:", var->elm_type);
    stream(buff, stream_arg);

    if (print_ascii)
    {
        tlm_variable_print_value(var, buff, sizeof(buff));
        stream(buff, stream_arg);
    }
    else
    {
        /* A variable has at least one data byte */
        sprintf(buff, "%02X", ((*p++) & 0xFF));
        stream(buff, stream_arg);

        /* Stream rest of the data bytes */
        for(i=(var->elm_size_bytes) * (var->elm_arr_size); /* Total bytes */
            i > 1; i--) { /* note: 1 byte already streamed above */
            sprintf(buff, ",%02X", ((*p++) & 0xFF) );
            stream(buff, stream_arg);
        }
    }

    stream("\n", stream_arg);

    return true;
}