Skip to content

Commit

Permalink
WIP Checkin
Browse files Browse the repository at this point in the history
  • Loading branch information
gentijo committed May 27, 2023
1 parent 0ed20cb commit 43979f7
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 59 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ RUN apt -y update && \
emacs nano \
cmake git \
gdb gdbserver && \
pip3 install ampy rshell
pip3 install adafruit-ampy rshell

22 changes: 0 additions & 22 deletions src/CustomTemplate.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions src/CustomTemplate.h

This file was deleted.

56 changes: 48 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ std::string buildSelfParams(DataTypeDefinition *dataDef);

void buildDataCatalog(const char* baseType, const char* typeDir);

void createPythonArtifacts(std::string templateFilename);
void createPythonArtifact(std::string filename, DataTypeDefinition *typeDef);
void createPythonArtifacts(std::string outDir, std::string templateFilename);
void createPythonArtifact(std::string outDir, std::string filename, DataTypeDefinition *typeDef);

void build_DTI_table_for_type(std::ofstream &file, string baseType, int index, bool isSubType);

std::map<std::string, std::string> g_typeLocatorMap;

Expand Down Expand Up @@ -110,12 +111,40 @@ extern "C" int main (int argc, char **argv)
g_DataTypeCatalog.print();

std::string filename = templateName;
createPythonArtifacts(filename);
createPythonArtifacts(std::string(outDir),filename);

std::ofstream dti_file;
std::string dti_filename = std::string(outDir) + "/" + std::string(baseType) + ".dti";
dti_file.open (dti_filename);
build_DTI_table_for_type(dti_file, baseType, 0, false);
dti_file.close();

cout << "\r\n End \r\n";
};

void build_DTI_table_for_type(std::ofstream &file, string baseType, int index, bool isSubType) {

int initialIndex = index;
int subIndex = 0;

std::map<std::string, DataTypeDefinition*> dataMap = g_DataTypeCatalog.getDataTypeCatalog();

DataTypeDefinition *type = dataMap.at(string(baseType));

std::list<DataField> fields = type->getFields();
for (auto const& i : fields) {

if (isSubType) { subIndex++; }
else if (initialIndex == 0) { index++; }

file << index << ", " << subIndex << ", " << i.typeName << ", " <<
i.typePrefix << ", " << i.valueName << ", " << i.valueType << "\r\n";

if (i.valueType == rt_ros) build_DTI_table_for_type(file, i.typeName, index, true);

}
}

void buildDataCatalog(const char* baseType, const char* typeDir) {

g_DataTypeCatalog.addDataTypeDefinition(new DataTypeDefinition(baseType, ""));
Expand All @@ -136,23 +165,30 @@ void buildDataCatalog(const char* baseType, const char* typeDir) {
}
}

void createPythonArtifacts(std::string templateFilename) {
void createPythonArtifacts(std::string outDir, std::string templateFilename) {

std::map<std::string, DataTypeDefinition*> dataMap = g_DataTypeCatalog.getDataTypeCatalog();

for (auto typeDef : dataMap) {
createPythonArtifact(templateFilename, typeDef.second);
for (auto dataMapEntry : dataMap) {

DataTypeDefinition *typeDef = dataMapEntry.second;
createPythonArtifact(outDir, templateFilename, typeDef);

}
};

void createPythonArtifact(std::string filename, DataTypeDefinition *typeDef) {
void createPythonArtifact(std::string outDir, std::string filename, DataTypeDefinition *typeDef) {

std::ifstream t(filename, std::ios::binary);

if (t.is_open()) {
t.seekg(0, std::ios::end);
size_t size = t.tellg();
std::string buffer(size, ' ');
t.seekg(0);
t.read(&buffer[0], size);
t.close();

Jinja2CppLight::Template mytemplate(buffer);

mytemplate.setValue("type", typeDef->getTypeName());
Expand All @@ -161,7 +197,11 @@ void createPythonArtifact(std::string filename, DataTypeDefinition *typeDef) {
mytemplate.setValue("selfParams", buildSelfParams(typeDef));

string result = mytemplate.render();
cout << result;

std::string outFilename = outDir + "/" + typeDef->getTypeName() + ".py";
std::ofstream outFile(outFilename);
outFile << result;
outFile.close();
}

}
Expand Down
8 changes: 8 additions & 0 deletions test/output/Twist.dti
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1, 0, Vector3, , linear, 117
1, 1, float64, , x, 114
1, 2, float64, , y, 114
1, 3, float64, , z, 114
2, 0, Vector3, , angular, 117
2, 1, float64, , x, 114
2, 2, float64, , y, 114
2, 3, float64, , z, 114
17 changes: 17 additions & 0 deletions test/output/Twist.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

From Vector3 import Vector3


class Twist:
def __init__(self, linear:Vector3, angular:Vector3):
self.linear:Vector3 = linear
self.angular:Vector3 = angular


#
# Marshal data to ROS
#
def publishToROS(self, endPoint:str):
pass


18 changes: 18 additions & 0 deletions test/output/Vector3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

From float64 import float64


class Vector3:
def __init__(self, x:float64, y:float64, z:float64):
self.x:float64 = x
self.y:float64 = y
self.z:float64 = z


#
# Marshal data to ROS
#
def publishToROS(self, endPoint:str):
pass


8 changes: 8 additions & 0 deletions test/outputTwist.dti
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1, 0, Vector3, , linear, 117
1, 1, float64, , x, 114
1, 2, float64, , y, 114
1, 3, float64, , z, 114
2, 0, Vector3, , angular, 117
2, 1, float64, , x, 114
2, 2, float64, , y, 114
2, 3, float64, , z, 114

0 comments on commit 43979f7

Please sign in to comment.