Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slave stack - various fixes and start unit tests #191

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ if (GTest_FOUND)
unit/gateway-t.cc
unit/kickcat-t.cc
unit/link-t.cc
unit/mailbox-t.cc
unit/prints-t.cc
unit/protocol-t.cc
unit/slave-t.cc
unit/socket-t.cc
unit/Time.cc
unit/CoE/protocol-t.cc
unit/mailbox/request-t.cc
unit/mailbox/response-t.cc
)

target_link_libraries(kickcat_unit kickcat GTest::gmock_main)
target_include_directories(kickcat_unit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/unit)
set_kickcat_properties(kickcat_unit)
add_test(NAME kickcat COMMAND kickcat_unit WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

Expand Down
4 changes: 2 additions & 2 deletions examples/master/load_esi/load_esi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

using namespace kickcat;

int main()
int main(int, char const* argv[])
{
CoE::EsiParser parser;

nanoseconds t1 = since_epoch();
CoE::Dictionary coe_dict = parser.load("ingenia_esi.xml");
CoE::Dictionary coe_dict = parser.load(argv[1]);
nanoseconds t2 = since_epoch();

// dangerous lack of error checking.
Expand Down
Binary file modified examples/slave/nuttx/xmc4800/boards/wdc_foot/foot.bin
Binary file not shown.
135 changes: 132 additions & 3 deletions examples/slave/nuttx/xmc4800/boards/wdc_foot/foot.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Groups>
<Group SortOrder="0">
<Type>XMC4800 Wandercraft</Type>
<Name LcId="1033">foot</Name>
<Name LcId="1033">Foot</Name>
</Group>
</Groups>
<Devices>
Expand All @@ -36,7 +36,8 @@
</Info>
<GroupType>XMC4800 Wandercraft</GroupType>
<Profile>
<ProfileNo>402</ProfileNo>
<!-- Profile custom -->
<ProfileNo>0</ProfileNo>
<!-- Dictionnary -->
<Dictionary>

Expand Down Expand Up @@ -157,6 +158,79 @@
</SubItem>
</DataType>

<DataType>
<Name>DT1C12</Name>
<BitSize>32</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Subindex 000</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access WriteRestrictions="PreOP">rw</Access>
<Category>o</Category>
<Backup>0</Backup>
<Setting>0</Setting>
</Flags>
</SubItem>
<SubItem>
<Name>Elements</Name>
<Type>DT1C12ARR</Type>
<BitSize>16</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access WriteRestrictions="PreOP">rw</Access>
<Category>o</Category>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1C12ARR</Name>
<BaseType>UINT</BaseType>
<BitSize>16</BitSize>
<ArrayInfo>
<LBound>1</LBound>
<Elements>1</Elements>
</ArrayInfo>
</DataType>
<DataType>
<Name>DT1C13</Name>
<BitSize>32</BitSize>
<SubItem>
<SubIdx>0</SubIdx>
<Name>Subindex 000</Name>
<Type>USINT</Type>
<BitSize>8</BitSize>
<BitOffs>0</BitOffs>
<Flags>
<Access WriteRestrictions="PreOP">rw</Access>
<Category>o</Category>
<Backup>0</Backup>
<Setting>0</Setting>
</Flags>
</SubItem>
<SubItem>
<Name>Elements</Name>
<Type>DT1C13ARR</Type>
<BitSize>16</BitSize>
<BitOffs>16</BitOffs>
<Flags>
<Access WriteRestrictions="PreOP">rw</Access>
<Category>o</Category>
</Flags>
</SubItem>
</DataType>
<DataType>
<Name>DT1C13ARR</Name>
<BaseType>UINT</BaseType>
<BitSize>16</BitSize>
<ArrayInfo>
<LBound>1</LBound>
<Elements>1</Elements>
</ArrayInfo>
</DataType>

<DataType>
<Name>DT2000</Name> <!-- Value ?-->
<BitSize>80</BitSize>
Expand Down Expand Up @@ -204,7 +278,21 @@

<!-- Objects -->
<Objects>

<Object>
<Index>#x1000</Index>
<Name>Device Type</Name>
<Type>UDINT</Type>
<BitSize>32</BitSize>
<Info>
<DefaultData>00000000</DefaultData>
</Info>
<Flags>
<Access>ro</Access>
<Category>m</Category>
<Backup>0</Backup>
<Setting>0</Setting>
</Flags>
</Object>
<Object>
<Index>#x1018</Index>
<Name>Identity Object</Name>
Expand Down Expand Up @@ -244,6 +332,47 @@
</Info>
</Object>

<Object>
<Index>#x1c12</Index>
<Name>RxPDO assign</Name>
<Type>DT1C12</Type>
<BitSize>32</BitSize>
<Info>
<SubItem>
<Name>Subindex 000</Name>
<Info>
<DefaultData>01</DefaultData>
</Info>
</SubItem>
<SubItem>
<Name>RxPDO assign Element 1</Name>
<Info>
<DefaultData>0016</DefaultData>
</Info>
</SubItem>
</Info>
</Object>
<Object>
<Index>#x1c13</Index>
<Name>TxPDO assign</Name>
<Type>DT1C13</Type>
<BitSize>32</BitSize>
<Info>
<SubItem>
<Name>Subindex 000</Name>
<Info>
<DefaultData>01</DefaultData>
</Info>
</SubItem>
<SubItem>
<Name>TxPDO assign Element 1</Name>
<Info>
<DefaultData>001a</DefaultData>
</Info>
</SubItem>
</Info>
</Object>

<Object>
<Index>#x2000</Index>
<Name>FreezeValue</Name>
Expand Down
60 changes: 36 additions & 24 deletions examples/slave/nuttx/xmc4800/od_populator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,31 @@ namespace kickcat::CoE
{
CoE::Dictionary dictionary;

{
CoE::Object object
{
0x1000,
CoE::ObjectCode::VAR,
"Device Type",
{}
};
CoE::addEntry<uint32_t>(object,0,32,0,7,static_cast<CoE::DataType>(7),"",0x0);
dictionary.push_back(std::move(object));
}

{
CoE::Object object
{
0x1018,
CoE::ObjectCode::ARRAY,
CoE::ObjectCode::RECORD,
"Identity Object",
{}
};
CoE::addEntry(object,0,8, 7,static_cast<CoE::DataType>(5),"Subindex 000",0x4);
CoE::addEntry(object,1,32,7,static_cast<CoE::DataType>(7),"Vendor ID",0x6a5);
CoE::addEntry(object,2,32,7,static_cast<CoE::DataType>(7),"Product code",0xb0cad0);
CoE::addEntry(object,3,32,7,static_cast<CoE::DataType>(7),"Revision number",0x0);
CoE::addEntry(object,4,32,7,static_cast<CoE::DataType>(7),"Serial number",0xcafedeca);
CoE::addEntry<uint8_t>(object,0,8,0,7,static_cast<CoE::DataType>(5),"Subindex 000",0x4);
CoE::addEntry<uint32_t>(object,1,32,16,7,static_cast<CoE::DataType>(7),"Vendor ID",0x6a5);
CoE::addEntry<uint32_t>(object,2,32,48,7,static_cast<CoE::DataType>(7),"Product code",0xb0cad0);
CoE::addEntry<uint32_t>(object,3,32,80,7,static_cast<CoE::DataType>(7),"Revision number",0x0);
CoE::addEntry<uint32_t>(object,4,32,112,7,static_cast<CoE::DataType>(7),"Serial number",0xcafedeca);
dictionary.push_back(std::move(object));
}

Expand All @@ -32,8 +44,8 @@ namespace kickcat::CoE
"RxPDO Map 1",
{}
};
CoE::addEntry(object,0,8,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry(object,1,32,15,static_cast<CoE::DataType>(7),"RxPDO Map 1 Element 1",0x10);
CoE::addEntry<uint8_t>(object,0,8,0,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry<uint32_t>(object,1,32,16,15,static_cast<CoE::DataType>(7),"RxPDO Map 1 Element 1",0x10);
dictionary.push_back(std::move(object));
}

Expand All @@ -45,8 +57,8 @@ namespace kickcat::CoE
"TxPDO Map 1",
{}
};
CoE::addEntry(object,0,8,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry(object,1,32,15,static_cast<CoE::DataType>(7),"TxPDO Map 1 Element 1",0xe0);
CoE::addEntry<uint8_t>(object,0,8,0,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry<uint32_t>(object,1,32,16,15,static_cast<CoE::DataType>(7),"TxPDO Map 1 Element 1",0xe0);
dictionary.push_back(std::move(object));
}

Expand All @@ -58,11 +70,11 @@ namespace kickcat::CoE
"Sync manager type",
{}
};
CoE::addEntry(object,0,8,7,static_cast<CoE::DataType>(5),"Subindex 0",0x4);
CoE::addEntry(object,1,8,7,static_cast<CoE::DataType>(5),"Subindex 1",0x1);
CoE::addEntry(object,2,8,7,static_cast<CoE::DataType>(5),"Subindex 2",0x2);
CoE::addEntry(object,3,8,7,static_cast<CoE::DataType>(5),"Subindex 3",0x3);
CoE::addEntry(object,4,8,7,static_cast<CoE::DataType>(5),"Subindex 4",0x4);
CoE::addEntry<uint8_t>(object,0,8,0,7,static_cast<CoE::DataType>(5),"Subindex 0",0x4);
CoE::addEntry<uint32_t>(object,1,8,16,7,static_cast<CoE::DataType>(5),"Subindex 1",0x1);
CoE::addEntry<uint32_t>(object,2,8,24,7,static_cast<CoE::DataType>(5),"Subindex 2",0x2);
CoE::addEntry<uint32_t>(object,3,8,32,7,static_cast<CoE::DataType>(5),"Subindex 3",0x3);
CoE::addEntry<uint32_t>(object,4,8,40,7,static_cast<CoE::DataType>(5),"Subindex 4",0x4);
dictionary.push_back(std::move(object));
}

Expand All @@ -74,8 +86,8 @@ namespace kickcat::CoE
"RxPDO assign",
{}
};
CoE::addEntry(object,0,8,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry(object,1,32,15,static_cast<CoE::DataType>(7),"RxPDO assign Element 1",0x1600);
CoE::addEntry<uint8_t>(object,0,8,0,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry<uint16_t>(object,1,16,16,15,static_cast<CoE::DataType>(6),"RxPDO assign Element 1",0x1600);
dictionary.push_back(std::move(object));
}

Expand All @@ -87,25 +99,25 @@ namespace kickcat::CoE
"TxPDO assign",
{}
};
CoE::addEntry(object,0,8,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry(object,1,32,15,static_cast<CoE::DataType>(7),"TxPDO assign Element 1",0x1a00);
CoE::addEntry<uint8_t>(object,0,8,0,15,static_cast<CoE::DataType>(5),"Subindex 000",0x1);
CoE::addEntry<uint16_t>(object,1,16,16,15,static_cast<CoE::DataType>(6),"TxPDO assign Element 1",0x1a00);
dictionary.push_back(std::move(object));
}

