ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
ArduinoDevice.hpp
1 /*
2  * Copyright 2021 Marcus Behel
3  *
4  * This file is part of ArPiRobot-CoreLib.
5  *
6  * ArPiRobot-CoreLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * ArPiRobot-CoreLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with ArPiRobot-CoreLib. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <arpirobot/arduino/iface/BaseArduinoInterface.hpp>
23 
24 #include <string>
25 #include <vector>
26 
27 namespace arpirobot{
28 
36  public:
37 
43  ArduinoDevice(bool createDevice, int deviceId);
44 
45  virtual ~ArduinoDevice() = default;
46 
50  virtual std::string getDeviceName();
51 
52  protected:
53  static std::vector<uint8_t> stringToData(const std::string &str);
54 
55  void setArduino(BaseArduinoInterface *arduino);
56  void setDeviceId(int deviceId);
57 
58  bool sendData(const std::vector<uint8_t> &data);
59  bool sendData(const std::string &data);
60 
61  // Device specific
62  virtual void applyDefaultState() = 0;
63  virtual std::vector<uint8_t> getCreateData() = 0;
64  virtual void handleData(const std::vector<uint8_t> &data) = 0;
65 
66  bool createDevice;
67  int deviceId;
68 
69  std::string deviceName;
70 
71  // Not a shared_ptr because this is set and cleared by the managing ArduinoInterface
72  // This should not keep an ArduinoInterface in scope. The interface keeps devices
73  // in scope. When interface goes out of scope, devices can as well;
74  BaseArduinoInterface *arduino = nullptr;
75 
76  friend class BaseArduinoInterface;
77  };
78 }
Definition: ArduinoDevice.hpp:35
ArduinoDevice(bool createDevice, int deviceId)
virtual std::string getDeviceName()
Definition: BaseArduinoInterface.hpp:41
Definition: ArduinoDevice.hpp:27