BlackCore.h
Go to the documentation of this file.
1  /*
2 
3  ####################################################################################
4  # BlackLib Library controls Beaglebone Black's inputs and outputs. #
5  # Copyright (C) 2013-2015 by Yigit YUCE #
6  ####################################################################################
7  # #
8  # This file is part of BlackLib library. #
9  # #
10  # BlackLib library is free software: you can redistribute it and/or modify #
11  # it under the terms of the GNU Lesser General Public License as published by #
12  # the Free Software Foundation, either version 3 of the License, or #
13  # (at your option) any later version. #
14  # #
15  # BlackLib library is distributed in the hope that it will be useful, #
16  # but WITHOUT ANY WARRANTY; without even the implied warranty of #
17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18  # GNU Lesser General Public License for more details. #
19  # #
20  # You should have received a copy of the GNU Lesser General Public License #
21  # along with this program. If not, see <http://www.gnu.org/licenses/>. #
22  # #
23  # For any comment or suggestion please contact the creator of BlackLib Library #
24  # at ygtyce@gmail.com #
25  # #
26  ####################################################################################
27 
28  */
29 
30 
31 #ifndef BLACKCORE_H_
32 #define BLACKCORE_H_
33 
34 
35 #include "BlackErr.h" // Black Errors header file
36 #include "BlackDef.h" // Black Definitions header file
37 
38 
39 #include <cstring>
40 #include <string>
41 #include <sstream> // need for tostr() function
42 #include <cstdio> // need for popen() function in BlackCore::executeShellCmd()
43 #include <dirent.h> // need for dirent struct in BlackCore::searchDirectory()
44 
45 
46 
47 
48 
49 
50 
51 
52 namespace BlackLib
53 {
54 
60  template <typename T>
61  inline std::string tostr(const T& t)
62  {
63  std::ostringstream os;
64  os << t;
65  return os.str();
66  }
67 
68 
69 
70 
71 
72  // ########################################### BLACKCORE DECLARATION STARTS ########################################### //
73 
80  class BlackCore
81  {
82  private:
84  std::string capeMgrName;
85  std::string ocpName;
86  std::string slotsFilePath;
95  bool findCapeMgrName();
96 
104  bool findOcpName();
105 
113  std::string executeCommand(std::string command);
114 
121  std::string searchDirectory(std::string searchIn, std::string searchThis);
122 
125  virtual bool loadDeviceTree() = 0;
126 
127 
128 
129  protected:
130 
134  enum ocpSearch { ADC_helper = 0,
135  PWM_P8_13 = 1,
136  PWM_P8_19 = 2,
137  PWM_P9_14 = 3,
138  PWM_P9_16 = 4,
139  PWM_P9_21 = 5,
140  PWM_P9_22 = 6,
141  PWM_P9_42 = 7,
142  SPI0 = 8,
143  SPI1 = 9
144  };
145 
152  std::string searchDirectoryOcp(BlackCore::ocpSearch searchThis);
153 
159 
164  std::string getCapeMgrName();
165 
170  std::string getOcpName();
171 
176  std::string getSlotsFilePath();
177 
178 
179 
180  public:
187  BlackCore();
188 
193  virtual ~BlackCore();
194 
195  };
196  // ############################################ BLACKCORE DECLARATION ENDS ############################################ //
197 
198 
199 } /* namespace BlackLib */
200 
201 #endif /* BLACKCORE_H_ */
Definition: BlackCore.h:140
virtual ~BlackCore()
Destructor of BlackCore class.
Definition: BlackCore.cpp:51
std::string ocpName
is used to hold the ocp name
Definition: BlackCore.h:85
bool findCapeMgrName()
Finds full name of capemgr directory.
Definition: BlackCore.cpp:108
std::string tostr(const T &t)
Uses for converting the different types variable to string type.
Definition: BlackCore.h:61
Definition: BlackCore.h:143
BlackCore()
Constructor of BlackCore class.
Definition: BlackCore.cpp:42
Definition: BlackCore.h:141
Definition: BlackCore.h:134
virtual bool loadDeviceTree()=0
First declaration of this function.
Holds BlackCore errors.
Definition: BlackErr.h:47
bool findOcpName()
Finds full name of ocp directory.
Definition: BlackCore.cpp:126
Definition: BlackCore.h:136
std::string executeCommand(std::string command)
Executes system call.
Definition: BlackCore.cpp:56
std::string slotsFilePath
is used to hold the slots file path
Definition: BlackCore.h:86
ocpSearch
Definition: BlackCore.h:134
Definition: BlackCore.h:138
std::string searchDirectory(std::string searchIn, std::string searchThis)
Searches specified directory to find specified file/directory.
Definition: BlackCore.cpp:79
std::string searchDirectoryOcp(BlackCore::ocpSearch searchThis)
Searches ocp directory to find specified file/directory.
Definition: BlackCore.cpp:147
std::string capeMgrName
is used to hold the capemgr name
Definition: BlackCore.h:84
errorCore * coreErrors
is used to hold the errors of BlackCore class
Definition: BlackCore.h:83
Definition: BlackCore.h:139
std::string getOcpName()
Exports ocp name to derived class.
Definition: BlackCore.cpp:241
Definition: BlackCore.h:135
Definition: BlackCore.h:142
Definition: BlackCore.h:137
errorCore * getErrorsFromCore()
Exports errorCore struct to derived class.
Definition: BlackCore.cpp:229
Definition: BlackADC.cpp:36
std::string getCapeMgrName()
Exports capemgr name to derived class.
Definition: BlackCore.cpp:236
std::string getSlotsFilePath()
Exports slots file path to derived class.
Definition: BlackCore.cpp:246
Base class of the other classes.
Definition: BlackCore.h:80