Skip to content

Commit

Permalink
updated sim API header test
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel-cavalcanti committed Sep 19, 2023
1 parent 0169ca8 commit db350dd
Show file tree
Hide file tree
Showing 8 changed files with 483 additions and 481 deletions.
4 changes: 2 additions & 2 deletions c_transpiler/assets/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ std::tuple<std::vector<uint8_t>, std::vector<int64_t>> getVisionSensorCharImage(
void setVisionSensorCharImage(int64_t sensorHandle, std::vector<uint8_t> image);
std::vector<int64_t> getObjectSelection();
void setObjectSelection(std::vector<double> objectHandles);
std::optional<std::vector<uint8_t>> getStringSignal(std::string signalName);
std::string getStringSignal(std::string signalName);
std::optional<int64_t> getInt32Signal(std::string signalName);
std::optional<double> getFloatSignal(std::string signalName);
int64_t addDrawingObject(int64_t objectType, double size, double duplicateTolerance, int64_t parentObjectHandle, int64_t maxItemCount, std::optional<std::vector<double>> color = {});
Expand Down Expand Up @@ -379,4 +379,4 @@ void writeCustomDataBlock(int64_t objectHandle, std::string tagName, std::vector
void writeCustomDataBlockEx(int64_t handle, std::string tagName, std::string data, std::optional<json> options = {});
void writeCustomTableData(int64_t handle, std::string tagName, json theTable, std::optional<json> options = {});
void writeTexture(int64_t textureId, int64_t options, std::vector<uint8_t> textureData, std::optional<int64_t> posX = {}, std::optional<int64_t> posY = {}, std::optional<int64_t> sizeX = {}, std::optional<int64_t> sizeY = {}, std::optional<double> interpol = {});
std::tuple<double, double, double> yawPitchRollToAlphaBetaGamma(double yawAngle, double pitchAngle, double rollAngle);
std::tuple<double, double, double> yawPitchRollToAlphaBetaGamma(double yawAngle, double pitchAngle, double rollAngle);
2 changes: 1 addition & 1 deletion c_transpiler/assets/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def getObjectSelection(self)->list[int]:
def setObjectSelection(self,objectHandles:list[float])->None:
...

def getStringSignal(self,signalName:str)->Optional[list[int]]:
def getStringSignal(self,signalName:str)->str:
...

def getInt32Signal(self,signalName:str)->Optional[int]:
Expand Down
772 changes: 386 additions & 386 deletions c_transpiler/assets/sim.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion c_transpiler/assets/sim_api_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// DEPRECATED END

// SPECIAL START
std::optional<std::vector<uint8_t>> getStringSignal(std::string signalName);
std::string getStringSignal(std::string signalName);
std::optional<int64_t> getInt32Signal(std::string signalName);
std::optional<double> getFloatSignal(std::string signalName);
// SPECIAL END
Expand Down
161 changes: 80 additions & 81 deletions c_transpiler/assets/sim_ik.rs

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions c_transpiler/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

def cpp_to_rust(assigns: list[FunctionAssign], rust_file: Path) -> None:

rust_assigns = [ir_to_macro_request_rust(assign) for assign in assigns]
rust_string = ",\n".join(rust_assigns)
file_name = rust_file.name.split(".")[0]
trait_name = inflection.camelize(file_name)
space = ' '*4

rust_assigns = [ir_to_macro_request_rust(
assign, file_name) for assign in assigns]
rust_string = ",\n".join(rust_assigns)
content = f'pub trait {trait_name} : RemoteApiClientInterface {{\n{space}requests!{{\n"{file_name}",\n{rust_string}\n}}\n}}'

rust_file.write_text(content)
Expand Down
4 changes: 2 additions & 2 deletions c_transpiler/ir_transpiler/ir_to_macro_request_rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import inflection


def ir_to_macro_request_rust(assign: FunctionAssign) -> str:
def ir_to_macro_request_rust(assign: FunctionAssign, file_name: str) -> str:
return_type = type_node_to_rust(assign.return_type)

rust_func_name = inflection.underscore(assign.function_name)
rust_func_name = f'{file_name}_{inflection.underscore(assign.function_name)}'

required_args = []
option_args = []
Expand Down
13 changes: 7 additions & 6 deletions c_transpiler/tests/test_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_ir_parser_remote_api_header(self):
ir = [ir_to_cpp(assign) for assign in assigns]
result_content = "\n".join(ir)

self.assertEqual(result_content, expected_h.read_text())
self.assertEqual(result_content + '\n', expected_h.read_text())

def test_ir_to_string(self):
vec_u8_ir = TypeNode(TokenType.VEC, [TypeNode(TokenType.U8, [])])
Expand Down Expand Up @@ -236,12 +236,13 @@ def test_ir_to_macro_request_rust(self):
wait_ir, get_vision_sensor_depth_buffer_if]

expected_strings = [
'(switch_thread,"switchThread"->())',
'(unpack_table,"unpackTable",(buffer:Vec<u8>)->serde_json::Value)',
'(wait,"wait",(dt:f64),opt(simulation_time:bool)->f64)',
'(get_vision_sensor_depth_buffer,"getVisionSensorDepthBuffer",(sensor_handle:i64),opt(pos:Vec<i64>,size:Vec<i64>)->(Vec<u8>,Vec<i64>))'
'(test_switch_thread,"switchThread"->())',
'(test_unpack_table,"unpackTable",(buffer:Vec<u8>)->serde_json::Value)',
'(test_wait,"wait",(dt:f64),opt(simulation_time:bool)->f64)',
'(test_get_vision_sensor_depth_buffer,"getVisionSensorDepthBuffer",(sensor_handle:i64),opt(pos:Vec<i64>,size:Vec<i64>)->(Vec<u8>,Vec<i64>))'
]
result = [ir_to_macro_request_rust(ir) for ir in inputs]
result = [ir_to_macro_request_rust(
ir, file_name='test') for ir in inputs]
self.assertEqualStrings(result, expected_strings)

def assertEqualStrings(self, result: list[str], expected: list[str]):
Expand Down

0 comments on commit db350dd

Please sign in to comment.