00001 #ifndef MESSAGE_HPP 00002 #define MESSAGE_HPP 00003 00004 #include <iostream> 00005 #include <memory> 00006 #include <string> 00007 #include <vector> 00008 #include "ByteVector.hpp" 00009 #include "FirmwareVariants.hpp" 00010 00011 namespace msp { 00012 00013 enum class ID : uint16_t; 00014 00015 class Message { 00016 public: 00021 virtual ID id() const = 0; 00022 00028 Message(FirmwareVariant v) : fw_variant(v) {} 00029 00033 virtual ~Message() {} 00034 00040 void setFirmwareVariant(FirmwareVariant v) { fw_variant = v; } 00041 00046 FirmwareVariant getFirmwareVariant() const { return fw_variant; } 00047 00053 virtual bool decode(const ByteVector& /*data*/) { return false; } 00054 00059 virtual ByteVectorUptr encode() const { return ByteVectorUptr(); } 00060 00061 virtual std::ostream& print(std::ostream& s) const { 00062 s << "Print method for message ID " << uint16_t(id()) 00063 << " is not implemented" << std::endl; 00064 return s; 00065 } 00066 00067 protected: 00068 FirmwareVariant fw_variant; 00069 }; 00070 00071 } // namespace msp 00072 00073 inline std::ostream& operator<<(std::ostream& s, const msp::ID& id) { 00074 s << int(id); 00075 return s; 00076 } 00077 00078 inline std::ostream& operator<<(std::ostream& s, const msp::Message& val) { 00079 return val.print(s); 00080 } 00081 00082 #endif // TYPES_HPP