Export to MBED Studio

Dependencies:   mbed

Committer:
tgrosch
Date:
Sun Oct 25 00:58:24 2020 +0000
Revision:
0:62b846b3988a
First successful compile.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tgrosch 0:62b846b3988a 1 /*!
tgrosch 0:62b846b3988a 2 * \file OPT3101DesignCoefficients.cpp
tgrosch 0:62b846b3988a 3 * \author Karthik Rajagopal <krthik@ti.com>
tgrosch 0:62b846b3988a 4 * \version 0.9.1
tgrosch 0:62b846b3988a 5 *
tgrosch 0:62b846b3988a 6 * \section COPYRIGHT
tgrosch 0:62b846b3988a 7 * TEXAS INSTRUMENTS TEXT FILE LICENSE
tgrosch 0:62b846b3988a 8 * Copyright (c) 2018 Texas Instruments Incorporated
tgrosch 0:62b846b3988a 9 * All rights reserved not granted herein.
tgrosch 0:62b846b3988a 10 * Limited License.
tgrosch 0:62b846b3988a 11 * Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive license under copyrights and patents it now or hereafter owns or controls to make, have made, use, import, offer to sell and sell ("Utilize") this software subject to the terms herein. With respect to the foregoing patent license, such license is granted solely to the extent that any such patent is necessary to Utilize the software alone. The patent license shall not apply to any combinations which include this software, other than combinations with devices manufactured by or for TI ("TI Devices"). No hardware patent is licensed hereunder.
tgrosch 0:62b846b3988a 12 * Redistributions must preserve existing copyright notices and reproduce this license (including the above copyright notice and the disclaimer and (if applicable) source code license limitations below) in the documentation and/or other materials provided with the distribution
tgrosch 0:62b846b3988a 13 * Redistribution and use in binary form, without modification, are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 14 * * No reverse engineering, decompilation, or disassembly of this software is permitted with respect to any software provided in binary form.
tgrosch 0:62b846b3988a 15 * * any redistribution and use are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 16 * * Nothing shall obligate TI to provide you with source code for the software licensed and provided to you in object code.
tgrosch 0:62b846b3988a 17 * If software source code is provided to you, modification and redistribution of the source code are permitted provided that the following conditions are met:
tgrosch 0:62b846b3988a 18 * * any redistribution and use of the source code, including any resulting derivative works, are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 19 * * any redistribution and use of any object code compiled from the source code and any resulting derivative works, are licensed by TI for use only with TI Devices.
tgrosch 0:62b846b3988a 20 * Neither the name of Texas Instruments Incorporated nor the names of its suppliers may be used to endorse or promote products derived from this software without specific prior written permission.
tgrosch 0:62b846b3988a 21 * DISCLAIMER.
tgrosch 0:62b846b3988a 22 * THIS SOFTWARE IS PROVIDED BY TI AND TI'S LICENSORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TI AND TI'S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tgrosch 0:62b846b3988a 23 *
tgrosch 0:62b846b3988a 24 * \section DESCRIPTION
tgrosch 0:62b846b3988a 25 * The file contains methods definitions for classes OPT3101::crosstalkTempCoffC OPT3101::calibrationC OPT3101::phaseAmbientCoffC OPT3101::phaseTempCoffC
tgrosch 0:62b846b3988a 26 */
tgrosch 0:62b846b3988a 27 #include "OPT3101DesignCoefficients.h"
tgrosch 0:62b846b3988a 28 #include <stdlib.h>
tgrosch 0:62b846b3988a 29
tgrosch 0:62b846b3988a 30 OPT3101::crosstalkTempCoffC::crosstalkTempCoffC()
tgrosch 0:62b846b3988a 31 {
tgrosch 0:62b846b3988a 32 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 33 this->coffI = 0.0; ///* Initilizes all the members to 0
tgrosch 0:62b846b3988a 34 this->coffQ = 0.0;
tgrosch 0:62b846b3988a 35 this->coffIReg = 0;
tgrosch 0:62b846b3988a 36 this->coffQReg = 0;
tgrosch 0:62b846b3988a 37 this->commonScale = 0;
tgrosch 0:62b846b3988a 38 }
tgrosch 0:62b846b3988a 39
tgrosch 0:62b846b3988a 40 void OPT3101::crosstalkTempCoffC::calculateCoff(OPT3101::crosstalkC *illumXtalk0, OPT3101::crosstalkC *illumXtalk1)
tgrosch 0:62b846b3988a 41 {
tgrosch 0:62b846b3988a 42 int32_t I[2], Q[2];
tgrosch 0:62b846b3988a 43 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 44 I[0] = ((int32_t)illumXtalk0->I) << illumXtalk0->xtalkScale; ///* Scales the 16bit crosstalk registers OPT3101::crosstalkC::I and OPT3101::crosstalkC::Q to 24 bit level using OPT3101::crosstalkC::xtalkScale
tgrosch 0:62b846b3988a 45 I[1] = ((int32_t)illumXtalk1->I) << illumXtalk1->xtalkScale;
tgrosch 0:62b846b3988a 46 Q[0] = ((int32_t)illumXtalk0->Q) << illumXtalk0->xtalkScale;
tgrosch 0:62b846b3988a 47 Q[1] = ((int32_t)illumXtalk1->Q) << illumXtalk1->xtalkScale;
tgrosch 0:62b846b3988a 48 ///* Makes the data base circular to avoid errorneous high slope measurements
tgrosch 0:62b846b3988a 49 if (I[0] > 6291456 && I[1] < -6291456) // 3/4 of the 24 bit signed range
tgrosch 0:62b846b3988a 50 I[1] += 16777216; //Adding 2**24 to this
tgrosch 0:62b846b3988a 51 if (I[1] > 6291456 && I[0] < -6291456) // 3/4 of the 24 bit signed range
tgrosch 0:62b846b3988a 52 I[0] += 16777216; //Adding 2**24 to this
tgrosch 0:62b846b3988a 53 if (Q[0] > 6291456 && Q[1] < -6291456) // 3/4 of the 24 bit signed range
tgrosch 0:62b846b3988a 54 Q[1] += 16777216; //Adding 2**24 to this
tgrosch 0:62b846b3988a 55 if (Q[1] > 6291456 && Q[0] < -6291456) // 3/4 of the 24 bit signed range
tgrosch 0:62b846b3988a 56 Q[0] += 16777216; //Adding 2**24 to this
tgrosch 0:62b846b3988a 57
tgrosch 0:62b846b3988a 58 //printf("Temp diff is [%d]\n", illumXtalk0->tmain - illumXtalk1->tmain);
tgrosch 0:62b846b3988a 59 if(!((illumXtalk0->tmain - illumXtalk1->tmain)==0)) {
tgrosch 0:62b846b3988a 60 this->coffI = ((double)(I[0] - I[1])) / (illumXtalk0->tmain - illumXtalk1->tmain) / ((illumXtalk0->magnitude() + illumXtalk1->magnitude())/2.0); ///* Calculates the double precision OPT3101::crosstalkTempCoffC::coffI and OPT3101::crosstalkTempCoffC::coffQ by finding difference between 24 bit registers divided by delta OPT3101::crosstalkC::tmain divided by OPT3101::crosstalkC::magnitude()
tgrosch 0:62b846b3988a 61 this->coffQ = ((double)(Q[0] - Q[1])) / (illumXtalk0->tmain - illumXtalk1->tmain) / ((illumXtalk0->magnitude() + illumXtalk1->magnitude())/2.0);
tgrosch 0:62b846b3988a 62 }
tgrosch 0:62b846b3988a 63 else {
tgrosch 0:62b846b3988a 64 this->coffI = 0.0;
tgrosch 0:62b846b3988a 65 this->coffQ = 0.0;
tgrosch 0:62b846b3988a 66 }
tgrosch 0:62b846b3988a 67 ///* <b>Warning:</b> Makes the OPT3101::crosstalkTempCoffC::I and OPT3101::crosstalkTempCoffC::Q 0 if the OPT3101::crosstalkC::tmain are same for both the input arguments
tgrosch 0:62b846b3988a 68 }
tgrosch 0:62b846b3988a 69
tgrosch 0:62b846b3988a 70 void OPT3101::crosstalkTempCoffC::report()
tgrosch 0:62b846b3988a 71 {
tgrosch 0:62b846b3988a 72 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 73 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 74 printf("--------------------------------\n");
tgrosch 0:62b846b3988a 75 printf("Crosstalk Temp Coff Class Report\n");
tgrosch 0:62b846b3988a 76 printf("--------------------------------\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 77 printf("coffI=%4.2f\n", this->coffI);
tgrosch 0:62b846b3988a 78 printf("coffQ=%4.2f\n", this->coffQ);
tgrosch 0:62b846b3988a 79 printf("coffIReg=%d\n", this->coffIReg);
tgrosch 0:62b846b3988a 80 printf("coffQReg=%d\n", this->coffQReg);
tgrosch 0:62b846b3988a 81 printf("commonScale=%d\n", this->commonScale);
tgrosch 0:62b846b3988a 82 printf("--------------------------------\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 83 #endif
tgrosch 0:62b846b3988a 84 }
tgrosch 0:62b846b3988a 85
tgrosch 0:62b846b3988a 86 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 87 void OPT3101::crosstalkTempCoffC::storeToFile(char * fileName)
tgrosch 0:62b846b3988a 88 {
tgrosch 0:62b846b3988a 89 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 90 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 91 std::ofstream ofs(fileName);
tgrosch 0:62b846b3988a 92 ofs << this;
tgrosch 0:62b846b3988a 93 ofs.close(); ///* User needs to implement file storage based on host.
tgrosch 0:62b846b3988a 94 #endif
tgrosch 0:62b846b3988a 95 }
tgrosch 0:62b846b3988a 96 #endif
tgrosch 0:62b846b3988a 97
tgrosch 0:62b846b3988a 98 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 99 void OPT3101::crosstalkTempCoffC::loadFromFile(char * fileName)
tgrosch 0:62b846b3988a 100 {
tgrosch 0:62b846b3988a 101 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 102 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 103 std::ifstream ifs(fileName);
tgrosch 0:62b846b3988a 104 ifs >> this;
tgrosch 0:62b846b3988a 105 ifs.close(); ///* User needs to implement file load/restore based on host.
tgrosch 0:62b846b3988a 106 #endif
tgrosch 0:62b846b3988a 107 }
tgrosch 0:62b846b3988a 108 #endif
tgrosch 0:62b846b3988a 109
tgrosch 0:62b846b3988a 110 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 111 std::ostream & OPT3101::operator<<(std::ostream & os, const crosstalkTempCoffC * data)
tgrosch 0:62b846b3988a 112 {
tgrosch 0:62b846b3988a 113 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 114 os << data->coffI << '\n'; ///* Serializes all the members and returns to the stream
tgrosch 0:62b846b3988a 115 os << data->coffQ << '\n';
tgrosch 0:62b846b3988a 116 os << data->coffIReg << '\n';
tgrosch 0:62b846b3988a 117 os << data->coffQReg << '\n';
tgrosch 0:62b846b3988a 118 os << data->commonScale << '\n';
tgrosch 0:62b846b3988a 119 return os;
tgrosch 0:62b846b3988a 120 }
tgrosch 0:62b846b3988a 121 #endif
tgrosch 0:62b846b3988a 122
tgrosch 0:62b846b3988a 123 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 124 std::istream & OPT3101::operator>>(std::istream & is, crosstalkTempCoffC * data)
tgrosch 0:62b846b3988a 125 {
tgrosch 0:62b846b3988a 126 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 127 is >> data->coffI; ///* Reads from stream and de-serializes all the members
tgrosch 0:62b846b3988a 128 is >> data->coffQ;
tgrosch 0:62b846b3988a 129 is >> data->coffIReg;
tgrosch 0:62b846b3988a 130 is >> data->coffQReg;
tgrosch 0:62b846b3988a 131 is >> data->commonScale;
tgrosch 0:62b846b3988a 132 return is;
tgrosch 0:62b846b3988a 133
tgrosch 0:62b846b3988a 134 }
tgrosch 0:62b846b3988a 135 #endif
tgrosch 0:62b846b3988a 136
tgrosch 0:62b846b3988a 137 OPT3101::phaseTempCoffC::phaseTempCoffC()
tgrosch 0:62b846b3988a 138 {
tgrosch 0:62b846b3988a 139 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 140 this->coff = 0.0; ///* Initializes all members to 0. Sets OPT3101::phaseTempCoffC::istMainCoff to true
tgrosch 0:62b846b3988a 141 this->coffReg = 0;
tgrosch 0:62b846b3988a 142 this->commonScale = 0;
tgrosch 0:62b846b3988a 143 this->istMainCoff = true;
tgrosch 0:62b846b3988a 144 }
tgrosch 0:62b846b3988a 145
tgrosch 0:62b846b3988a 146 void OPT3101::phaseTempCoffC::calculateCoff(OPT3101::frameData *frameData0, OPT3101::frameData *frameData1, bool istMainCoff)
tgrosch 0:62b846b3988a 147 {
tgrosch 0:62b846b3988a 148 int32_t phase[2];
tgrosch 0:62b846b3988a 149
tgrosch 0:62b846b3988a 150 phase[0] = frameData0->phase;
tgrosch 0:62b846b3988a 151 phase[1] = frameData1->phase;
tgrosch 0:62b846b3988a 152 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 153 if (phase[0] > 49152 && phase[1] < 16384) // 3/4 of the 16 unsigned
tgrosch 0:62b846b3988a 154 phase[1] += 65536; //Adding 2**16 to this
tgrosch 0:62b846b3988a 155 if (phase[1] > 49152 && phase[0] < 16384) // 3/4 of the 16 unsigned
tgrosch 0:62b846b3988a 156 phase[0] += 65536; //Adding 2**16 to this
tgrosch 0:62b846b3988a 157 ///* Makes the data base circular to avoid errorneous high slope measurements
tgrosch 0:62b846b3988a 158 this->istMainCoff = istMainCoff; ///* Assigns OPT3101::phaseTempCoffC::istMainCoff to the value assigned by argument
tgrosch 0:62b846b3988a 159 if (istMainCoff)
tgrosch 0:62b846b3988a 160 if (!(frameData0->tmain - frameData1->tmain) == 0)
tgrosch 0:62b846b3988a 161 this->coff = ((double)((int32_t)phase[0] - (int32_t)phase[1])) / (frameData0->tmain - frameData1->tmain); ///* Calculates the double precision OPT3101::phaseTempCoffC::coff by finding difference between OPT3101::frameData::phase divided by delta OPT3101::frameData::tmain or OPT3101::frameData::tillum based on input flag
tgrosch 0:62b846b3988a 162 else
tgrosch 0:62b846b3988a 163 this->coff = 0.0;
tgrosch 0:62b846b3988a 164 else
tgrosch 0:62b846b3988a 165 if (!(frameData0->tillum - frameData1->tillum) == 0)
tgrosch 0:62b846b3988a 166 this->coff = ((double)((int32_t)phase[0] - (int32_t)phase[1])) / (frameData0->tillum - frameData1->tillum);
tgrosch 0:62b846b3988a 167 else
tgrosch 0:62b846b3988a 168 this->coff = 0.0;
tgrosch 0:62b846b3988a 169 ///* <b>Warning:</b> Makes the OPT3101::phaseTempCoffC::coff 0 if the OPT3101::frameData::tmain or OPT3101::frameData::tillum are same for both the input arguments
tgrosch 0:62b846b3988a 170
tgrosch 0:62b846b3988a 171 }
tgrosch 0:62b846b3988a 172
tgrosch 0:62b846b3988a 173 void OPT3101::phaseTempCoffC::report()
tgrosch 0:62b846b3988a 174 {
tgrosch 0:62b846b3988a 175 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 176 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 177 printf("----------------------------\n");
tgrosch 0:62b846b3988a 178 printf("Phase Temp Coff Class Report\n");
tgrosch 0:62b846b3988a 179 printf("----------------------------\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 180 printf("coff=%4.2f\n", this->coff);
tgrosch 0:62b846b3988a 181 printf("coffReg=%d\n", this->coffReg);
tgrosch 0:62b846b3988a 182 printf("commonScale=%d\n", this->commonScale);
tgrosch 0:62b846b3988a 183 printf("----------------------------\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 184 #endif
tgrosch 0:62b846b3988a 185 }
tgrosch 0:62b846b3988a 186
tgrosch 0:62b846b3988a 187
tgrosch 0:62b846b3988a 188 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 189 void OPT3101::phaseTempCoffC::storeToFile(char * fileName)
tgrosch 0:62b846b3988a 190 {
tgrosch 0:62b846b3988a 191 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 192 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 193 std::ofstream ofs(fileName);
tgrosch 0:62b846b3988a 194 ofs << this;
tgrosch 0:62b846b3988a 195 ofs.close(); ///* User needs to implement file storage based on host.
tgrosch 0:62b846b3988a 196 #endif
tgrosch 0:62b846b3988a 197 }
tgrosch 0:62b846b3988a 198 #endif
tgrosch 0:62b846b3988a 199
tgrosch 0:62b846b3988a 200 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 201 void OPT3101::phaseTempCoffC::loadFromFile(char * fileName)
tgrosch 0:62b846b3988a 202 {
tgrosch 0:62b846b3988a 203 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 204 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 205 std::ifstream ifs(fileName);
tgrosch 0:62b846b3988a 206 ifs >> this;
tgrosch 0:62b846b3988a 207 ifs.close(); ///* User needs to implement file load/restore based on host.
tgrosch 0:62b846b3988a 208 #endif
tgrosch 0:62b846b3988a 209 }
tgrosch 0:62b846b3988a 210 #endif
tgrosch 0:62b846b3988a 211
tgrosch 0:62b846b3988a 212 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 213 std::ostream & OPT3101::operator<<(std::ostream & os, const phaseTempCoffC * data)
tgrosch 0:62b846b3988a 214 {
tgrosch 0:62b846b3988a 215 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 216 os << data->coff << '\n'; ///* Serializes all the members and returns to the stream
tgrosch 0:62b846b3988a 217 os << data->coffReg << '\n';
tgrosch 0:62b846b3988a 218 os << data->commonScale << '\n';
tgrosch 0:62b846b3988a 219 os << data->istMainCoff << '\n';
tgrosch 0:62b846b3988a 220 return os;
tgrosch 0:62b846b3988a 221 }
tgrosch 0:62b846b3988a 222 #endif
tgrosch 0:62b846b3988a 223
tgrosch 0:62b846b3988a 224 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 225 std::istream & OPT3101::operator>>(std::istream & is, phaseTempCoffC * data)
tgrosch 0:62b846b3988a 226 {
tgrosch 0:62b846b3988a 227 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 228 is >> data->coff; ///* Reads from stream and de-serializes all the members
tgrosch 0:62b846b3988a 229 is >> data->coffReg;
tgrosch 0:62b846b3988a 230 is >> data->commonScale;
tgrosch 0:62b846b3988a 231 is >> data->istMainCoff;
tgrosch 0:62b846b3988a 232 return is;
tgrosch 0:62b846b3988a 233 }
tgrosch 0:62b846b3988a 234 #endif
tgrosch 0:62b846b3988a 235
tgrosch 0:62b846b3988a 236 OPT3101::phaseAmbientCoffC::phaseAmbientCoffC()
tgrosch 0:62b846b3988a 237 {
tgrosch 0:62b846b3988a 238 uint8_t c0;
tgrosch 0:62b846b3988a 239 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 240 for (c0 = 0; c0 < 4; c0++)
tgrosch 0:62b846b3988a 241 this->coff[c0] = 0; ///* Serializes all the members and returns to the stream
tgrosch 0:62b846b3988a 242 for (c0 = 0; c0<4; c0++)
tgrosch 0:62b846b3988a 243 this->coffReg[c0] = 0;
tgrosch 0:62b846b3988a 244 for (c0 = 0; c0 < 3; c0++)
tgrosch 0:62b846b3988a 245 this->splitsReg[c0] = 0;
tgrosch 0:62b846b3988a 246 this->commonScale = 0;
tgrosch 0:62b846b3988a 247 }
tgrosch 0:62b846b3988a 248
tgrosch 0:62b846b3988a 249 void OPT3101::phaseAmbientCoffC::calculateCoff(uint16_t freqCount)
tgrosch 0:62b846b3988a 250 {
tgrosch 0:62b846b3988a 251 uint8_t c0;
tgrosch 0:62b846b3988a 252 uint8_t scaleCoff;
tgrosch 0:62b846b3988a 253
tgrosch 0:62b846b3988a 254 double maxCoff=-1;
tgrosch 0:62b846b3988a 255 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 256 for(c0=1;c0<4;c0++)
tgrosch 0:62b846b3988a 257 maxCoff = abs(this->coff[c0]) > maxCoff ? abs(this->coff[c0]) : maxCoff; ///* Identifies max of absolute of OPT3101::phaseAmbientCoffC::coff values
tgrosch 0:62b846b3988a 258
tgrosch 0:62b846b3988a 259 maxCoff *= 16384 / freqCount; ///* scales the max coefficient with input frequencyCount
tgrosch 0:62b846b3988a 260 scaleCoff = 0;
tgrosch 0:62b846b3988a 261 for (c0 = 0; c0 < 8; c0++) {
tgrosch 0:62b846b3988a 262 scaleCoff = (maxCoff*(1 << (c0 + 2))) < (1 << 7) ? c0 : scaleCoff; ///* Finds a OPT3101::phaseAmbientCoffC::commonScale which can fit the OPT3101::phaseAmbientCoffC::coff to 8 bit registers
tgrosch 0:62b846b3988a 263 }
tgrosch 0:62b846b3988a 264 this->commonScale = scaleCoff;
tgrosch 0:62b846b3988a 265 for (c0 = 0; c0 < 4; c0++)
tgrosch 0:62b846b3988a 266 this->coffReg[c0] = (uint8_t) (16384.0 / freqCount * this->coff[c0]*(1 << (this->commonScale+2))); ///* Finds OPT3101::phaseAmbientCoffC::coffReg values (8 bit register values) based on OPT3101::phaseAmbientCoffC::coff and OPT3101::phaseAmbientCoffC::commonScale
tgrosch 0:62b846b3988a 267 }
tgrosch 0:62b846b3988a 268
tgrosch 0:62b846b3988a 269 void OPT3101::phaseAmbientCoffC::report()
tgrosch 0:62b846b3988a 270 {
tgrosch 0:62b846b3988a 271 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 272 uint8_t c0;
tgrosch 0:62b846b3988a 273 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 274 printf("-------------------------------\n");
tgrosch 0:62b846b3988a 275 printf("Phase Ambient Coff Class Report\n");
tgrosch 0:62b846b3988a 276 printf("-------------------------------\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 277 for(c0=0;c0<4;c0++)
tgrosch 0:62b846b3988a 278 printf("coff[%d]=%4.2f\n", c0,this->coff[c0]);
tgrosch 0:62b846b3988a 279 for (c0 = 0; c0<4; c0++)
tgrosch 0:62b846b3988a 280 printf("coffReg[%d]=%d\n", c0, this->coffReg[c0]);
tgrosch 0:62b846b3988a 281 for (c0 = 0; c0<3; c0++)
tgrosch 0:62b846b3988a 282 printf("splitsReg[%d]=%d\n", c0, this->splitsReg[c0]);
tgrosch 0:62b846b3988a 283 printf("commonScale=%d\n", this->commonScale);
tgrosch 0:62b846b3988a 284 printf("-------------------------------\n"); ///* Prints all the members and values of members on screen.
tgrosch 0:62b846b3988a 285 #endif
tgrosch 0:62b846b3988a 286 }
tgrosch 0:62b846b3988a 287
tgrosch 0:62b846b3988a 288 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 289 void OPT3101::phaseAmbientCoffC::storeToFile(char * fileName)
tgrosch 0:62b846b3988a 290 {
tgrosch 0:62b846b3988a 291 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 292 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 293 std::ofstream ofs(fileName);
tgrosch 0:62b846b3988a 294 ofs << this;
tgrosch 0:62b846b3988a 295 ofs.close(); ///* User needs to implement file storage based on host.
tgrosch 0:62b846b3988a 296 #endif
tgrosch 0:62b846b3988a 297 }
tgrosch 0:62b846b3988a 298 #endif
tgrosch 0:62b846b3988a 299
tgrosch 0:62b846b3988a 300 #ifdef OPT3101_USE_STDIOLIB
tgrosch 0:62b846b3988a 301 void OPT3101::phaseAmbientCoffC::loadFromFile(char * fileName)
tgrosch 0:62b846b3988a 302 {
tgrosch 0:62b846b3988a 303 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 304 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 305 std::ifstream ifs(fileName);
tgrosch 0:62b846b3988a 306 ifs >> this;
tgrosch 0:62b846b3988a 307 ifs.close(); ///* User needs to implement file load/restore based on host.
tgrosch 0:62b846b3988a 308 #endif
tgrosch 0:62b846b3988a 309 }
tgrosch 0:62b846b3988a 310 #endif
tgrosch 0:62b846b3988a 311
tgrosch 0:62b846b3988a 312 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 313 std::ostream & OPT3101::operator<<(std::ostream & os, const phaseAmbientCoffC * data)
tgrosch 0:62b846b3988a 314 {
tgrosch 0:62b846b3988a 315 uint8_t c0;
tgrosch 0:62b846b3988a 316 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 317
tgrosch 0:62b846b3988a 318 for(c0=0;c0<4;c0++)
tgrosch 0:62b846b3988a 319 os << data->coff[c0] << '\n'; ///* Serializes all the members and returns to the stream
tgrosch 0:62b846b3988a 320 for (c0 = 0; c0<4; c0++)
tgrosch 0:62b846b3988a 321 os << data->coffReg[c0] << '\n';
tgrosch 0:62b846b3988a 322 for (c0 = 0; c0<3; c0++)
tgrosch 0:62b846b3988a 323 os << data->splitsReg[c0] << '\n';
tgrosch 0:62b846b3988a 324 os << data->commonScale << '\n';
tgrosch 0:62b846b3988a 325
tgrosch 0:62b846b3988a 326 return os;
tgrosch 0:62b846b3988a 327 }
tgrosch 0:62b846b3988a 328 #endif
tgrosch 0:62b846b3988a 329
tgrosch 0:62b846b3988a 330 #ifdef OPT3101_USE_STREAMLIB
tgrosch 0:62b846b3988a 331 std::istream & OPT3101::operator>>(std::istream & is, phaseAmbientCoffC * data)
tgrosch 0:62b846b3988a 332 {
tgrosch 0:62b846b3988a 333 /// <b>Algorithm of the method is as follows</b>
tgrosch 0:62b846b3988a 334 uint8_t c0;
tgrosch 0:62b846b3988a 335 for (c0 = 0; c0 < 4; c0++) ///* Reads from stream and de-serializes all the members
tgrosch 0:62b846b3988a 336 is >> data->coff[c0];
tgrosch 0:62b846b3988a 337 for (c0 = 0; c0 < 4; c0++)
tgrosch 0:62b846b3988a 338 is >> data->coffReg[c0];
tgrosch 0:62b846b3988a 339 for (c0 = 0; c0 < 3; c0++)
tgrosch 0:62b846b3988a 340 is >> data->splitsReg[c0];
tgrosch 0:62b846b3988a 341 is >> data->commonScale;
tgrosch 0:62b846b3988a 342
tgrosch 0:62b846b3988a 343 return is;
tgrosch 0:62b846b3988a 344
tgrosch 0:62b846b3988a 345 }
tgrosch 0:62b846b3988a 346 #endif
tgrosch 0:62b846b3988a 347
tgrosch 0:62b846b3988a 348