Skip to content

Commit ad787bc

Browse files
committed
Added first variant of util generator.
1 parent bc72a4f commit ad787bc

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

src/codegen/c-util-generator.cpp

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "c-util-generator.h"
2+
#include <algorithm>
3+
4+
CiUtilGenerator::CiUtilGenerator()
5+
{
6+
Clear();
7+
}
8+
9+
void CiUtilGenerator::Clear()
10+
{
11+
// clear all groups of messages
12+
tx.clear();
13+
rx.clear();
14+
both.clear();
15+
}
16+
17+
18+
void CiUtilGenerator::Generate(std::vector<MessageDescriptor_t*>& msgs, const FsDescriptor_t& fsd,
19+
const MsgsClassification& groups)
20+
{
21+
Clear();
22+
23+
// 1 step is to prepare vectors of message's groups
24+
for (auto m : msgs)
25+
{
26+
auto v = std::find_if(groups.Both.begin(), groups.Both.end(), [&](const uint32_t& msgid)
27+
{
28+
return msgid == m->MsgID;
29+
});
30+
31+
if (v != std::end(groups.Both))
32+
{
33+
// message is in Both group, so put it to rx and tx containers
34+
tx.push_back(m);
35+
rx.push_back(m);
36+
continue;
37+
}
38+
39+
v = std::find_if(groups.Rx.begin(), groups.Rx.end(), [&](const uint32_t& msgid)
40+
{
41+
return msgid == m->MsgID;
42+
});
43+
44+
if (v != std::end(groups.Rx))
45+
{
46+
rx.push_back(m);
47+
continue;
48+
}
49+
50+
v = std::find_if(groups.Tx.begin(), groups.Tx.end(), [&](const uint32_t& msgid)
51+
{
52+
return msgid == m->MsgID;
53+
});
54+
55+
if (v != std::end(groups.Tx))
56+
{
57+
tx.push_back(m);
58+
continue;
59+
}
60+
}
61+
62+
std::sort(rx.begin(), rx.end(), [&](const MessageDescriptor_t* a, const MessageDescriptor_t* b)
63+
{
64+
return a->MsgID < b->MsgID;
65+
});
66+
std::sort(tx.begin(), tx.end(), [&](const MessageDescriptor_t* a, const MessageDescriptor_t* b)
67+
{
68+
return a->MsgID < b->MsgID;
69+
});
70+
71+
fdesc = &fsd;
72+
73+
}
74+

src/codegen/c-util-generator.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
#include "types/message.h"
4+
#include "fs-creator.h"
5+
6+
class CiUtilGenerator {
7+
public:
8+
CiUtilGenerator();
9+
10+
void Clear();
11+
12+
// msgs - the whole list of messages in CAN matrix
13+
// fsd - file and names descriptor
14+
// groups - collection of msg IDs assigned to available groups (rx, tx, both)
15+
16+
// the output of this function source files which contain:
17+
// - global TX and RX typedefs message struct
18+
// - function to Unpack incoming frame to dedicated RX message struct field
19+
// - optional (through define in global "dbccodeconf.h") variable allocation in source files
20+
//
21+
void Generate(std::vector<MessageDescriptor_t*>& msgs, const FsDescriptor_t& fsd, const MsgsClassification& groups);
22+
23+
private:
24+
void PrintHeader();
25+
void PrintSource();
26+
27+
private:
28+
29+
std::vector<MessageDescriptor_t*> tx;
30+
std::vector<MessageDescriptor_t*> rx;
31+
std::vector<MessageDescriptor_t*> both;
32+
33+
const FsDescriptor_t* fdesc;
34+
};

src/types/message.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,14 @@ typedef struct
131131
std::string CommentText;
132132

133133
} MessageDescriptor_t;
134+
135+
typedef struct
136+
{
137+
std::vector<uint32_t> Rx;
138+
139+
std::vector<uint32_t> Tx;
140+
141+
std::vector<uint32_t> Both;
142+
143+
} MsgsClassification;
144+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy