1*c33452fbSAndroid Build Coastguard Worker /*
2*c33452fbSAndroid Build Coastguard Worker  * Copyright (c) 2011-2015, Intel Corporation
3*c33452fbSAndroid Build Coastguard Worker  * All rights reserved.
4*c33452fbSAndroid Build Coastguard Worker  *
5*c33452fbSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without modification,
6*c33452fbSAndroid Build Coastguard Worker  * are permitted provided that the following conditions are met:
7*c33452fbSAndroid Build Coastguard Worker  *
8*c33452fbSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright notice, this
9*c33452fbSAndroid Build Coastguard Worker  * list of conditions and the following disclaimer.
10*c33452fbSAndroid Build Coastguard Worker  *
11*c33452fbSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright notice,
12*c33452fbSAndroid Build Coastguard Worker  * this list of conditions and the following disclaimer in the documentation and/or
13*c33452fbSAndroid Build Coastguard Worker  * other materials provided with the distribution.
14*c33452fbSAndroid Build Coastguard Worker  *
15*c33452fbSAndroid Build Coastguard Worker  * 3. Neither the name of the copyright holder nor the names of its contributors
16*c33452fbSAndroid Build Coastguard Worker  * may be used to endorse or promote products derived from this software without
17*c33452fbSAndroid Build Coastguard Worker  * specific prior written permission.
18*c33452fbSAndroid Build Coastguard Worker  *
19*c33452fbSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20*c33452fbSAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21*c33452fbSAndroid Build Coastguard Worker  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22*c33452fbSAndroid Build Coastguard Worker  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23*c33452fbSAndroid Build Coastguard Worker  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24*c33452fbSAndroid Build Coastguard Worker  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25*c33452fbSAndroid Build Coastguard Worker  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26*c33452fbSAndroid Build Coastguard Worker  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*c33452fbSAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28*c33452fbSAndroid Build Coastguard Worker  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*c33452fbSAndroid Build Coastguard Worker  */
30*c33452fbSAndroid Build Coastguard Worker #include <fstream>
31*c33452fbSAndroid Build Coastguard Worker #include <string>
32*c33452fbSAndroid Build Coastguard Worker #include <sstream>
33*c33452fbSAndroid Build Coastguard Worker #include <cstdlib>
34*c33452fbSAndroid Build Coastguard Worker #include <cassert>
35*c33452fbSAndroid Build Coastguard Worker #include <iostream>
36*c33452fbSAndroid Build Coastguard Worker #include "ParameterType.h"
37*c33452fbSAndroid Build Coastguard Worker #include "MappingContext.h"
38*c33452fbSAndroid Build Coastguard Worker #include "SkeletonMappingKeys.h"
39*c33452fbSAndroid Build Coastguard Worker #include "InstanceConfigurableElement.h"
40*c33452fbSAndroid Build Coastguard Worker #include "SkeletonSubsystemObject.h"
41*c33452fbSAndroid Build Coastguard Worker 
42*c33452fbSAndroid Build Coastguard Worker #define STR_FORMAT_LENGTH 32
43*c33452fbSAndroid Build Coastguard Worker 
44*c33452fbSAndroid Build Coastguard Worker #define base CFormattedSubsystemObject
45*c33452fbSAndroid Build Coastguard Worker 
46*c33452fbSAndroid Build Coastguard Worker using std::string;
47*c33452fbSAndroid Build Coastguard Worker 
CSkeletonSubsystemObject(const string & strMappingValue,CInstanceConfigurableElement * pInstanceConfigurableElement,const CMappingContext & context,core::log::Logger & logger)48*c33452fbSAndroid Build Coastguard Worker CSkeletonSubsystemObject::CSkeletonSubsystemObject(
49*c33452fbSAndroid Build Coastguard Worker     const string &strMappingValue, CInstanceConfigurableElement *pInstanceConfigurableElement,
50*c33452fbSAndroid Build Coastguard Worker     const CMappingContext &context, core::log::Logger &logger)
51*c33452fbSAndroid Build Coastguard Worker     : base(pInstanceConfigurableElement, logger, strMappingValue, EAmend1, EAmendEnd - EAmend1 + 1,
52*c33452fbSAndroid Build Coastguard Worker            context),
53*c33452fbSAndroid Build Coastguard Worker       _bWrongElementTypeError(false)
54*c33452fbSAndroid Build Coastguard Worker {
55*c33452fbSAndroid Build Coastguard Worker     // Get actual element type
56*c33452fbSAndroid Build Coastguard Worker     const CParameterType *pParameterType =
57*c33452fbSAndroid Build Coastguard Worker         static_cast<const CParameterType *>(pInstanceConfigurableElement->getTypeElement());
58*c33452fbSAndroid Build Coastguard Worker 
59*c33452fbSAndroid Build Coastguard Worker     // Retrieve sizes
60*c33452fbSAndroid Build Coastguard Worker     _scalarSize = pParameterType->getSize();
61*c33452fbSAndroid Build Coastguard Worker     _arraySize = pInstanceConfigurableElement->getFootPrint() / _scalarSize;
62*c33452fbSAndroid Build Coastguard Worker 
63*c33452fbSAndroid Build Coastguard Worker     // Construct message
64*c33452fbSAndroid Build Coastguard Worker     _strMessage = context.getItem(ESkeletonOwner) + ":" + strMappingValue;
65*c33452fbSAndroid Build Coastguard Worker 
66*c33452fbSAndroid Build Coastguard Worker     // Handle types
67*c33452fbSAndroid Build Coastguard Worker     // Check we are able to handle elements (no exception support, defer the error)
68*c33452fbSAndroid Build Coastguard Worker     switch (pInstanceConfigurableElement->getType()) {
69*c33452fbSAndroid Build Coastguard Worker 
70*c33452fbSAndroid Build Coastguard Worker     case CInstanceConfigurableElement::EParameter:
71*c33452fbSAndroid Build Coastguard Worker         break;
72*c33452fbSAndroid Build Coastguard Worker     default:
73*c33452fbSAndroid Build Coastguard Worker         _bWrongElementTypeError = true;
74*c33452fbSAndroid Build Coastguard Worker         break;
75*c33452fbSAndroid Build Coastguard Worker     }
76*c33452fbSAndroid Build Coastguard Worker }
77*c33452fbSAndroid Build Coastguard Worker // Sync to/from HW
accessHW(bool bReceive,string & strError)78*c33452fbSAndroid Build Coastguard Worker bool CSkeletonSubsystemObject::accessHW(bool bReceive, string &strError)
79*c33452fbSAndroid Build Coastguard Worker {
80*c33452fbSAndroid Build Coastguard Worker     // Check parameter type is ok (deferred error, no exceptions available :-()
81*c33452fbSAndroid Build Coastguard Worker     if (_bWrongElementTypeError) {
82*c33452fbSAndroid Build Coastguard Worker 
83*c33452fbSAndroid Build Coastguard Worker         strError = "Unsupported parameter type";
84*c33452fbSAndroid Build Coastguard Worker 
85*c33452fbSAndroid Build Coastguard Worker         return false;
86*c33452fbSAndroid Build Coastguard Worker     }
87*c33452fbSAndroid Build Coastguard Worker 
88*c33452fbSAndroid Build Coastguard Worker     return base::accessHW(bReceive, strError);
89*c33452fbSAndroid Build Coastguard Worker }
90*c33452fbSAndroid Build Coastguard Worker 
sendToHW(string &)91*c33452fbSAndroid Build Coastguard Worker bool CSkeletonSubsystemObject::sendToHW(string & /*strError*/)
92*c33452fbSAndroid Build Coastguard Worker {
93*c33452fbSAndroid Build Coastguard Worker     void *pvValue = alloca(_scalarSize);
94*c33452fbSAndroid Build Coastguard Worker 
95*c33452fbSAndroid Build Coastguard Worker     for (size_t index = 0; index < _arraySize; index++) {
96*c33452fbSAndroid Build Coastguard Worker 
97*c33452fbSAndroid Build Coastguard Worker         // Read Value in BlackBoard
98*c33452fbSAndroid Build Coastguard Worker         blackboardRead(pvValue, _scalarSize);
99*c33452fbSAndroid Build Coastguard Worker 
100*c33452fbSAndroid Build Coastguard Worker         // Send here the value
101*c33452fbSAndroid Build Coastguard Worker         std::cout << "Sending to HW: " << _strMessage << std::endl;
102*c33452fbSAndroid Build Coastguard Worker     }
103*c33452fbSAndroid Build Coastguard Worker 
104*c33452fbSAndroid Build Coastguard Worker     return true;
105*c33452fbSAndroid Build Coastguard Worker }
106*c33452fbSAndroid Build Coastguard Worker 
receiveFromHW(string &)107*c33452fbSAndroid Build Coastguard Worker bool CSkeletonSubsystemObject::receiveFromHW(string & /*strError*/)
108*c33452fbSAndroid Build Coastguard Worker {
109*c33452fbSAndroid Build Coastguard Worker     void *pvValue = alloca(_scalarSize);
110*c33452fbSAndroid Build Coastguard Worker 
111*c33452fbSAndroid Build Coastguard Worker     for (size_t index = 0; index < _arraySize; index++) {
112*c33452fbSAndroid Build Coastguard Worker 
113*c33452fbSAndroid Build Coastguard Worker         // Retreive here the value
114*c33452fbSAndroid Build Coastguard Worker         std::cout << "Retreive from HW: " << _strMessage << std::endl;
115*c33452fbSAndroid Build Coastguard Worker 
116*c33452fbSAndroid Build Coastguard Worker         // Write Value in Blackboard
117*c33452fbSAndroid Build Coastguard Worker         blackboardWrite(pvValue, _scalarSize);
118*c33452fbSAndroid Build Coastguard Worker     }
119*c33452fbSAndroid Build Coastguard Worker 
120*c33452fbSAndroid Build Coastguard Worker     return true;
121*c33452fbSAndroid Build Coastguard Worker }
122