2023-03-13 18:54:57 +08:00
|
|
|
#include "common/printing.h"
|
2023-06-10 15:01:54 +08:00
|
|
|
#include "common/jsonconfig.h"
|
2023-03-13 18:54:57 +08:00
|
|
|
#include "detection/board/board.h"
|
|
|
|
|
#include "modules/board/board.h"
|
2023-06-19 15:21:49 +08:00
|
|
|
#include "util/stringUtils.h"
|
2023-03-13 18:54:57 +08:00
|
|
|
|
|
|
|
|
#define FF_BOARD_NUM_FORMAT_ARGS 3
|
|
|
|
|
|
|
|
|
|
void ffPrintBoard(FFinstance* instance, FFBoardOptions* options)
|
|
|
|
|
{
|
|
|
|
|
FFBoardResult result;
|
|
|
|
|
ffDetectBoard(&result);
|
|
|
|
|
|
|
|
|
|
if(result.error.length > 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &options->moduleArgs, "%*s", result.error.length, result.error.chars);
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(result.boardName.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &options->moduleArgs, "board_name is not set.");
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(options->moduleArgs.outputFormat.length == 0)
|
|
|
|
|
{
|
2023-06-18 12:32:47 +08:00
|
|
|
ffPrintLogoAndKey(instance, FF_BOARD_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
|
2023-06-19 21:17:07 +08:00
|
|
|
ffStrbufWriteTo(&result.boardName, stdout);
|
|
|
|
|
if (result.boardVersion.length)
|
|
|
|
|
printf(" (%s)", result.boardVersion.chars);
|
|
|
|
|
putchar('\n');
|
2023-03-13 18:54:57 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffPrintFormat(instance, FF_BOARD_MODULE_NAME, 0, &options->moduleArgs, FF_BOARD_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.boardName},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.boardVendor},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.boardVersion},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
ffStrbufDestroy(&result.boardName);
|
|
|
|
|
ffStrbufDestroy(&result.boardVendor);
|
|
|
|
|
ffStrbufDestroy(&result.boardVersion);
|
|
|
|
|
ffStrbufDestroy(&result.error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffInitBoardOptions(FFBoardOptions* options)
|
|
|
|
|
{
|
|
|
|
|
options->moduleName = FF_BOARD_MODULE_NAME;
|
|
|
|
|
ffOptionInitModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const char* value)
|
|
|
|
|
{
|
|
|
|
|
const char* subKey = ffOptionTestPrefix(key, FF_BOARD_MODULE_NAME);
|
|
|
|
|
if (!subKey) return false;
|
|
|
|
|
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffDestroyBoardOptions(FFBoardOptions* options)
|
|
|
|
|
{
|
|
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-10 15:01:54 +08:00
|
|
|
void ffParseBoardJsonObject(FFinstance* instance, yyjson_val* module)
|
2023-03-13 18:54:57 +08:00
|
|
|
{
|
|
|
|
|
FFBoardOptions __attribute__((__cleanup__(ffDestroyBoardOptions))) options;
|
|
|
|
|
ffInitBoardOptions(&options);
|
|
|
|
|
|
2023-03-15 15:24:40 +08:00
|
|
|
if (module)
|
2023-03-13 18:54:57 +08:00
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
yyjson_val *key_, *val;
|
|
|
|
|
size_t idx, max;
|
|
|
|
|
yyjson_obj_foreach(module, idx, max, key_, val)
|
2023-03-15 15:24:40 +08:00
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
const char* key = yyjson_get_str(key_);
|
2023-06-19 15:21:49 +08:00
|
|
|
if(ffStrEqualsIgnCase(key, "type"))
|
2023-06-10 15:01:54 +08:00
|
|
|
continue;
|
|
|
|
|
|
2023-03-15 15:24:40 +08:00
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
|
|
|
|
continue;
|
2023-03-15 11:24:49 +08:00
|
|
|
|
2023-03-15 15:24:40 +08:00
|
|
|
ffPrintError(instance, FF_BOARD_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
|
|
|
|
}
|
2023-03-13 18:54:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffPrintBoard(instance, &options);
|
|
|
|
|
}
|