Skip to content

Commit c87f41a

Browse files
committed
Minor code cleanup
1 parent b9118f2 commit c87f41a

File tree

19 files changed

+413
-303
lines changed

19 files changed

+413
-303
lines changed

lib-artnet/src/controller/artnetpolltable.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Art-Net Designed by and Copyright Artistic Licence Holdings Ltd.
77
*/
8-
/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@orangepi-dmx.nl
8+
/* Copyright (C) 2017-2024 by Arjan van Vught mailto:info@gd32-dmx.org
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -72,8 +72,8 @@ ArtNetPollTable::ArtNetPollTable() {
7272
m_PollTableClean.nUniverseIndex = 0;
7373
m_PollTableClean.bOffLine = true;
7474

75-
DEBUG_PRINTF("NodeEntry[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_ENRIES, (sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])), (sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])) / 1024U);
76-
DEBUG_PRINTF("PollTableUniverses[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_UNIVERSES, (sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])), (sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])) / 1024U);
75+
DEBUG_PRINTF("NodeEntry[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_ENRIES, static_cast<unsigned int>(sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])), static_cast<unsigned int>(sizeof(artnet::NodeEntry[artnet::POLL_TABLE_SIZE_ENRIES])) / 1024U);
76+
DEBUG_PRINTF("PollTableUniverses[%d] = %u bytes [%u Kb]", artnet::POLL_TABLE_SIZE_UNIVERSES, static_cast<unsigned int>(sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])), static_cast<unsigned int>(sizeof(artnet::PollTableUniverses[artnet::POLL_TABLE_SIZE_UNIVERSES])) / 1024U);
7777
DEBUG_EXIT
7878
}
7979

lib-configstore/.cproject

+158-30
Large diffs are not rendered by default.

lib-configstore/.settings/language.settings.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<project>
3-
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.1474025154" name="H3">
3+
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.309283989.303033930.1702909156.1968016134.2033060944.291204756" name="H3">
44
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
7-
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
8-
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-869088479795149684" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
7+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
8+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="738023790827142799" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>

lib-configstore/include/envparams.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define ENVPARAMS_H_
2828

2929
#include <cstdint>
30+
#include <cassert>
3031

3132
class EnvParams {
3233
public:
@@ -38,7 +39,11 @@ class EnvParams {
3839
void Builder(char *pBuffer, uint32_t nLength, uint32_t& nSize);
3940

4041
public:
41-
static void staticCallbackFunction(void *p, const char *s);
42+
static void staticCallbackFunction(void *p, const char *s) {
43+
assert(p != nullptr);
44+
assert(s != nullptr);
45+
(static_cast<EnvParams *>(p))->callbackFunction(s);
46+
}
4247

4348
private:
4449
void Dump();

lib-configstore/src/envparams.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ void EnvParams::callbackFunction(const char *pLine) {
9696
}
9797
}
9898

99-
void EnvParams::staticCallbackFunction(void *p, const char *s) {
100-
assert(p != nullptr);
101-
assert(s != nullptr);
102-
103-
(static_cast<EnvParams *>(p))->callbackFunction(s);
104-
}
105-
10699
void EnvParams::Builder(char *pBuffer, uint32_t nLength, uint32_t& nSize) {
107100
DEBUG_ENTRY
108101

lib-e131/include/e131bridge.h

-3
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ class E131Bridge {
350350
#endif
351351
}
352352
}
353-
#endif
354-
#if defined (DMXCONFIGUDP_H)
355-
m_DmxConfigUdp.Run();
356353
#endif
357354
}
358355

lib-flash/.settings/language.settings.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
77
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
8-
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-869088479795149684" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
8+
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-869023348763085684" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>

lib-flash/src/spi/gd32/spi_flash.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int spi_init() {
5555
return 0;
5656
}
5757

58-
inline static void spi_transfern(char *pBuffer, uint32_t nLength) {
58+
inline static void spi_transfern(char *pBuffer, const uint32_t nLength) {
5959
gd32_spi_transfernb(pBuffer, pBuffer, nLength);
6060
}
6161

lib-osc/Rules.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
$(info [${CURDIR}])
22
$(info $$MAKE_FLAGS [${MAKE_FLAGS}])
33

4-
EXTRA_INCLUDES+=../lib-display/include ../lib-properties/include ../lib-network/include
4+
EXTRA_INCLUDES+=../lib-display/include ../lib-properties/include ../lib-lightset/include ../lib-network/include
55

66
ifneq ($(MAKE_FLAGS),)
77
ifneq (,$(findstring NODE_OSC_CLIENT,$(MAKE_FLAGS)))

lib-osc/include/oscblob.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file oscblob.h
33
*
44
*/
5-
/* Copyright (C) 2016-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
5+
/* Copyright (C) 2016-2024 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
@@ -36,17 +36,14 @@
3636

3737
class OSCBlob {
3838
public:
39-
OSCBlob(const uint8_t *pData, uint32_t nSize) :
40-
m_pData(const_cast<uint8_t*>(pData)), m_nSize(nSize) {
41-
}
42-
~OSCBlob() {
39+
OSCBlob(const uint8_t *pData, uint32_t nSize) : m_pData(pData), m_nSize(nSize) {
4340
}
4441

45-
uint32_t GetDataSize() {
42+
uint32_t GetDataSize() const {
4643
return m_nSize;
4744
}
4845

49-
const uint8_t* GetDataPtr() {
46+
const uint8_t* GetDataPtr() const {
5047
return m_pData;
5148
}
5249

@@ -55,15 +52,15 @@ class OSCBlob {
5552
return (4 * ((nBlobSize + 3) / 4));
5653
}
5754

58-
uint8_t GetByte(uint32_t nIndex) {
55+
uint8_t GetByte(const uint32_t nIndex) {
5956
if (nIndex < m_nSize) {
6057
return m_pData[nIndex];
6158
}
6259
return 0;
6360
}
6461

6562
private:
66-
uint8_t *m_pData;
63+
const uint8_t *m_pData;
6764
uint32_t m_nSize;
6865
};
6966

lib-osc/include/oscclient.h

+100-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @file oscclient.h
33
*
44
*/
5-
/* Copyright (C) 2019-2023 by Arjan van Vught mailto:info@orangepi-dmx.nl
5+
/* Copyright (C) 2019-2024 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
@@ -29,8 +29,16 @@
2929
#include <cstdint>
3030
#include <cassert>
3131

32+
#include "osc.h"
33+
#include "oscsimplesend.h"
3234
#include "oscclientled.h"
3335

36+
#include "hardware.h"
37+
#include "network.h"
38+
#include "display.h"
39+
40+
#include "debug.h"
41+
3442
namespace oscclient {
3543
static constexpr auto STORE = 944; ///< Configuration store in bytes
3644
namespace defaults {
@@ -54,15 +62,92 @@ static constexpr uint32_t LED = oscclient::max::LED_COUNT * oscclient::max::LED_
5462

5563
class OscClient {
5664
public:
57-
OscClient();
58-
~OscClient() {
59-
Stop();
65+
OscClient() :
66+
m_nPortOutgoing(oscclient::defaults::PORT_OUTGOING),
67+
m_nPortIncoming(oscclient::defaults::PORT_INCOMING),
68+
m_nPingDelayMillis(oscclient::defaults::PING_DELAY_SECONDS * 1000)
69+
{
70+
DEBUG_ENTRY
71+
72+
DEBUG_EXIT
73+
}
74+
75+
void Start() {
76+
DEBUG_ENTRY
77+
78+
assert(m_nHandle == -1);
79+
m_nHandle = Network::Get()->Begin(m_nPortIncoming);
80+
assert(m_nHandle != -1);
81+
82+
DEBUG_EXIT
83+
}
84+
85+
void Stop() {
86+
DEBUG_ENTRY
87+
88+
assert(m_nHandle != -1);
89+
Network::Get()->End(m_nPortIncoming);
90+
m_nHandle = -1;
91+
92+
DEBUG_EXIT
6093
}
6194

62-
void Start();
63-
void Stop();
95+
void Run() {
96+
if (!m_bPingDisable) {
97+
m_nCurrenMillis = Hardware::Get()->Millis();
98+
99+
if ((m_nCurrenMillis - m_nPreviousMillis) >= m_nPingDelayMillis) {
100+
OscSimpleSend MsgSend(m_nHandle, m_nServerIP, m_nPortOutgoing, "/ping", nullptr);
101+
m_bPingSent = true;
102+
m_nPreviousMillis = m_nCurrenMillis;
103+
m_nPingTimeMillis = m_nCurrenMillis;
104+
DEBUG_PUTS("Ping sent");
105+
}
106+
}
107+
108+
uint32_t nRemoteIp;
109+
uint16_t nRemotePort;
64110

65-
void Run();
111+
const auto nBytesReceived = Network::Get()->RecvFrom(m_nHandle, reinterpret_cast<const void **>(&m_pBuffer), &nRemoteIp, &nRemotePort);
112+
113+
if (__builtin_expect((nBytesReceived == 0), 1)) {
114+
if (m_bPingSent && ((m_nCurrenMillis - m_nPingTimeMillis) >= 1000)) {
115+
if (m_bPongReceived) {
116+
m_bPongReceived = false;
117+
Display::Get()->TextStatus("No /Pong");
118+
DEBUG_PUTS("No /Pong");
119+
}
120+
}
121+
return;
122+
}
123+
124+
if (nRemoteIp != m_nServerIP) {
125+
DEBUG_PRINTF("Data not received from server " IPSTR , IP2STR(nRemoteIp));
126+
return;
127+
}
128+
129+
if ((m_pOscClientLed != nullptr) && (HandleLedMessage(nBytesReceived))) {
130+
DEBUG_EXIT
131+
return;
132+
}
133+
134+
135+
if (!m_bPingDisable) {
136+
if (!osc::is_match(m_pBuffer, "/pong")) {
137+
DEBUG_PUTS(m_pBuffer);
138+
return;
139+
}
140+
141+
142+
if (!m_bPongReceived) {
143+
Display::Get()->TextStatus("Ping-Pong");
144+
DEBUG_PUTS("Ping-Pong");
145+
}
146+
147+
m_bPongReceived = true;
148+
m_bPingSent = false;
149+
}
150+
}
66151

67152
void Send(const char *pPath);
68153
void SendCmd(uint32_t nCmd);
@@ -125,23 +210,23 @@ class OscClient {
125210
bool HandleLedMessage(const uint16_t nBytesReceived);
126211

127212
private:
128-
uint32_t m_nServerIP { 0 };
129213
uint16_t m_nPortOutgoing;
130214
uint16_t m_nPortIncoming;
131-
int32_t m_nHandle { -1 };
132-
bool m_bPingDisable { false };
133215
uint32_t m_nPingDelayMillis;
134-
bool m_bPingSent { false };
135-
bool m_bPongReceived { false };
136-
char *m_pBuffer { nullptr };
216+
uint32_t m_nServerIP { 0 };
217+
int32_t m_nHandle { -1 };
137218
uint32_t m_nCurrenMillis { 0 };
138219
uint32_t m_nPreviousMillis { 0 };
139220
uint32_t m_nPingTimeMillis { 0 };
221+
const char *m_pBuffer { nullptr };
222+
bool m_bPingDisable { false };
223+
bool m_bPingSent { false };
224+
bool m_bPongReceived { false };
140225

141226
OscClientLed *m_pOscClientLed { nullptr };
142227

143-
static char m_pCmds[oscclient::buffer::size::CMD];
144-
static char m_pLeds[oscclient::buffer::size::LED];
228+
static inline char m_pCmds[oscclient::buffer::size::CMD];
229+
static inline char m_pLeds[oscclient::buffer::size::LED];
145230
};
146231

147232
#endif /* OSCCLIENT_H_ */

0 commit comments

Comments
 (0)