diff --git a/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/cmd_tlm/inst_tlm.txt b/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/cmd_tlm/inst_tlm.txt index 302404dec7..e970a5161f 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/cmd_tlm/inst_tlm.txt +++ b/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/cmd_tlm/inst_tlm.txt @@ -145,5 +145,6 @@ TELEMETRY <%= target_name %> MECH BIG_ENDIAN "Mechanism status" UNITS DEGREES DEG APPEND_ITEM CURRENT 32 FLOAT "Device current" UNITS micro-Ampères µA + APPEND_ITEM STRING 0 STRING "String" ITEM PACKET_TIME 0 0 DERIVED "Ruby time based on TIMESEC and TIMEUS" READ_CONVERSION openc3/conversions/unix_time_conversion.py TIMESEC TIMEUS diff --git a/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/lib/sim_inst.py b/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/lib/sim_inst.py index 2ec0e5f3d5..ec08a0e47b 100644 --- a/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/lib/sim_inst.py +++ b/openc3-cosmos-init/plugins/packages/openc3-cosmos-demo/targets/INST2/lib/sim_inst.py @@ -373,6 +373,7 @@ def read(self, count_100hz, time): packet.write("slrpnl4", self.solar_panel_positions[3]) packet.write("slrpnl5", self.solar_panel_positions[4]) packet.write("current", 0.5) + packet.write("string", f"Time is {time}") # Every 10s throw an unknown packet at the server just to demo that if count_100hz % 1000 == 900: diff --git a/openc3/python/openc3/accessors/binary_accessor.py b/openc3/python/openc3/accessors/binary_accessor.py index 36a2f073c5..c89129a1d9 100644 --- a/openc3/python/openc3/accessors/binary_accessor.py +++ b/openc3/python/openc3/accessors/binary_accessor.py @@ -349,7 +349,10 @@ def write( ####################################### if cls.byte_aligned(bit_offset): - temp = value + if data_type == "STRING" and type(value) == str: + temp = value.encode(encoding="utf-8") + else: + temp = value if given_bit_size <= 0: end_bytes = -math.floor(given_bit_size / 8) old_upper_bound = len(buffer) - 1 - end_bytes diff --git a/openc3/python/test/accessors/test_binary_accessor_write.py b/openc3/python/test/accessors/test_binary_accessor_write.py index 028418d2e7..23a61bc10d 100644 --- a/openc3/python/test/accessors/test_binary_accessor_write.py +++ b/openc3/python/test/accessors/test_binary_accessor_write.py @@ -402,6 +402,18 @@ def test_writes_a_shorter_string_with_zero_bit_size(self): ) self.assertEqual(self.data, b"\x00\x00\x00\x00\x00\x00\x00\x00") + def test_writes_a_string_with_zero_bit_size(self): + BinaryAccessor.write( + "This is a test", + 0, + 0, + "STRING", + self.data, + "BIG_ENDIAN", + "ERROR", + ) + self.assertEqual(self.data, b"This is a test") + def test_writes_a_shorter_block_with_zero_bit_size(self): BinaryAccessor.write( b"\x00\x00\x00\x00\x00\x00\x00\x00",