简体   繁体   English

类图传感器接口

[英]class diagram sensor interface

To organize my software better I'm starting to port my matlab functions to matlab classes and I'm struggling a bit with the oop concept. 为了更好地组织软件,我开始将matlab函数移植到matlab类中,并且在oop概念上有些挣扎。

Thats the situation: 多数民众赞成在这种情况:

  • there are physical sensors measuring a position in various ways. 有物理传感器以各种方式测量位置。 Each sensor has a different calculation algorithm, but all sensors do have smiliar properties: temperature, rawData, serialNumber etc. 每个传感器都有不同的计算算法,但所有传感器的确具有以下特殊属性:温度,rawData,serialNumber等。
  • I want to simulate the sensor's output (via previously saved data from a database or a csv file) or get data directly from an UART interface. 我想模拟传感器的输出(通过以前从数据库或csv文件保存的数据)或直接从UART接口获取数据。
  • the data format differs, but the readout functions are similar (loading columns from a csv file or from a database) 数据格式不同,但读出功能相似(从csv文件或数据库中加载列)
  • I want to calibrate the sensors within a class "SensorToolbox". 我想在“ SensorToolbox”类中校准传感器。 This class could be used by a GUI and shall be as generic as possible. GUI可以使用此类,并且应尽可能通用。

Here is my first class diagram attached: classDiagram 这是我的第一个类图: classDiagram

My main objective is where to put the "loadDataFromX" and "calibrateSensor" methods. 我的主要目标是在哪里放置“ loadDataFromX”和“ calibrateSensor”方法。 If I consider a sensor object representating a "real" sensor, then the sensor can not load data or calibrate itself. 如果我认为代表“真实”传感器的传感器对象,则该传感器无法加载数据或自行校准。 It's only possible via a function in the "SensorToolbox". 仅可通过“ SensorToolbox”中的功能进行。 But the calibration realization is different for each sensor. 但是每个传感器的校准实现方式都不相同。 So putting the function into the toolbox would require the detection of the class type and a implementation outside the sensor. 因此,将功能放入工具箱将需要检测类类型并在传感器外部进行实现。 The same applies to the sensor's data. 这同样适用于传感器的数据。 Calling "loadDataFromFile" from the toolbox would require to know the needed dataformat outside of the sensor. 从工具箱中调用“ loadDataFromFile”将需要知道传感器外部所需的数据格式。

Hopefully you understand my problem and you can push me into the right direction, thank you! 希望您理解我的问题,并且可以将我推向正确的方向,谢谢!

I think you should put these methods into sensors. 我认为您应该将这些方法应用于传感器。 Don't worry that they don't 100% represent the behavior of the real sensor, it is just a model. 不必担心它们不能100%代表真实传感器的行为,它只是一个模型。

Another option is to share these methods between SensorToolbox and Sensor. 另一个选择是在SensorToolbox和Sensor之间共享这些方法。 For example, SensorToolbox can read the data from different datasources and then pass in to the Sensor, for example (pseudocode): 例如,SensorToolbox可以从不同的数据源读取数据,然后传递到Sensor中,例如(伪代码):

SensorToolbox::loadDataFromDatabase():
   database = Database()
   data = database->readData()
   sensor->loadData(data)

SensorToolbox::loadDataFromFile():
   file = File('path/to/file')
   data = file->read()
   sensor->loadData(data)

Same for the calibration, SensorToolbox can have this method and then just path it to the Sensor (or maybe do some preparation before it): 与校准相同,SensorToolbox可以使用此方法,然后将其传递到Sensor(或在此之前做一些准备工作):

SensorToolbox::calibrate(Sensor sensor, SensorData data):
   // check the data
   // ...
   sensor->calibrate(data)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM