Skip to content

Commit

Permalink
Adds POM commands to the dcc debug print routine. (#589)
Browse files Browse the repository at this point in the history
* Adds POM commands to the dcc debug print routine.

* fix mixed up printf
  • Loading branch information
balazsracz authored Dec 19, 2021
1 parent 24ca60b commit 9770c9b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
51 changes: 50 additions & 1 deletion src/dcc/DccDebug.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,56 @@ string packet_to_string(const DCCPacket &pkt, bool bin_payload)
else if (cmd == 0 && is_idle_packet)
{
}

else if ((cmd >> 4) == 0b1110)
{
// POM command
options += " POM CV";
unsigned kk = (cmd >> 2) & 3;
unsigned cv = (cmd & 3) << 8;
cv |= pkt.payload[ofs];
ofs++;
options += StringPrintf("%d", cv + 1);
uint8_t d = pkt.payload[ofs++];

switch (kk)
{
case 0b00:
{
options += StringPrintf(" resvd %02x", d);
break;
}
case 0b01:
{
options += StringPrintf(" read/verify %d", d);
break;
}
case 0b11:
{
options += StringPrintf(" write = %d", d);
break;
}
case 0b10:
{
unsigned bit = d & 7;
unsigned value = (d >> 3) & 1;
if ((d & 0xE0) != 0xE0)
{
options += StringPrintf(" bit manipulate unknown (%02x)", d);
break;
}
if ((d & 0x10) == 0x10)
{
options += StringPrintf(" bit %d write = %d", bit, value);
}
else
{
options += StringPrintf(" bit %d verify ?= %d", bit, value);
}
break;
}
}
}

// checksum of packet
if (ofs == pkt.dlc && pkt.packet_header.skip_ec == 0)
{
Expand Down
32 changes: 32 additions & 0 deletions src/dcc/DccDebug.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,38 @@ TEST(DccDebug, F21_28)
EXPECT_EQ("[dcc] Short Address 3 F[21-28]=01101001", packet_to_string(pkt));
}

TEST(DccDebug, POMWrite)
{
Packet pkt;
pkt.add_dcc_address(DccShortAddress(3));
pkt.add_dcc_pom_write1(13, 67);
EXPECT_EQ(
"[dcc] Short Address 3 POM CV14 write = 67", packet_to_string(pkt));
}

TEST(DccDebug, POMWriteHighCV)
{
Packet pkt;
pkt.add_dcc_address(DccShortAddress(3));
pkt.add_dcc_pom_write1(950, 255);
EXPECT_EQ(
"[dcc] Short Address 3 POM CV951 write = 255", packet_to_string(pkt));
pkt.clear();
pkt.add_dcc_address(DccShortAddress(3));
pkt.add_dcc_pom_write1(1023, 0);
EXPECT_EQ(
"[dcc] Short Address 3 POM CV1024 write = 0", packet_to_string(pkt));
}

TEST(DccDebug, POMRead)
{
Packet pkt;
pkt.add_dcc_address(DccShortAddress(3));
pkt.add_dcc_pom_read1(13);
EXPECT_EQ(
"[dcc] Short Address 3 POM CV14 read/verify 0", packet_to_string(pkt));
}

TEST(DccDebug, Accy)
{
Packet pkt;
Expand Down

0 comments on commit 9770c9b

Please sign in to comment.