Skip to content

Commit 00816e6

Browse files
committed
Fix console output, hostname & network utilities
Multiple fixes and cleanups across networking, console, and utility code: - Ensure snprintf uses full buffer size in json format helpers; adjust FormatUtcOffset logic. - Append newlines to many console::Error messages and replace a Puts call with Write for separator output. - Update copyright years in several headers/sources. - Change DmxNode layout (use reserved[2]). - Add/adjust includes (cstdint, cctype), IWYU pragmas, and header replacements. - Increase TCP TCB limit (16 -> 32) and network memory blocks (8 -> 12); add RFC1123 comment and switch HOST_NAME_PREFIX to use hyphen. - Improve hostname building and sanitization: use hex utility ToCharUppercase, filter non-printable chars, and add debug traces. - Refactor generate_content tool: rename file pointers/vars, use http/http.h, simplify directory iteration and content handling, and normalize output formatting. - Minor PHY timing define tweak and remove an unused khtmlinfos entry. These changes fix buffer/use issues, improve hostname generation, increase network capacity, and clean up build/tooling helpers.
1 parent ae7dbd6 commit 00816e6

18 files changed

Lines changed: 151 additions & 121 deletions

File tree

common/include/json/json_format_helpers.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,22 @@ constexpr size_t kOffsetBufferSize = 12; // For timezone offsets e.g. "+01:00"
3636

3737
[[nodiscard]] inline const char* FormatFloat(float value, char (&buf)[kFloatBufferSize], const char* fmt = "%.2f")
3838
{
39-
snprintf(buf, sizeof(buf) - 1, fmt, value);
39+
snprintf(buf, sizeof(buf), fmt, value);
4040
return buf;
4141
}
4242

4343
[[nodiscard]] inline const char* FormatUtcOffset(int32_t hours, uint32_t minutes, char (&buf)[kOffsetBufferSize])
4444
{
45-
if (hours == 0)
45+
if (hours <= 0)
4646
{
47-
snprintf(buf, sizeof(buf) - 1, "%.2d:%.2u", hours, minutes);
47+
snprintf(buf, sizeof(buf), "%.2d:%.2u", hours, minutes);
4848
}
4949
else
5050
{
51-
snprintf(buf, sizeof(buf) - 1, "%c%.2d:%.2u", hours < 0 ? '-' : '+', hours, minutes);
51+
snprintf(buf, sizeof(buf), "+%.2d:%.2u", hours, minutes);
5252
}
5353
return buf;
5454
}
55-
5655
} // namespace format
5756

5857
#endif // JSON_JSON_FORMAT_HELPERS_H_

lib-clib/src/malloc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ extern "C"
150150

