/**
 * @brief  USBD_USR_SerialStrDescriptor
 *         return the serial number string descriptor
 * @param  speed : current device speed
 * @param  length : pointer to data length variable
 * @retval pointer to descriptor buffer
 */
uint8_t *  USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length)
{
    uint8_t deviceId[16];
    char deviceIdHex[sizeof(deviceId) * 2 + 1] = {0};
    unsigned deviceIdLen = 0;
    deviceIdLen = HAL_device_ID(deviceId, sizeof(deviceId));
    bytes2hexbuf(deviceId, deviceIdLen, deviceIdHex);
    USBD_GetString (deviceIdHex, USBD_StrDesc, length);
    return USBD_StrDesc;
}
bool system_info_to_json(appender_fn append, void* append_data, hal_system_info_t& system)
{
    AppendJson json(append, append_data);
    bool result = true;
    result &= json.write_value("p", system.platform_id)
        && json.write_key_values(system.key_value_count, system.key_values)
        && json.write_attribute("m")
        && json.write('[');
    char buf[65];
    for (unsigned i=0; i<system.module_count; i++) {
        if (i) result &= json.write(',');
        const hal_module_t& module = system.modules[i];
        const module_info_t* info = module.info;
        buf[64] = 0;
        bool output_uuid = module.suffix && module_function(info)==MODULE_FUNCTION_USER_PART;
        result &= json.write('{') && json.write_value("s", module.bounds.maximum_size) && json.write_string("l", module_store_string(module.bounds.store))
                && json.write_value("vc",module.validity_checked) && json.write_value("vv", module.validity_result)
          && (!output_uuid || json.write_string("u", bytes2hexbuf(module.suffix->sha, 32, buf)))
          && (!info || (json.write_string("f", module_function_string(module_function(info)))
                        && json.write_string("n", module_name(module_index(info), buf))
                        && json.write_value("v", info->module_version)))
        // on the photon we have just one dependency, this will need generalizing for other platforms
          && json.write_attribute("d") && json.write('[');

        for (unsigned int d=0; d<1 && info; d++) {
            const module_dependency_t& dependency = info->dependency;
            module_function_t function = module_function_t(dependency.module_function);
            if (function==MODULE_FUNCTION_NONE) // skip empty dependents
                continue;
            if (d) result &= json.write(',');
            result &= json.write('{')
              && json.write_string("f", module_function_string(function))
              && json.write_string("n", module_name(dependency.module_index, buf))
              && json.write_value("v", dependency.module_version)
               && json.end_list() && json.write('}');
        }
        result &= json.write("]}");
    }

    result &= json.write(']');
    return result;
}
Example #3
0
 static void get_device_id(char buffer[25]) {
     bytes2hexbuf((const uint8_t*)0x1FFF7A10, 12, buffer);
     buffer[24] = 0;
 }