/****************************************************************** * Sample the piezo port for NSAMPLES. Convert to 0 centered * voltage and sent over UART. Send the string "END" after * all samples are sent. * ******************************************************************/ void stringTestControls::sampleFreq(int strng) { int sensorValue[NSAMPLES]; double sensorValVolts; pluck(strng); //Fill a buffer with sample data for(int i =0; i <NSAMPLES; i++) { sensorValue[i] = analogRead(PIEZOPORT);//100 microseconds // Sampling Rate //delay(2); //472.8Hz //delay(1); //888 Hz //delayMicroseconds(750); //1142.8 Hz delayMicroseconds(700); //1215 Hz //delayMicroseconds(500); //1606 Hz } for(int i =0; i <NSAMPLES; i++) { //Convert the sensorValue to volts and center it at 0 sensorValVolts = (((sensorValue[i]/1023.0)*5.0)-2.5); printDouble(sensorValVolts,1); } Serial.println("END"); }
static void writeDouble(A2PWriter writer, ATermReal real){ double doubleValue = ATgetReal(real); writeByteToBuffer(writer->buffer, PDB_IEEE754_ENCODED_DOUBLE_HEADER); printDouble(writer->buffer, doubleValue); }
void SenMLRecord::fieldsToJson() { int bnLength = this->_name.length(); if(bnLength){ printText("\"n\":\"", 5); printText(this->_name.c_str(), bnLength); printText("\"", 1); } if(!isnan(this->_time)){ printText(",\"t\":", 5); printDouble(this->_time, SENML_MAX_DOUBLE_PRECISION); } if(this->_unit != SENML_UNIT_NONE){ printText(",\"u\":\"", 6); printUnit(this->_unit); printText("\"", 1); } if(this->_updateTime != 0){ printText(",\"ut\":", 5); #ifdef __MBED__ char buf[10]; sprintf(buf, "%d", this->_updateTime); String val = buf; #else String val(this->_updateTime); #endif printText(val.c_str(), val.length()); } }
void printNumTable(){ unsigned int index; puts("****************** NUM_TABLE Start ******************"); for(index=0;index<totalNumConsts;index++){ printf("%d|\t",index);printDouble(numConsts[index]);printf("\n"); } puts("------------------ NUM_TABLE End ------------------"); }
void ReconstructDouble(double d) { double val; //unsigned char *pDouble = (unsigned char *) &val; char *pDouble = (char *) &val; //unsigned char *pD = (unsigned char *) &d; char *pD = (char *) &d; for (int i = 0; i < sizeof(double); ++i) { *pDouble = *pD; *pDouble++; *pD++; } printf("In double %lf, Out double %lf\n", d, val); printDouble(d); printDouble(val); }
/* Main cycle function */ static void main_cycle(void) { float TEMPERATURE_Value; float HUMIDITY_Value; float PRESSURE_Value; float PRESSURE_Temp_Value; AxesRaw_TypeDef MAG_Value; AxesRaw_TypeDef ACC_Value; AxesRaw_TypeDef GYR_Value; char buffer1[32]; char buffer2[32]; char buffer3[32]; char buffer4[32]; unsigned int ret = 0; /* Switch LED On */ myled = LED_ON; printf("===\n"); /* Determine Environmental Values */ ret |= (!CALL_METH(temp_sensor1, GetTemperature, &TEMPERATURE_Value, 0.0f) ? 0x0 : 0x1); ret |= (!CALL_METH(humidity_sensor, GetHumidity, &HUMIDITY_Value, 0.0f) ? 0x0 : 0x2);; ret |= (!CALL_METH(pressure_sensor, GetPressure, &PRESSURE_Value, 0.0f) ? 0x0 : 0x4);; ret |= (!CALL_METH(temp_sensor2, GetFahrenheit, &PRESSURE_Temp_Value, 0.0f) ? 0x0 : 0x8);; ret |= (!CALL_METH(magnetometer, Get_M_Axes, (int32_t *)&MAG_Value, 0) ? 0x0 : 0x10);; ret |= (!CALL_METH(accelerometer, Get_X_Axes, (int32_t *)&ACC_Value, 0) ? 0x0 : 0x20);; ret |= (!CALL_METH(gyroscope, Get_G_Axes, (int32_t *)&GYR_Value, 0) ? 0x0 : 0x40); /* Print Values Out */ printf("I2C [errors]: 0x%.2x X Y Z\n", ret); printf("MAG [mgauss]: %9ld %9ld %9ld\n", MAG_Value.AXIS_X, MAG_Value.AXIS_Y, MAG_Value.AXIS_Z); printf("ACC [mg]: %9ld %9ld %9ld\n", ACC_Value.AXIS_X, ACC_Value.AXIS_Y, ACC_Value.AXIS_Z); printf("GYR [mdps]: %9ld %9ld %9ld\n", GYR_Value.AXIS_X, GYR_Value.AXIS_Y, GYR_Value.AXIS_Z); printf("---\nTEMP | HUMIDITY: %s°C | %s%%\nTEMP | PRESSURE: %s°F | %smbar\n", printDouble(buffer1, TEMPERATURE_Value), printDouble(buffer2, HUMIDITY_Value), printDouble(buffer4, PRESSURE_Temp_Value), printDouble(buffer3, PRESSURE_Value)); /* Switch LED Off */ myled = LED_OFF; }
bool ImplicitList::toString(std::wostringstream& ostr) { ostr << L" "; if (m_eStartType == ScilabDouble) { Double *pD = m_poStart->getAs<Double>(); ostr << printDouble(pD); } else //Polynom { Polynom* pMP = m_poStart->getAs<types::Polynom>(); ostr << printInLinePoly(pMP->get(0), pMP->getVariableName()); } ostr << L":"; if (m_eStepType == ScilabDouble) { Double *pD = m_poStep->getAs<Double>(); ostr << printDouble(pD); } else //Polynom { Polynom* pMP = m_poStep->getAs<types::Polynom>(); ostr << printInLinePoly(pMP->get(0), pMP->getVariableName()); } ostr << L":"; if (m_eEndType == ScilabDouble) { Double *pD = m_poEnd->getAs<Double>(); ostr << printDouble(pD); } else //Polynom { Polynom* pMP = m_poEnd->getAs<types::Polynom>(); ostr << printInLinePoly(pMP->get(0), pMP->getVariableName()); } ostr << std::endl; return true; }
/* 01_anydata (b) * Print the given AnyData value, using one of the above functions */ void printValue(AnyData val) { switch (val.type) { case DOUBLE: printDouble(val.value.dval); break; case INT: printInt(val.value.ival); break; case BYTE: printByte(val.value.bval); break; } }
int main(int, char **) { printf("IsBigEndian: %s\n", (IsBigEndian()) ? "yes" : "no"); printf("IsBigEndian2: %s\n", (IsBigEndian2()) ? "yes" : "no"); printDouble(1.0); printDouble(0.0); printDouble(12345.6789); ReconstructDouble(12345.6789); ReconstructDouble(123401234.567891234); double val = 123401234.567891234; printInt(1); printInt(0x10000); printf("Swap test\n"); printDouble(val); DoSwap(val); printDouble(val); return 0; }
void printVMarg(struct vmarg* arg){ switch(arg->type){ case label_a: printf("00, %d\t",arg->val);break; // label_a case global_a: printf("01, %d:\t",arg->val);printVar(arg->val);break; //global_a case formal_a: printf("02, %d:\t",arg->val);printVar(arg->val);break; //formal_a case local_a: printf("03, %d:\t",arg->val);printVar(arg->val);break; // local_a case number_a: printf("04, %d:\t",arg->val);printDouble(numConsts[arg->val]);break; // number_a case string_a: printf("05, %d:%s\t",arg->val, stringConsts[arg->val]);break; // string_a case bool_a: printf("06, %c\t",arg->val);break; // bool_a case nil_a: /*printf("\t(nil_a)\t");*/break; //nil_a case userfunc_a: printf("08, %d: %s\t",arg->val, userFuncs[arg->val].id);break; // userfunc_a case libfunc_a: printf("09, %d: %s\t",arg->val, namedLibfuncs[arg->val]);break; // libfunc_a case retval_a: printf("10, retval\t");break; // retval_a default: ;//printf("Asserting for arg->val=%d\n",arg->val);assert(0); } }
void SenMLPack::fieldsToJson() { int bnLength = this->_bn.length(); if(bnLength > 0){ printText("\"bn\":\"", 6); printText(this->_bn.c_str(), bnLength); printText("\"", 1); } if(this->_bu){ printText(",\"bu\":\"", 7); printUnit(this->_bu); printText("\"", 1); } if(!isnan(this->_bt)){ printText(",\"bt\":", 6); printDouble(this->_bt, SENML_MAX_DOUBLE_PRECISION); } }
void VDRIVE2::WriteFileData(double* DATA, int columns, bool n) { byte cr = 0x0d; int i=0; String WriteVal; while (i < columns) { //4=size of int String DATA2 = printDouble( DATA[i], 6); WriteVal += DATA2; WriteVal += ", "; i++; } char data[WriteVal.length()+1]; WriteVal.toCharArray(data, WriteVal.length()+1); Serial1.print("WRF "); int Size = WriteVal.length()+2; Serial1.print(Size, DEC); Serial1.write(cr); i = 0; while (i < WriteVal.length()+1) { Serial1.write(data[i]); i++; } Serial1.write(0x0a); //LineFeed Serial1.write(cr); delay(10); digitalWrite(_CTS, LOW); while (Serial1.available() > 0) { if (n == true) { char a = Serial1.read(); if (a == 0x0d) { Serial.println(); } else { Serial.write(a); } } else { Serial1.read(); } } delay(10); digitalWrite(_CTS, HIGH); }
int main (void) { FILE *inputStream = NULL, /* File pointer for input file */ *outputStream = NULL; /* File pointer for output file */ int studentId1 = 0, studentId2 = 0, studentId3 = 0, studentId4 = 0, studentId5 = 0; /* 5 student IDs */ int studentClassStanding1 = 0, studentClassStanding2 = 0, studentClassStanding3 = 0, studentClassStanding4 = 0, studentClassStanding5 = 0; /* 5 student class standings */ double studentGpa1 = 0.0, studentGpa2 = 0.0, studentGpa3 = 0.0, studentGpa4 = 0.0, studentGpa5 = 0.0; /* 5 student GPAs */ double studentAge1 = 0.0, studentAge2 = 0.0, studentAge3 = 0.0, studentAge4 = 0.0, studentAge5 = 0.0; /* 5 student ages */ double sumGpa = 0.0, /* sum of the 5 student's GPA */ sumClassStanding = 0.0, /* sum of the 5 student's class standing */ sumAge = 0.0; /* sum of the 5 student's ages */ double meanGpa = 0.0, /* mean of the 5 student's GPA */ meanClassStanding = 0.0, /* mean of the 5 student's class standing */ meanAge = 0.0; /* mean of the 5 student's ages */ double deviationGpa1 = 0.0, deviationGpa2 = 0.0, deviationGpa3 = 0.0, deviationGpa4 = 0.0, deviationGpa5 = 0.0; /* deviation of each student's GPA */ double varianceGpa = 0.0, /* variance of the 5 student's GPA */ standardDeviationGpa = 0.0, /* standard variance of the 5 student's GPA */ maxStudentGpa = 0.0, /* maximum number out of the 5 student's GPA */ minStudentGpa = 0.0; /* minimum number out of the 5 student's GPA */ /* Opens an input file "input.dat" for reading; */ inputStream = openFileStream (INPUT_FILE, INPUT_FILE_MODE); /* Opens an output file "output.dat" for writing; */ outputStream = openFileStream (OUTPUT_FILE, OUTPUT_FILE_MODE); /* Checks the condition if files were successfully opened. * If either file didn't open, then an error message is prompted, * otherwise program will continue to execute other operations. */ if (inputStream == NULL || outputStream == NULL) { /* Files were not successfully opened and prompts user of the error. * Program will not continue to execute the rest of the program. */ printf ("Error: Not able to open files!\n"); } else { /* Reads five records from the input file (input.dat); */ /* Student 1 */ studentId1 = readInteger (inputStream); studentGpa1 = readDouble (inputStream); studentClassStanding1 = readInteger (inputStream); studentAge1 = readDouble (inputStream); /* Student 2 */ studentId2 = readInteger (inputStream); studentGpa2 = readDouble (inputStream); studentClassStanding2 = readInteger (inputStream); studentAge2 = readDouble (inputStream); /* Student 3 */ studentId3 = readInteger (inputStream); studentGpa3 = readDouble (inputStream); studentClassStanding3 = readInteger (inputStream); studentAge3 = readDouble (inputStream); /* Student 4 */ studentId4 = readInteger (inputStream); studentGpa4 = readDouble (inputStream); studentClassStanding4 = readInteger (inputStream); studentAge4 = readDouble (inputStream); /* Student 5 */ studentId5 = readInteger (inputStream); studentGpa5 = readDouble (inputStream); studentClassStanding5 = readInteger (inputStream); studentAge5 = readDouble (inputStream); /* Calculates the sum of the GPAs; */ sumGpa = calculateSum (studentGpa1, studentGpa2, studentGpa3, studentGpa4, studentGpa5); /* Calculates the sum of the class standings; */ sumClassStanding = calculateSum (studentClassStanding1, studentClassStanding2, studentClassStanding3, studentClassStanding4, studentClassStanding5); /* Calculates the sum of the ages; */ sumAge = calculateSum (studentAge1, studentAge2, studentAge3, studentAge4, studentAge5); /* Calculates the mean of the GPAs; */ meanGpa = calculateMean (sumGpa, NUMBER_OF_STUDENTS); /* Calculates the mean of the class standings; */ meanClassStanding = calculateMean (sumClassStanding, NUMBER_OF_STUDENTS); /* Calculates the mean of the ages; */ meanAge = calculateMean (sumAge, NUMBER_OF_STUDENTS); /* Calculates the deviation of each GPA from the mean */ deviationGpa1 = calculateDeviation (studentGpa1, meanGpa); deviationGpa2 = calculateDeviation (studentGpa2, meanGpa); deviationGpa3 = calculateDeviation (studentGpa3, meanGpa); deviationGpa4 = calculateDeviation (studentGpa4, meanGpa); deviationGpa5 = calculateDeviation (studentGpa5, meanGpa); /* Calculates the variance of the GPAs */ varianceGpa = calculateVariance (deviationGpa1, deviationGpa2, deviationGpa3, deviationGpa4, deviationGpa5, NUMBER_OF_STUDENTS); /* Calculates the standard deviation of the GPAs; */ standardDeviationGpa = calculateStandardDeviation (varianceGpa); /* Determines the min of the GPAs; */ minStudentGpa = findMin (studentGpa1, studentGpa2, studentGpa3, studentGpa4, studentGpa5); /* Determines the max of the GPAs; */ maxStudentGpa = findMax (studentGpa1, studentGpa2, studentGpa3, studentGpa4, studentGpa5); /* Writing the result to the output file (output.dat) */ printDouble (outputStream, meanGpa); printDouble (outputStream, meanClassStanding); printDouble (outputStream, meanAge); printDouble (outputStream, standardDeviationGpa); printDouble (outputStream, minStudentGpa); printDouble (outputStream, maxStudentGpa); /* Closes the input and output files (i.e. input.dat and output.dat) */ closeFileStream (inputStream); closeFileStream (outputStream); } return 0; }
SerialOutput& SerialOutput::operator <<(const float s) { printDouble(s, 5); return *this; }
void Interpreter::executeFun(uint16_t id) { _bc = ((BytecodeFunction*)_code->functionById(id))->bytecode(); _insPtr = 0; Instruction inst; while (true) { inst = nextInsn(); //cout << "Current instruction " << inst << endl; //cout << "__STACK:" << endl; //printStack(); switch (inst) { case BC_INVALID: _out << inst << " Invalid instruction" << endl; assert(false); break; case BC_DLOAD: loadDouble(); break; case BC_ILOAD: loadInt(); break; case BC_SLOAD: loadString(); break; case BC_DLOAD0: _out << inst << " Not implemented" << endl; assert(false); break; case BC_ILOAD0: pushInt(0); break; case BC_SLOAD0: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_DLOAD1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_ILOAD1: pushInt(1); break; case BC_DLOADM1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_ILOADM1: pushInt(-1); break; case BC_DADD: addDoubles(); break; case BC_IADD: addInts(); break; case BC_DSUB: subDoubles(); break; case BC_ISUB: subInts(); break; case BC_DMUL: dMul(); break; case BC_IMUL: iMul(); break; case BC_DDIV: divDoubles(); break; case BC_IDIV: divInts(); break; case BC_IMOD: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_DNEG: dNeg(); break; case BC_INEG: iNeg(); break; case BC_IPRINT: printInt(); break; case BC_DPRINT: printDouble(); break; case BC_SPRINT: printString(); break; case BC_I2D: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_D2I: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_S2I: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_SWAP: swap(); break; case BC_POP: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADDVAR0: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADDVAR1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADDVAR2: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADDVAR3: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADIVAR0: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADIVAR1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADIVAR2: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADIVAR3: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADSVAR0: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADSVAR1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADSVAR2: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADSVAR3: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREDVAR0: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREDVAR1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREDVAR2: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREDVAR3: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREIVAR0: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREIVAR1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREIVAR2: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREIVAR3: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STORESVAR0: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STORESVAR1: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STORESVAR2: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STORESVAR3: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADDVAR: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADIVAR: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADSVAR: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREDVAR: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOREIVAR: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STORESVAR: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_LOADCTXDVAR: loadCtxDouble(); break; case BC_LOADCTXIVAR: loadCtxInt(); break; case BC_LOADCTXSVAR: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STORECTXDVAR: storeCtxDouble(); break; case BC_STORECTXIVAR: storeCtxInt(); break; case BC_STORECTXSVAR: _out << inst << " STORE STRING ? Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_DCMP: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_ICMP: compareInts(); break; case BC_JA: jumpAlways(); break; case BC_IFICMPNE: intsNotEqualJMP(); break; case BC_IFICMPE: intsEqualJMP(); break; case BC_IFICMPG: GJump(); break; case BC_IFICMPGE: GEJump(); break; case BC_IFICMPL: //cout << "IFLESS" << endl; assert(false); break; case BC_IFICMPLE: LEJump(); break; case BC_DUMP: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_STOP: this->popContext(); return; case BC_CALL: //cout << "CALLING. STACK SIZE: " << _stack.size() << endl; call(); break; case BC_CALLNATIVE: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; case BC_RETURN: doReturn(); break; case BC_BREAK: _out << inst << " Not implemented" << endl; exit(EXIT_FAILURE); break; default: _out << "Bad instruction" << endl; break; } } this->popContext(); }
void DoSwap(double val) { SwapDouble(val); printDouble(val); }