1 | | /* Virginia Tech Cognitive Radio Open Source Systems |
2 | | * Virginia Tech, 2009 |
3 | | * |
4 | | * LICENSE INFORMATION GOES HERE |
| 1 | /* |
| 2 | Copyright 2009 Virginia Polytechnic Institute and State University |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /*! This CE was written to extend the functionality of a basic CBR-based CE for |
| 18 | * use with the OSSIE demonstration. This file contains the implementation for |
| 19 | * both the OSSIE CBR as well as the OSSIE Cognitive Engine. |
7 | | /*! This CE was written to extend the functionality of a basic CBR-based CE for |
8 | | * use with the OSSIE demonstration. |
9 | | */ |
10 | | |
11 | | |
12 | | #include <cmath> |
13 | | #include <cstdlib> |
14 | | #include <cstring> |
15 | | #include <stdint.h> |
16 | | #include <string> |
17 | | |
18 | | #include "vtcross/cbr.h" |
19 | | #include "vtcross/cognitive_engine.h" |
20 | | #include "vtcross/common.h" |
21 | | #include "vtcross/containers.h" |
22 | | #include "vtcross/debug.h" |
23 | | #include "vtcross/error.h" |
24 | | #include "vtcross/socketcomm.h" |
25 | | |
26 | | |
27 | | #define TXPOWER 1 |
28 | | #define BER_ENV 1 |
29 | | #define BER_OBJ 1 |
30 | | |
31 | | #define DECREMENTSCALE 5 |
32 | | #define INCREMENTSCALE 5 |
33 | | |
34 | | #define EVF 20 |
35 | | |
36 | | |
37 | | /* ossieCBR Class |
38 | | * |
39 | | * Derives from the default VTCROSS CBR class to add the following functionality |
40 | | * necessary for the OSSIE demo: |
41 | | * |
42 | | * TODO |
43 | | */ |
44 | | class ossieCBR : public CBR |
45 | | { |
46 | | public: |
47 | | ossieCBR(); |
48 | | |
49 | | ossieCBR(string _filename, string _tablename, string _cols[], uint32_t _len); |
50 | | |
51 | | ~ossieCBR(){}; |
52 | | |
53 | | int32_t Update(string _where[], string _set[], float *_wherevals, float *_setvals, \ |
54 | | unsigned int _wherelen, unsigned int _setlen); |
55 | | |
56 | | int32_t Search(string _names[], int32_t *_ops, float *_vals, uint32_t _n, \ |
57 | | float *_retvals, int32_t evf); |
58 | | }; |
| 22 | |
| 23 | #include "OSSIE_CE.h" |
| 24 | |
| 25 | |
| 26 | using namespace std; |
168 | | class OSSIE_CE : public CognitiveEngine |
169 | | { |
170 | | public: |
171 | | /*! Default constructor. */ |
172 | | OSSIE_CE() : CognitiveEngine(){}; |
173 | | |
174 | | /*! Default destructor. */ |
175 | | ~OSSIE_CE(); |
176 | | |
177 | | /*! \brief Preferred constructor. |
178 | | * |
179 | | * Overloaded constructor that creates a cognitive engine object and |
180 | | * connects it to either the shell or an SML, depening on the SML bool. |
181 | | * |
182 | | * The 'numFields' parameter sets how large the parameter, observable, |
183 | | * and utility arrays should be upon instantiation. |
184 | | */ |
185 | | OSSIE_CE(const char* serverName, const char* serverPort, \ |
186 | | const int32_t numFields, const bool SML) \ |
187 | | : CognitiveEngine(serverName, serverPort, numFields, SML){} |
188 | | |
189 | | |
190 | | void RegisterServices(); |
191 | | void DeregisterServices(); |
192 | | |
193 | | /*! \brief Request that the CE optimize a set of parameters. |
194 | | * |
195 | | * Find the most optimal set of transmission parameters given certain |
196 | | * observables and possibly a service if the SML component is present |
197 | | * and active. */ |
198 | | Parameter *GetSolution(Observable *observables, \ |
199 | | Parameter *currentParameters); |
200 | | Parameter *GetSolution(Observable *observables, \ |
201 | | Parameter *currentParameters, std::string service); |
202 | | |
203 | | /*! \brief Receive feedback from the radio |
204 | | * |
205 | | * Receive a feedback from the radio regarding the performance of a |
206 | | * certain set of parameters, possibly associated with a service. |
207 | | * |
208 | | * Feedback is a single set of performance statistics that is achieved |
209 | | * corresponding to a specific set of transmission parameters. Feedback |
210 | | * helps a Cognitive Engine make better future decisions based upon |
211 | | * more accurate performance statistics. |
212 | | */ |
213 | | void ReceiveFeedback(Observable *observables,Parameter *parameters); |
214 | | void ReceiveFeedback(Observable *observables, Parameter *parameters, \ |
215 | | std::string service); |
216 | | |
217 | | |
218 | | /*! \brief Initialize the CE and prepare it for operation. |
219 | | * |
220 | | * BuildCognitiveEngine performs the CE implementation specific work |
221 | | * that defines the internals of a CE. For example, a CBR CE engine |
222 | | * would build the case-base reasoner or create the database, a neural |
223 | | * network based CE may perform the initial training, a GA based CE |
224 | | * may build the chromosome structure. |
225 | | */ |
226 | | void BuildCognitiveEngine(); |
227 | | |
228 | | /*! \brief Each of these functions responds to a specific command. |
229 | | * |
230 | | * These functions are left principally un-implemented. It is the duty |
231 | | * of child classes to implement these functions, as they define the |
232 | | * cognitive engine's functionality. |
233 | | */ |
234 | | void PerformUpdatePerformance(); |
235 | | void PerformRequestOptimizationService(); |
236 | | void PerformRequestOptimization(); |
237 | | void PerformQueryComponentType(); |
238 | | void PerformConnectSML(); |
239 | | void PerformDisconnectSML(); |
240 | | void PerformResetEngineCognitive(); |
241 | | void PerformShutdownEngineCognitive(); |
242 | | |
243 | | ossieCBR *myCBR; |
244 | | }; |
| 136 | OSSIE_CE::OSSIE_CE(const char* serverName, const char* serverPort, \ |
| 137 | const int32_t numFields, const bool SML) \ |
| 138 | : CognitiveEngine(serverName, serverPort, numFields, SML) |
| 139 | { |
| 140 | BuildCognitiveEngine(); |
| 141 | } |