Commit 53d45730 authored by Raptor Engineering Development Team's avatar Raptor Engineering Development Team
Browse files

Add initial Redfish JSON framework

Only responds to API version request
parent 65f5a51d
......@@ -33,6 +33,7 @@ target_sources(app PRIVATE
${KESTREL_SOURCE_DIR}/src/flash_filesystem.c
${KESTREL_SOURCE_DIR}/src/fsi.c
${KESTREL_SOURCE_DIR}/src/kestrel.c
${KESTREL_SOURCE_DIR}/src/redfish.c
${KESTREL_SOURCE_DIR}/src/simple_pwm.c
${KESTREL_SOURCE_DIR}/src/webservice.c
${KESTREL_SOURCE_DIR}/src/webportal.c
......
/*
* Copyright (c) 2021 Raptor Engineering, LLC <sales@raptorengineering.com>
*
* SPDX-License-Identifier: GPL-3.0
*/
#include <logging/log.h>
LOG_MODULE_REGISTER(redfish, LOG_LEVEL_DBG);
#include <zephyr.h>
#include <posix/pthread.h>
#include <data/json.h>
#include "simple_pwm.h"
#include "webportal.h"
#include "redfish.h"
#include "raptor_extensions.h"
#define WITH_ZEPHYR 1
#include "kestrel.h"
#include <generated/mem.h>
#define STANDARD_HEADER(title) \
"<head>" \
"<title>" title "</title>" \
"</head>"
#define SEND_STANDARD_TITLE_HEADER(conn, title) \
civetweb_send_file_data(conn, STANDARD_HEADER(title), sizeof(STANDARD_HEADER(title)));
#define SEND_STANDARD_HEADER(conn, title) \
#define SEND_STANDARD_FOOTER(conn)
const char* redfish_base_path = "/redfish/v1/";
struct json_redfish_version {
const char *v1;
};
static const struct json_obj_descr json_redfish_version_desc[] = {
JSON_OBJ_DESCR_PRIM(struct json_redfish_version, v1, JSON_TOK_STRING),
};
int redfish_version_handler(struct mg_connection *conn, void *cbdata)
{
struct json_redfish_version redfish_version;
uint8_t json_string_buffer[1024];
int ret;
redfish_version.v1 = redfish_base_path;
ret = json_obj_encode_buf(json_redfish_version_desc,
ARRAY_SIZE(json_redfish_version_desc), &redfish_version,
json_string_buffer,
sizeof(json_string_buffer)-1);
if (ret) {
return -1;
}
send_ok(conn);
SEND_STANDARD_HEADER(conn, "Redfish API")
mg_printf(conn, "%s", json_string_buffer);
SEND_STANDARD_FOOTER(conn);
return 200;
}
\ No newline at end of file
// © 2021 Raptor Engineering, LLC
//
// Released under the terms of the GPL v3
// See the LICENSE file for full details
#ifndef _REDFISH_H
#define _REDFISH_H
int redfish_version_handler(struct mg_connection *conn, void *cbdata);
#endif // _REDFISH_H
\ No newline at end of file
......@@ -11,10 +11,11 @@ LOG_MODULE_REGISTER(webportal, LOG_LEVEL_DBG);
#include <posix/pthread.h>
#include <data/json.h>
#include "civetweb.h"
#include "simple_pwm.h"
#include "webportal.h"
#include "redfish.h"
#include "raptor_extensions.h"
#include "static_files.h"
......@@ -407,5 +408,8 @@ void *web_portal_pthread(void *arg)
mg_set_request_handler(ctx, "/firmware$", firmware_upload_form_handler, (void *)"/firmware.upload");
mg_set_request_handler(ctx, "/firmware.upload$", firmware_upload_handler, (void *)0);
// Redfish
mg_set_request_handler(ctx, "/redfish$", redfish_version_handler, (void *)0);
return 0;
}
......@@ -6,6 +6,9 @@
#ifndef _WEBPORTAL_H
#define _WEBPORTAL_H
#include "civetweb.h"
void *web_portal_pthread(void *arg);
void send_ok(struct mg_connection *conn);
#endif // _WEBPORTAL_H
\ No newline at end of file
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