151151
if (next > block_limit)
152152
{
153-
console::Error("malloc: out of memory");
153+
console::Error("malloc: out of memory\n");
154154
#ifdef DEBUG_HEAP
155155
debug_heap();
156156
#endif

lib-clib/src/perror.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file perror.cpp
33
*
44
*/
5-
/* Copyright (C) 2020-2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2020-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -31,6 +31,7 @@ namespace console
3131
void Error(const char*);
3232
int Putc(int);
3333
int Puts(const char*);
34+
void Write(const char*, unsigned int);
3435
} // namespace console
3536

3637
/*
@@ -107,7 +108,7 @@ extern "C"
107108
if (s && *s)
108109
{
109110
console::Error(s);
110-
console::Puts(": ");
111+
console::Write(": ", 2);
111112
}
112113

113114
console::Error(ptr);

lib-configstore/include/configurationstore.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ struct Flags
167167
struct DmxNode
168168
{
169169
uint32_t flags;
170-
uint8_t personality;
171-
uint8_t reserved;
170+
uint8_t reserved[2];
172171
uint16_t universe[dmxnode::kParamPorts];
173172
uint16_t direction;
174173
uint16_t merge_mode;

lib-hal/console/uart0/console.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* THE SOFTWARE.
2424
*/
2525

26+
#include <cstdint>
2627
#include <cstring>
2728

2829
#include "console.h"

lib-hal/include/gd32/hal.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file hal.h
33
*
44
*/
5-
/* Copyright (C) 2025 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2025-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -28,17 +28,13 @@
2828

2929
#include <cstdint>
3030

31-
#include "gd32.h"
31+
#include "gd32.h" // IWYU pragma: keep
3232

33-
#if defined(ENABLE_USB_HOST) && defined(CONFIG_USB_HOST_MSC)
33+
#if defined(ENABLE_USB_HOST)
3434
extern "C"
3535
{
3636
#include "usbh_core.h"
37-
#if defined(GD32H7XX) || defined(GD32F4XX)
38-
extern usbh_host usb_host_msc;
39-
#else
4037
extern usbh_host usb_host;
41-
#endif
4238
}
4339
#endif
4440

@@ -54,10 +50,10 @@ void emac_debug_run();
5450
#include "task.h"
5551
#endif
5652

57-
#include "softwaretimers.h"
53+
#include "softwaretimers.h" // IWYU pragma: keep
5854

5955
#if !defined(DISABLE_RTC)
60-
#include "hwclock.h"
56+
#include "hwclock.h" // IWYU pragma: keep
6157
#endif
6258

6359
#include "hal_panelled.h"
@@ -74,13 +70,9 @@ inline constexpr float kCoreTemperatureMax = +85.0;
7470

7571
inline void Run()
7672
{
77-
#if defined(ENABLE_USB_HOST) && defined(CONFIG_USB_HOST_MSC)
78-
#if defined(GD32H7XX) || defined(GD32F4XX)
79-
usbh_core_task(&usb_host_msc);
80-
#else
73+
#if defined(ENABLE_USB_HOST)
8174
usbh_core_task(&usb_host);
8275
#endif
83-
#endif
8476
#if !defined(USE_FREE_RTOS)
8577
SoftwareTimerRun();
8678
#endif

lib-hal/superloop/softwaretimers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ TimerHandle_t SoftwareTimerAdd(uint32_t interval_millis, const TimerCallbackFunc
7777
if (s_timers_count >= hal::kSoftwareTimersMax)
7878
{
7979
#ifndef NDEBUG
80-
console::Error("SoftwareTimerAdd: Max timer limit reached");
80+
console::Error("SoftwareTimerAdd: Max timer limit reached\n");
8181
#endif
8282
return -1;
8383
}
@@ -134,7 +134,7 @@ bool SoftwareTimerDelete(TimerHandle_t& id)
134134
}
135135

136136
#ifndef NDEBUG
137-
console::Error("SoftwareTimerDelete: Timer not found");
137+
console::Error("SoftwareTimerDelete: Timer not found\n");
138138
#endif
139139

140140
DEBUG_EXIT();
@@ -163,7 +163,7 @@ bool SoftwareTimerChange(TimerHandle_t id, uint32_t interval_millis)
163163
}
164164

165165
#ifndef NDEBUG
166-
console::Error("SoftwareTimerChange: Timer not found");
166+
console::Error("SoftwareTimerChange: Timer not found\n");
167167
#endif
168168

169169
return false;

lib-network/config/net_config.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file net_config.h
33
*
44
*/
5-
/* Copyright (C) 2021-2024 by Arjan van Vught mailto:info@gd32-dmx.org
5+
/* Copyright (C) 2021-2026 by Arjan van Vught mailto:info@gd32-dmx.org
66
*
77
* Permission is hereby granted, free of charge, to any person obtaining a copy
88
* of this software and associated documentation files (the "Software"), to deal
@@ -26,16 +26,20 @@
2626
#ifndef NET_CONFIG_H_
2727
#define NET_CONFIG_H_
2828

29+
// Valid hostnames (as per RFC 1123) must consist only of ASCII letters (a-z, A-Z), digits (0-9), and hyphens (-).
30+
// Labels must be 1-63 characters, with a maximum total length of 253 characters.
31+
// They cannot start or end with a hyphen, and should not be all-numeric.
32+
2933
#if defined(__linux__) || defined (__APPLE__)
3034
# define UDP_MAX_PORTS_ALLOWED 32
3135
# define IGMP_MAX_JOINS_ALLOWED (4 + (8 * 4)) /* 8 outputs x 4 Universes */
32-
# define TCP_MAX_TCBS_ALLOWED 16
36+
# define TCP_MAX_TCBS_ALLOWED 32
3337
# define TCP_MAX_PORTS_ALLOWED 2
3438
#else
3539
# define TCP_MAX_PORTS_ALLOWED 1
3640
# if defined (H3)
3741
# if !defined(HOST_NAME_PREFIX)
38-
# define HOST_NAME_PREFIX "allwinner_"
42+
# define HOST_NAME_PREFIX "allwinner-"
3943
# endif
4044
# define UDP_MAX_PORTS_ALLOWED 16
4145
# define IGMP_MAX_JOINS_ALLOWED (4 + (8 * 4)) /* 8 outputs x 4 Universes */
@@ -46,7 +50,7 @@
4650
*/
4751
# define CHECKSUM_BY_HARDWARE
4852
# if !defined(HOST_NAME_PREFIX)
49-
# define HOST_NAME_PREFIX "gigadevice_"
53+
# define HOST_NAME_PREFIX "gigadevice-"
5054
# endif
5155
# if !defined (UDP_MAX_PORTS_ALLOWED)
5256
# define UDP_MAX_PORTS_ALLOWED 8

lib-network/src/core/ipv4/dhcp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void Inform()
250250
#ifndef NDEBUG
251251
if (kHandle < 0)
252252
{
253-
console::Error("DHCP Inform");
253+
console::Error("DHCP Inform\n");
254254
return;
255255
}
256256
#endif
@@ -766,7 +766,7 @@ bool Start()
766766
#ifndef NDEBUG
767767
if (dhcp->handle < 0)
768768
{
769-
console::Error("DHCP Start");
769+
console::Error("DHCP Start\n");
770770
DEBUG_EXIT();
771771
return false;
772772
}

lib-network/src/core/ipv4/igmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void static Join(uint32_t group_address)
378378
}
379379

380380
#ifndef NDEBUG
381-
console::Error("igmp::Join");
381+
console::Error("igmp::Join\n");
382382
#endif
383383
DEBUG_ENTRY();
384384
}

0 commit comments

Comments
 (0)