in agora/contoso_motors/src/opc-simulator/app/frame_record_replay.py [0:0]
def record_frame(self, update_list: UpdateList, device: Device):
# pylint: disable=R0912
if not self.record:
return
num_vars_in_frame = len(update_list)
self.write_int(num_vars_in_frame, 2, False)
dev_var_types = self.var_types[device.device_type.name]
for var_name, var_val, var_good in update_list:
var_type, var_idx = dev_var_types[var_name]
self.write_int(var_idx, 2, False)
self.write_int(var_type.value, 1, False)
self.write_int(var_good, 1, False)
if var_type == ua.VariantType.Boolean:
self.write_int(var_val, 1, False)
elif var_type == ua.VariantType.SByte:
self.write_int(var_val, 1, True)
elif var_type == ua.VariantType.Byte:
self.write_int(var_val, 1, False)
elif var_type == ua.VariantType.Int16:
self.write_int(var_val, 2, True)
elif var_type == ua.VariantType.UInt16:
self.write_int(var_val, 2, False)
elif var_type == ua.VariantType.Int32:
self.write_int(var_val, 4, True)
elif var_type == ua.VariantType.UInt32:
self.write_int(var_val, 4, False)
elif var_type == ua.VariantType.Int64:
self.write_int(var_val, 8, True)
elif var_type == ua.VariantType.UInt64:
self.write_int(var_val, 8, False)
elif var_type == ua.VariantType.Float:
self.record_fp.write(struct.pack(">f", var_val))
elif var_type == ua.VariantType.Double:
self.record_fp.write(struct.pack(">d", var_val))
elif var_type == ua.VariantType.String:
bin_val = var_val.encode("utf-8")
self.write_int(bin_val, 4, False)
self.record_fp.write(bin_val)
elif var_type == ua.VariantType.DateTime:
bin_val = var_val.isoformat().encode("utf-8")
self.write_int(bin_val, 1, False)
self.record_fp.write(bin_val)
self.record_fp.flush()
self.num_frames_write += 1