/* * TfAbstractDevice.h * * Created on: 12.06.2014 * Author: matzman */ #ifndef TFABSTRACTDEVICE_H_ #define TFABSTRACTDEVICE_H_ #include #include #include #include #include #include namespace tfcppsimple { class TfConnection; class TfDevice; enum class TfDevicePosition : char { //'0' - '8' (Position in Stapel). Für Bricklets: 'a' - 'd' (Position an Brick). BRICK0 = '0', BRICK1 = '1', BRICK2 = '2', BRICK3 = '3', BRICK4 = '4', BRICK5 = '5', BRICK6 = '6', BRICK7 = '7', BRICK8 = '8', BRICKLET0 = 'a', BRICKLET1 = 'b', BRICKLET2 = 'c', BRICKLET3 = 'd', }; enum class TfDeviceIdentifier : uint16_t { UNKNOWN = 0, UNKNOWN_BRICK = 0, UNKNOWN_BRICKLET = 0, MASTER = 13, LCD20x4 = 212, HUMIDITY = 27, IO16 = 28, TEMPERATURE = 216 }; enum class TfDeviceType : int { UNKNOWN = 0, BRICK = 1, BRICKLET = 2 }; enum class TfDeviceState : int { UNKNOWN, AVAILABLE, CONNECTED, DISCONNECTED, CONNECTION_LOST }; struct TfVersion { uint8_t _major; uint8_t _minor; uint8_t _release; } __attribute__((packed)); class TfDeviceStateListener { public: virtual ~TfDeviceStateListener() {} virtual void stateChangeCallback(TfDevice& device, TfDeviceState oldstate, TfDeviceState newstate) {} virtual void shutdownCallback(TfDevice& device) {} }; class TfDevice : public ObservableTemplate { friend class TfDeviceFactory; friend class TfConnection; public: protected: static log4cpp::Category& logger; TfConnection& connection; std::string uid; std::string connected_uid; TfDevicePosition position; TfVersion hardware_version; TfVersion firmware_version; uint16_t raw_device_identifier; TfDeviceIdentifier device_identifier; TfDevice* parent; std::map children; TfDeviceType deviceType; TfDeviceState state = TfDeviceState::UNKNOWN; bool configuredFlag = false; TfDevice(TfConnection& connection, std::string uid, std::string connected_uid, TfDevicePosition position, TfVersion hardware_version, TfVersion firmware_version, uint16_t raw_device_identifier, TfDeviceIdentifier device_identifier, TfDevice* parent, TfDeviceType deviceType ); virtual bool changeDeviceState(TfDeviceState newstate); virtual void doConfigureDevice(); virtual void doReconfigureDevice(); virtual void doUnconfigureDevice(); virtual void doConnectionLost(); virtual void doShutdown(); void signalEnumerationCallback(TfCallbackEnumerationType enumeration_type); void signalConnectedCallback(TfCallbackConnectReason connect_reason); void signalDisconnectedCallback(TfCallbackDisconnectReason disconnect_reason); void signalShutdown(); public: virtual ~TfDevice(); bool connect(); bool disconnect(); const std::string& getConnectedUid() { return connected_uid; } TfDeviceIdentifier getDeviceIdentifier() { return device_identifier; } const TfVersion& getFirmwareVersion() { return firmware_version; } const TfVersion& getHardwareVersion() { return hardware_version; } TfDevicePosition getPosition() { return position; } uint16_t getRawDeviceIdentifier() { return raw_device_identifier; } const std::string& getUid() { return uid; } const std::map& getChildren() { return children; } TfDevice* getChild(TfDevicePosition pos) { auto ret = children.find(pos); return ret == children.end() ? nullptr : ret->second; } TfDevice* getParent() { return parent; } TfDeviceType getDeviceType() { return deviceType; } TfConnection& getConnection() { return connection; } TfDeviceState getDeviceState() { return state; } bool isConfigured() { return configuredFlag; } virtual std::string getDeviceName(bool extended = true); }; } /* namespace tfcppsimple */ #endif /* TFABSTRACTDEVICE_H_ */