Skip to content

Commit

Permalink
Merge branch 'bracz-esp-compiler-warnings' into bracz-tmp-compile-fix…
Browse files Browse the repository at this point in the history
…-merge

* bracz-esp-compiler-warnings:
  Fix compiler warnings in openmrn when using new GCC's. (#772)
  Fix comment.
  Upintegrate changes from the OpenMRNIDF repository (#771)
  Fix comments.
  Adds support for DCC extended accessories  (#769)
  Fix incorrect consumer identified message being emitted by dcc accy producer. (#768)
  Avoids rendering hidden segments. (#767)
  Adds trailing zero to the cdi XML file written to the filesystem. (#777)
  Fix target subdirectory name (#775)
  • Loading branch information
balazsracz committed Feb 5, 2024
2 parents 850c9ba + 7898dd3 commit 7cc73c8
Show file tree
Hide file tree
Showing 13 changed files with 317 additions and 20 deletions.
2 changes: 1 addition & 1 deletion applications/hub_test/targets/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = \
linux.86 \
linux.x86 \

include $(OPENMRNPATH)/etc/recurse.mk
8 changes: 8 additions & 0 deletions src/dcc/Packet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ void Packet::add_dcc_basic_accessory(unsigned address, bool is_activate)
add_dcc_checksum();
}

void Packet::add_dcc_ext_accessory(unsigned address, uint8_t aspect)
{
add_dcc_accy_address(false, address);
payload[dlc++] = aspect;
add_dcc_checksum();
}


void Packet::set_dcc_logon_enable(
Defs::LogonEnableParam param, uint16_t cid, uint8_t session_id)
{
Expand Down
15 changes: 15 additions & 0 deletions src/dcc/Packet.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,21 @@ TEST_F(PacketTest, DccBasicAccyPom)
0b10011100));
}

TEST_F(PacketTest, DccExtAccySet)
{
pkt_.add_dcc_ext_accessory(1733, 0x5a);
// 1733 = 0x6c5 = 0b 110 1100 0101
uint8_t b1 = 0b10110001;
uint8_t b2 = 0b00010011;
uint8_t b3 = 0x5a;
EXPECT_THAT(get_packet(), ElementsAre(b1, b2, b3, b1 ^ b2 ^ b3));

pkt_.clear();
pkt_.add_dcc_ext_accessory(1733, 0x80);
b3 = 0x80;
EXPECT_THAT(get_packet(), ElementsAre(b1, b2, b3, b1 ^ b2 ^ b3));
}


TEST_F(PacketTest, SvcProgDirectByte)
{
Expand Down
11 changes: 11 additions & 0 deletions src/dcc/Packet.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ struct Packet : public DCCPacket
/// @param is_normal true for normal, false for reverse
/// @param is_activate true for activate, false for deactivate
void set_dcc_basic_accy_params(bool is_normal, bool is_activate);

/// Adds a DCC extended accessory decoder command packet and the checksum
/// byte.
/// @param address is the 11-bit binary address, 0..2047. No bits have to be
/// inverted. This will be A10..A0 on the track. (To convert from a user
/// address, see accy_address_user_to_binary in dcc::Defs.)
/// @param aspect is the argument byte to the extended
/// accessory. Traditionally this was used as an aspect for a signal
/// decoder, but different accessories might have different interpretation
/// of it.
void add_dcc_ext_accessory(unsigned address, uint8_t aspect);

/// Sets the packet to a logon enable packet.
/// @param param defines which decoders should be requested to logon.
Expand Down
4 changes: 2 additions & 2 deletions src/freertos_drivers/esp32/Esp32Gpio.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

#include <driver/gpio.h>
#include <esp_rom_gpio.h>
#include <soc/adc_channel.h>

#include <soc/gpio_struct.h>

Expand Down Expand Up @@ -553,8 +552,9 @@ template <class Defs> struct GpioInputPUPD : public GpioInputPin<Defs, true, tru
struct NAME##Defs \
{ \
static const gpio_num_t PIN_NUM = (gpio_num_t)NUM; \
\
public: \
static gpio_num_t pin() \
static gpio_num_t pin() \
{ \
return PIN_NUM; \
} \
Expand Down
5 changes: 2 additions & 3 deletions src/freertos_drivers/esp32/Esp32HardwareTwai.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
* @date 1 May 2021
*/

// Ensure we only compile this code for the ESP32 family of MCUs and that the
// ESP-IDF version is supported for this code.
// Ensure we only compile this code for the ESP32 family of MCUs.
#if defined(ESP_PLATFORM)

#include "sdkconfig.h"
Expand Down Expand Up @@ -714,7 +713,7 @@ static void twai_isr(void *arg)
{
BaseType_t wakeup = pdFALSE;
uint32_t events = twai_hal_get_events(&twai.context);
ESP_EARLY_LOGV(TWAI_LOG_TAG, "events: %04x", events);
ESP_EARLY_LOGV(TWAI_LOG_TAG, "events: %04" PRIx32, events);

#if defined(CONFIG_TWAI_ERRATA_FIX_RX_FRAME_INVALID) || \
defined(CONFIG_TWAI_ERRATA_FIX_RX_FIFO_CORRUPT)
Expand Down
2 changes: 1 addition & 1 deletion src/freertos_drivers/esp32/Esp32Ledc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/

// Ensure we only compile this code for the ESP32 family of MCUs.
#if defined(ESP32)
#if defined(ESP_PLATFORM)

#include "Esp32Ledc.hxx"

Expand Down
3 changes: 3 additions & 0 deletions src/openlcb/CompileCdiMain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ void render_cdi_helper(const CdiType &t, string ns, string name)
t.config_renderer().render_cdi(&payload);
if (raw_render)
{
// Adds trailing zero to the file written.
payload.push_back(0);
// Writes the file.
string filename = name + ".xmlout";
printf("Writing %d bytes to %s\n", (int)payload.size(),
filename.c_str());
Expand Down
21 changes: 21 additions & 0 deletions src/openlcb/ConfigRenderer.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -351,5 +351,26 @@ TEST(CdiRender, RenderIdent)
EXPECT_EQ(34u, cfg.testseg().e2().offset());
}


CDI_GROUP(TestCdi3, MainCdi());
CDI_GROUP_ENTRY(acdi, Acdi);
CDI_GROUP_ENTRY(testseg, OtherSegment, Hidden(true));
CDI_GROUP_END();

TEST(CdiRender, NoRenderHiddenSegment)
{
string s;
TestCdi3 cfg(0);
cfg.config_renderer().render_cdi(&s);
const char kExpectedTestNodeCdi[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" R"data(
<cdi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://openlcb.org/schema/cdi/1/1/cdi.xsd">
<acdi/>
</cdi>
)data";
EXPECT_EQ(kExpectedTestNodeCdi, s);
EXPECT_EQ(34u, cfg.testseg().e2().offset());
}


} // namespace
} // namespace openlcb
6 changes: 5 additions & 1 deletion src/openlcb/ConfigRenderer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ public:
GroupConfigOptions opts(args..., Body::group_opts());
if (opts.hidden())
{
EmptyGroupConfigRenderer(Body::size() * replication_).render_cdi(s);
if (!opts.is_segment())
{
EmptyGroupConfigRenderer(Body::size() * replication_)
.render_cdi(s);
}
return;
}
const char *tag = nullptr;
Expand Down
80 changes: 80 additions & 0 deletions src/openlcb/DccAccyConsumer.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public:
class DccAccyTest : public AsyncNodeTest
{
protected:
DccAccyTest()
{
wait();
}

StrictMock<MockPacketQueue> trackSendQueue_;
DccAccyConsumer consumer_{node_, &trackSendQueue_};
};
Expand All @@ -72,6 +77,19 @@ TEST_F(DccAccyTest, identify_boot_invalid)
":X198F4111N0101020000FF01F0;", ":X194C722AN0101020000FF01F0;");
}

TEST_F(DccAccyTest, global_identify)
{
clear_expect(true);
// Consumer range for two 4096 long ranges.
expect_packet(":X194A422AN0101020000FF0FFF;");
expect_packet(":X194A422AN0101020000FE0FFF;");

// identify events addressed.
send_packet(":X19968111N022A;");
wait();
}


TEST_F(DccAccyTest, identify_throw_identify)
{
EXPECT_CALL(trackSendQueue_, arrived(_, _)).Times(2);
Expand Down Expand Up @@ -122,4 +140,66 @@ TEST_F(DccAccyTest, packet_throw)
wait();
}


class DccExtAccyTest : public AsyncNodeTest
{
protected:
DccExtAccyTest()
{
wait();
}

StrictMock<MockPacketQueue> trackSendQueue_;
DccExtAccyConsumer consumer_{node_, &trackSendQueue_};
};

TEST_F(DccExtAccyTest, create)
{
}

TEST_F(DccExtAccyTest, global_identify)
{
clear_expect(true);
// Consumer range for one very long range (11 bit plus 8 bit).
expect_packet(":X194A422AN010102000107FFFF;");

// identify events addressed.
send_packet(":X19968111N022A;");
wait();
}


TEST_F(DccExtAccyTest, identify_unknown)
{
// unknown identify
send_packet_and_expect_response(
":X198F4111N0101020001035a77;", ":X194C722AN0101020001035a77;");
}

TEST_F(DccExtAccyTest, packet_throw)
{
uint8_t hdr = 0b01100100;
EXPECT_CALL(trackSendQueue_,
arrived(hdr, ElementsAre(0b10110001, 0b00010011, 0xa5, _)));

// set to 0xa5
send_packet(":X195B4111N010102000106c5a5;");


EXPECT_CALL(trackSendQueue_,
arrived(hdr, ElementsAre(0b10110001, 0b00010011, 0x00, _)));

// set to 0x00
send_packet(":X195B4111N010102000106c500;");

EXPECT_CALL(trackSendQueue_,
arrived(hdr, ElementsAre(0b10110001, 0b00010011, 0xff, _)));

// set to 0xff
send_packet(":X195B4111N010102000106c5ff;");

wait();
}


} // namespace openlcb
Loading

0 comments on commit 7cc73c8

Please sign in to comment.