Skip to content

Commit

Permalink
[build] Generate NI Style UsageReporting header (wpilibsuite#7331)
Browse files Browse the repository at this point in the history
based on wplibsuite/ni-libraries src/include/FRC_NetworkCommunication/UsageReporting.h
  • Loading branch information
sciencewhiz authored Nov 16, 2024
1 parent ded7c87 commit 0798ac5
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hal/generate_usage_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ def generate_usage_reporting(output_directory: Path, template_directory: Path):
)
usage_reporting_hdr.write_text(contents, encoding="utf-8", newline="\n")

with (template_directory / "UsageReporting.h.in").open(
encoding="utf-8"
) as cpp_usage_reporting:
contents = (
# fmt: off
cpp_usage_reporting.read()
.replace(r"${usage_reporting_types_cpp}", "\n".join(usage_reporting_types_cpp))
.replace(r"${usage_reporting_instances_cpp}", "\n".join(usage_reporting_instances_cpp))
# fmt: on
)

usage_reporting_hdr = (
output_directory / "main/native/include/hal/UsageReporting.h"
)
usage_reporting_hdr.write_text(contents, encoding="utf-8", newline="\n")


def main():
dirname = Path(__file__).parent
Expand Down
55 changes: 55 additions & 0 deletions hal/src/generate/UsageReporting.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

#ifndef __UsageReporting_h__
#define __UsageReporting_h__

#ifdef _WIN32
#include <stdint.h>
#define EXPORT_FUNC __declspec(dllexport) __cdecl
#elif defined(__vxworks)
#include <vxWorks.h>
#define EXPORT_FUNC
#else
#include <stdint.h>
#include <stdlib.h>
#define EXPORT_FUNC
#endif

#define kUsageReporting_version 1

namespace nUsageReporting
{
typedef enum
{
${usage_reporting_types_cpp}

// kResourceType_MaximumID = 255,
} tResourceType;

typedef enum
{
${usage_reporting_instances_cpp}
} tInstances;

/**
* Report the usage of a resource of interest.
*
* @param resource one of the values in the tResourceType above (max value 51).
* @param instanceNumber an index that identifies the resource instance.
* @param context an optional additional context number for some cases (such as module number). Set to 0 to omit.
* @param feature a string to be included describing features in use on a specific resource. Setting the same resource more than once allows you to change the feature string.
*/
uint32_t EXPORT_FUNC report(tResourceType resource, uint8_t instanceNumber, uint8_t context = 0, const char* feature = NULL);
} // namespace nUsageReporting

#ifdef __cplusplus
extern "C"
{
#endif

uint32_t EXPORT_FUNC FRC_NetworkCommunication_nUsageReporting_report(uint8_t resource, uint8_t instanceNumber, uint8_t context, const char* feature);

#ifdef __cplusplus
}
#endif

#endif // __UsageReporting_h__
223 changes: 223 additions & 0 deletions hal/src/generated/main/native/include/hal/UsageReporting.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0798ac5

Please sign in to comment.