Skip to content

Commit 0798ac5

Browse files
authored
[build] Generate NI Style UsageReporting header (#7331)
based on wplibsuite/ni-libraries src/include/FRC_NetworkCommunication/UsageReporting.h
1 parent ded7c87 commit 0798ac5

File tree

3 files changed

+294
-0
lines changed

3 files changed

+294
-0
lines changed

hal/generate_usage_reporting.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ def generate_usage_reporting(output_directory: Path, template_directory: Path):
6767
)
6868
usage_reporting_hdr.write_text(contents, encoding="utf-8", newline="\n")
6969

70+
with (template_directory / "UsageReporting.h.in").open(
71+
encoding="utf-8"
72+
) as cpp_usage_reporting:
73+
contents = (
74+
# fmt: off
75+
cpp_usage_reporting.read()
76+
.replace(r"${usage_reporting_types_cpp}", "\n".join(usage_reporting_types_cpp))
77+
.replace(r"${usage_reporting_instances_cpp}", "\n".join(usage_reporting_instances_cpp))
78+
# fmt: on
79+
)
80+
81+
usage_reporting_hdr = (
82+
output_directory / "main/native/include/hal/UsageReporting.h"
83+
)
84+
usage_reporting_hdr.write_text(contents, encoding="utf-8", newline="\n")
85+
7086

7187
def main():
7288
dirname = Path(__file__).parent

hal/src/generate/UsageReporting.h.in

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
#ifndef __UsageReporting_h__
3+
#define __UsageReporting_h__
4+
5+
#ifdef _WIN32
6+
#include <stdint.h>
7+
#define EXPORT_FUNC __declspec(dllexport) __cdecl
8+
#elif defined(__vxworks)
9+
#include <vxWorks.h>
10+
#define EXPORT_FUNC
11+
#else
12+
#include <stdint.h>
13+
#include <stdlib.h>
14+
#define EXPORT_FUNC
15+
#endif
16+
17+
#define kUsageReporting_version 1
18+
19+
namespace nUsageReporting
20+
{
21+
typedef enum
22+
{
23+
${usage_reporting_types_cpp}
24+
25+
// kResourceType_MaximumID = 255,
26+
} tResourceType;
27+
28+
typedef enum
29+
{
30+
${usage_reporting_instances_cpp}
31+
} tInstances;
32+
33+
/**
34+
* Report the usage of a resource of interest.
35+
*
36+
* @param resource one of the values in the tResourceType above (max value 51).
37+
* @param instanceNumber an index that identifies the resource instance.
38+
* @param context an optional additional context number for some cases (such as module number). Set to 0 to omit.
39+
* @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.
40+
*/
41+
uint32_t EXPORT_FUNC report(tResourceType resource, uint8_t instanceNumber, uint8_t context = 0, const char* feature = NULL);
42+
} // namespace nUsageReporting
43+
44+
#ifdef __cplusplus
45+
extern "C"
46+
{
47+
#endif
48+
49+
uint32_t EXPORT_FUNC FRC_NetworkCommunication_nUsageReporting_report(uint8_t resource, uint8_t instanceNumber, uint8_t context, const char* feature);
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif // __UsageReporting_h__

hal/src/generated/main/native/include/hal/UsageReporting.h

Lines changed: 223 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)