Aktualizr
C++ SOTA Client
ecuversionmanifestsigned.h
1 #ifndef OPCUABRIDGE_ECUVERSIONMANIFESTSIGNED_H_
2 #define OPCUABRIDGE_ECUVERSIONMANIFESTSIGNED_H_
3 
4 #include "image.h"
5 
6 #include "common.h"
7 
8 namespace opcuabridge {
10  public:
11  ECUVersionManifestSigned() = default;
12  virtual ~ECUVersionManifestSigned() = default;
13 
14  const std::string& getEcuIdentifier() const { return ecuIdentifier_; }
15  void setEcuIdentifier(const std::string& ecuIdentifier) { ecuIdentifier_ = ecuIdentifier; }
16  const int& getPreviousTime() const { return previousTime_; }
17  void setPreviousTime(const int& previousTime) { previousTime_ = previousTime; }
18  const int& getCurrentTime() const { return currentTime_; }
19  void setCurrentTime(const int& currentTime) { currentTime_ = currentTime; }
20  const std::string& getSecurityAttack() const { return securityAttack_; }
21  void setSecurityAttack(const std::string& securityAttack) { securityAttack_ = securityAttack; }
22  const Image& getInstalledImage() const { return installedImage_; }
23  void setInstalledImage(const Image& installedImage) { installedImage_ = installedImage; }
24 
25  Json::Value wrapMessage() const {
26  Json::Value v;
27  v["ecu_serial"] = getEcuIdentifier();
28  v["previous_timeserver_time"] = getPreviousTime();
29  v["timeserver_time"] = getCurrentTime();
30  v["attacks_detected"] = getSecurityAttack();
31  v["installed_image"] = getInstalledImage().wrapMessage();
32  return v;
33  }
34  void unwrapMessage(Json::Value v) {
35  setEcuIdentifier(v["ecu_serial"].asString());
36  setPreviousTime(v["previous_timeserver_time"].asInt());
37  setCurrentTime(v["timeserver_time"].asInt());
38  setSecurityAttack(v["attacks_detected"].asString());
39  Image i;
40  i.unwrapMessage(v["installed_image"]);
41  setInstalledImage(i);
42  }
43 
44  protected:
45  std::string ecuIdentifier_;
46  int previousTime_{};
47  int currentTime_{};
48  std::string securityAttack_;
49  Image installedImage_;
50 
51  private:
52 #ifdef OPCUABRIDGE_ENABLE_SERIALIZATION
53  SERIALIZE_FUNCTION_FRIEND_DECLARATION
54 
55  DEFINE_SERIALIZE_METHOD() {
56  SERIALIZE_FIELD(ar, "ecuIdentifier_", ecuIdentifier_);
57  SERIALIZE_FIELD(ar, "previousTime_", previousTime_);
58  SERIALIZE_FIELD(ar, "currentTime_", currentTime_);
59  SERIALIZE_FIELD(ar, "securityAttack_", securityAttack_);
60  SERIALIZE_FIELD(ar, "installedImage_", installedImage_);
61  }
62 #endif // OPCUABRIDGE_ENABLE_SERIALIZATION
63 };
64 } // namespace opcuabridge
65 
66 #endif // OPCUABRIDGE_ECUVERSIONMANIFESTSIGNED_H_