Skip to content

Commit

Permalink
today()
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph2 committed Aug 5, 2024
1 parent cf86b19 commit 2925fc6
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 27 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(pya2l_extensions LANGUAGES C CXX)

cmake_policy(SET CMP0135 NEW)

# find_package(Python COMPONENTS Interpreter Development)
find_package(Python COMPONENTS Interpreter Development)
find_package(pybind11 REQUIRED)

set(ANTLR4_TAG 4.13.1)
Expand Down Expand Up @@ -133,7 +133,7 @@ target_link_libraries(if_data_parser antlr4_static ${SYSTEM_LIBS})
target_include_directories(aml_tester PUBLIC ${ANTLR4_INCLUDE_DIRS} ${ANTLR_AMLParser_OUTPUT_DIR} ${PROJECT_SOURCE_DIR}/pya2l/aml)
target_include_directories(if_data_parser PUBLIC ${ANTLR4_INCLUDE_DIRS} ${ANTLR_pyA2LLexer_OUTPUT_DIR} ${ANTLR_AMLParser_OUTPUT_DIR} ${PROJECT_SOURCE_DIR}/pya2l/aml) # !?

message("am_tester / output: " ${aml_tester_OUTPUT_DIRECTORY})
message("aml_tester / output: " ${aml_tester_OUTPUT_DIRECTORY})


# include generated files in project environment
Expand Down
37 changes: 17 additions & 20 deletions pya2l/aml/unmarshal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ class Node {
} else {
for (auto entry : get_members()) {
std::cout << static_cast<int>(entry->node_type()) << " " << static_cast<int>(entry->aml_type()) << std::endl;
if (entry->aml_type() == Node::AmlType::BLOCK) {
//if (entry->aml_type() == Node::AmlType::BLOCK) {
if (entry->get_tag() == name) {
return entry;
}
}
//}
}
}
return nullptr;
}

std::tuple<bool, std::optional<const Node*>, std::optional<const Node*>> member_or_type() const noexcept {
if (m_aml_type == AmlType::BLOCK) {
//if (m_aml_type == AmlType::BLOCK) {
auto multiple = is_multiple();
const auto& member = m_map.at("MEMBER");
if (member.aml_type() == Node::AmlType::NONE) {
Expand All @@ -127,7 +127,7 @@ class Node {
} else {
return { multiple, &member, std::nullopt };
}
}
//}
return { false, {}, {} };
}

Expand Down Expand Up @@ -157,28 +157,25 @@ class Node {
}

bool is_multiple() const noexcept {
if (m_node_type == NodeType::MAP) {
if ((m_node_type == NodeType::MAP) && (m_map.contains("MULTIPLE"))) {
const auto& multiple = m_map.at("MULTIPLE");
return bool(std::get<long long>(multiple.value()));
}
return false;
}

std::tuple<std::vector<long long>, const Node*> get_type() const noexcept {
if (m_node_type == NodeType::MAP) {
if (m_map.contains("MEMBER")) {
std::vector<long long> arr_spec;
const auto& member = m_map.at("MEMBER");
for (const auto& elem : member.map().at("ARR_SPEC").list()) {
arr_spec.push_back(std::get<long long>(elem.value()));
}
const auto& type = member.map().at("TYPE");
return { arr_spec, &type };
} else {
return {};
std::vector<long long> arr_spec;
if ((m_map.contains("TYPE")) && (m_map.contains("ARR_SPEC"))) {
const auto& type = map().at("TYPE");
for (const auto& elem : map().at("ARR_SPEC").list()) {
arr_spec.push_back(std::get<long long>(elem.value()));
}
return { arr_spec, &type };
}
else {
return {};
}
return {};
}

std::vector<const Node*> get_members() const noexcept {
Expand Down Expand Up @@ -210,9 +207,9 @@ class Node {
const auto& ts_def = ts_member.map().at("DEFINITION");
const auto ts_mult = bool(ts_member.map().at("MULTIPLE").get_int());

const auto& tsd_type = ts_def.map().at("TYPE");
const auto& tsd_member = ts_def.map().at("MEMBER");
const auto tsd_mult = bool(ts_def.map().at("MULTIPLE").get_int());
result.emplace(ts_tag, std::forward_as_tuple( & tsd_type, ts_mult, tsd_mult ));
result.emplace(ts_tag, std::forward_as_tuple( & tsd_member, ts_mult, tsd_mult ));
}
return result;
}
Expand Down Expand Up @@ -321,7 +318,7 @@ inline Node make_tagged_struct_definition(bool multiple, std::optional<Node> typ

Node::map_t map = {
{ "MULTIPLE", Node(Node::AmlType::TERMINAL, multiple) },
{ "TYPE", type_node },
{ "MEMBER", type_node },
};
auto res = Node(Node::AmlType::TAGGED_STRUCT_DEFINITION, map);
return res;
Expand Down
177 changes: 172 additions & 5 deletions pya2l/if_data_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class IfDataParser {
}

void parse() {
do_type();
#if 0
auto token = current_token();
if (token) {
auto [type, text] = *token;
Expand All @@ -44,6 +46,7 @@ class IfDataParser {
}
parse();
}
#endif
}

token_t next_token() {
Expand Down Expand Up @@ -106,7 +109,15 @@ class IfDataParser {
break;
}
} else if (member) {
m_grammar.push(*member);
const auto mem_real = *member;
if (mem_real->aml_type() == Node::AmlType::TAGGED_STRUCT_MEMBER) {
const auto& def = mem_real->map().at("DEFINITION");
const auto& [mmultiple, mmember, mtype] = def.member_or_type();
m_grammar.push(*mtype);
do_type();
m_grammar.pop();
}
//m_grammar.push(*member);
}
m_grammar.pop();
}
Expand All @@ -129,6 +140,14 @@ class IfDataParser {
}

void struct_type() {
const auto tos = top();
for (const auto& member: tos->get_members()) {
auto token = current_token();
if (token) {
auto [tp, text] = *token;
}
consume();
}
}

void tagged_struct_type() {
Expand All @@ -137,16 +156,23 @@ class IfDataParser {
auto [tp, text] = *token;
const auto tos = top();
const auto& ts_members = tos->get_tagged_struct_members();
const auto& [type, b0, b1] = ts_members.at(text);
const auto& [member, b0, b1] = ts_members.at(text);
const auto& [arr_spec, type] = member->get_type();
m_grammar.push(type);
consume();
do_type();
m_grammar.pop();

}
}

void tagged_union_type() {
auto token = current_token();
if (token) {
auto [tp, text] = *token;
const auto member = top()->find_tag(text);
const auto& [arr_spec, type] = member->get_type();
const auto tu_member = top()->find_tag(text);
const auto& member = tu_member->map().at("MEMBER");
const auto& [arr_spec, type] = member.get_type();
m_grammar.push(type);
consume();
do_type();
Expand All @@ -156,6 +182,19 @@ class IfDataParser {

void do_type() {
const auto tos = top();
auto token = current_token();
if (token) {
auto [type, text] = *token;
switch (type) {
case a2llg::BEGIN:
consume();
block_type();
break;
default:
std::cerr << "Unknown token type: " << type << std::endl;
}
}

switch (tos->aml_type()) {
case Node::AmlType::STRUCT:
struct_type();
Expand Down Expand Up @@ -197,6 +236,132 @@ class IfDataParser {
const std::string BASE{ "C:/csProjects/" };
//const std::string BASE{ ""C:/Users/HP/PycharmProjects/" };

const std::string CPLX_TEXT{
"" \
" /begin IF_DATA ASAP1B_CCP" \
" /begin SOURCE" \
" \"segment synchronous event channel\"" \
" 103" \
" 1" \
" /begin QP_BLOB" \
" 0" \
" LENGTH 8" \
" CAN_ID_FIXED 0x330" \
" FIRST_PID 0" \
" RASTER 0" \
" /end QP_BLOB" \
" /end SOURCE" \
" " \
" /begin SOURCE" \
" \"10ms time synchronous event channel\"" \
" 4" \
" 1" \
" /begin QP_BLOB" \
" 1" \
" LENGTH 12" \
" CAN_ID_FIXED 0x340" \
" FIRST_PID 8" \
" RASTER 1" \
" /end QP_BLOB" \
" /end SOURCE" \
" " \
" /begin SOURCE" \
" \"100ms time synchronous event channel\"" \
" 4" \
" 10" \
" /begin QP_BLOB" \
" 2" \
" LENGTH 8" \
" CAN_ID_FIXED 0x350" \
" FIRST_PID 20" \
" RASTER 2" \
" /end QP_BLOB" \
" /end SOURCE" \
" " \
" /begin RASTER" \
" \"segment synchronous event channel\"" \
" \"seg_sync\"" \
" 0" \
" 103" \
" 1" \
" /end RASTER" \
" " \
" /begin RASTER" \
" \"10ms time synchronous event channel\"" \
" \"10_ms\"" \
" 1" \
" 4" \
" 1" \
" /end RASTER" \
" " \
" /begin RASTER" \
" \"100ms time synchronous event channel\"" \
" \"100_ms\"" \
" 2" \
" 4" \
" 10" \
" /end RASTER" \
" " \
" /begin SEED_KEY" \
" \"\"" \
" \"\"" \
" \"\"" \
" /end SEED_KEY" \
" " \
" /begin TP_BLOB" \
" 0x200" \
" 0x202" \
" 0x200" \
" 0x210" \
" 0x1234" \
" 1" \
" " \
" /begin CAN_PARAM" \
" 0x3E8" \
" 0x40" \
" 0x16" \
" /end CAN_PARAM" \
" " \
" DAQ_MODE BURST" \
" CONSISTENCY DAQ" \
" " \
" /begin CHECKSUM_PARAM " \
" 0xC001" \
" 0xFFFFFFFF" \
" CHECKSUM_CALCULATION ACTIVE_PAGE" \
" /end CHECKSUM_PARAM " \
" " \
" /begin DEFINED_PAGES" \
" 1" \
" \"reference page\"" \
" 0x00" \
" 0x8E0670" \
" 0x1C26C" \
" ROM" \
" /end DEFINED_PAGES" \
" " \
" /begin DEFINED_PAGES" \
" 2" \
" \"working page\"" \
" 0x00" \
" 0x808E0670" \
" 0x1C26C" \
" RAM" \
" RAM_INIT_BY_ECU" \
" /end DEFINED_PAGES" \
" " \
" OPTIONAL_CMD 0x11 " \
" OPTIONAL_CMD 0xE " \
" OPTIONAL_CMD 0x19 " \
" OPTIONAL_CMD 0x9 " \
" OPTIONAL_CMD 0xC " \
" OPTIONAL_CMD 0xD " \
" OPTIONAL_CMD 0x12 " \
" OPTIONAL_CMD 0x13 " \
" /end TP_BLOB" \
" /end IF_DATA"
};

int main() {
std::ifstream stream;

Expand All @@ -214,7 +379,9 @@ int main() {
"0x10000\n"
"0x1E8\n"
"/end IF_DATA");
auto lex = IfDataParser(root, TEXT);
//auto lex = IfDataParser(root, TEXT);
auto lex = IfDataParser(root, CPLX_TEXT);

lex.parse();

return 0;
Expand Down

0 comments on commit 2925fc6

Please sign in to comment.