{
CoE::Object object
{
0x2000,
CoE::ObjectCode::ARRAY,
CoE::ObjectCode::RECORD,
"FreezeValue",
{}
};
CoE::addEntry(object,0,8,7,static_cast<CoE::DataType>(5),"Subindex 000",0x2);
CoE::addEntry(object,1,32,63,static_cast<CoE::DataType>(7),"ForceSensor0",0x2);
CoE::addEntry(object,2,32,63,static_cast<CoE::DataType>(7),"IMU",0x2);
CoE::addEntry<uint8_t>(object,0,8,0,7,static_cast<CoE::DataType>(5),"Subindex 000",0x2);
CoE::addEntry<uint32_t>(object,1,32,16,63,static_cast<CoE::DataType>(7),"ForceSensor0",0x2);
CoE::addEntry<uint32_t>(object,2,32,48,63,static_cast<CoE::DataType>(7),"IMU",0x2);
dictionary.push_back(std::move(object));
}

return dictionary;
return dictionary;
}
}
4 changes: 2 additions & 2 deletions lib/include/kickcat/CoE/EsiParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace kickcat::CoE

uint16_t loadAccess(tinyxml2::XMLNode* node);

std::tuple<DataType, uint16_t> toType(tinyxml2::XMLNode* node);
std::tuple<DataType, uint16_t, uint16_t> parseType(tinyxml2::XMLNode* node);

tinyxml2::XMLNode* findNodeType(tinyxml2::XMLNode* node);

Expand All @@ -61,7 +61,7 @@ namespace kickcat::CoE
tinyxml2::XMLElement* dtypes_;
tinyxml2::XMLElement* objects_;

static const std::unordered_map<std::string, std::tuple<DataType, uint16_t>> BASIC_TYPES;
static const std::unordered_map<std::string, DataType> BASIC_TYPES;
static const std::unordered_map<std::string, uint8_t> SM_CONF;
};
}
Expand Down
Loading
Loading