Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
presens.cpp
00001 #include "cisme.h" 00002 #include "presens.h" 00003 #include "OxygenSensor.h" 00004 #include "debug.h" 00005 #include "adc.h" 00006 #include "SerialBuffered.h" 00007 00008 /* Due to unknown reason in old version presens was 6 symbol long. */ 00009 //#define PRESENS_FLOAT_LENGTH 6 00010 #define PRESENS_BUFFER_LENGTH 32 00011 00012 //static int writeIx; 00013 //static int readIx; 00014 //static uint8_t Presens_Buffer[PRESENS_BUFFER_LENGTH]; 00015 00016 //Serial presenseComm(p9,p10); 00017 SerialBuffered presenseComm(100, p9, p10); 00018 00019 00020 static float presensReadFloat(int PRESENS_FLOAT_LENGTH) 00021 { 00022 00023 char buf[PRESENS_FLOAT_LENGTH]; 00024 for(int i=0;i<PRESENS_FLOAT_LENGTH;i++){ 00025 buf[i]='0'; 00026 } 00027 char charIx = 0; 00028 00029 while (charIx < PRESENS_FLOAT_LENGTH) { 00030 buf[charIx++] = presenseComm.getc(); 00031 } 00032 DEBUG1("received %s",buf); 00033 00034 return atof(buf); 00035 } 00036 00037 void presensInit(void) 00038 { 00039 //set the baud rate for the PreSense 00040 presenseComm.baud(PRESENS_BAUD); 00041 //set the Serial parameters for the PreSense 00042 presenseComm.format(PRESENS_NO_BITS, PRESENS_PARITY, PRESENS_NO_STOP_BITS); 00043 //presenseComm.baud( PRESENS_BAUD ); 00044 //presenseComm ->format(7,serialStream->Even,1); 00045 presenseComm.setTimeout( 0.1 ); 00046 00047 00048 wait(PRESENS_CONFIG_DELAY); 00049 } 00050 00051 void presensConfig(float ledCurrent) 00052 { 00053 wait(PRESENS_CONFIG_DELAY); 00054 00055 presenseComm.printf(""); 00056 00057 if (ledCurrent > 255 || ledCurrent < 0) { 00058 ERROR("Too big ledCurrent=%f, it should be not less than 0 and not greater than 255. Using default ledCurrent=%f", ledCurrent, PRESENS_LED_DEFAULT); 00059 ledCurrent = PRESENS_LED_DEFAULT; 00060 } 00061 00062 presenseComm.printf("sacu%-.4d\r", (int)ledCurrent); 00063 00064 presenseComm.printf("mode0000\r"); 00065 wait(PRESENS_CONFIG_DELAY); 00066 // presenseComm.printf("avrg0009\r"); 00067 // wait(PRESENS_CONFIG_DELAY); 00068 // presenseComm.printf("view0000\r"); 00069 // wait(PRESENS_CONFIG_DELAY); 00070 // presenseComm.printf("tmpc2000\r"); 00071 // wait(PRESENS_CONFIG_DELAY); 00072 00073 } 00074 00075 void presensGetData(float* result) 00076 { 00077 float amplitude = 0; 00078 float phase = 0; 00079 int PRESENS_FLOAT_LENGTH = 7; 00080 00081 00082 00083 00084 //presenseComm.printf("call0000\r");; 00085 // presenseComm.printf("data\r");; 00086 adcGetData(); 00087 wait(0.1); 00088 00089 const OxygenSensor oxsense(TempCal1, TempCal2, PhaseCal1, PhaseCal2, PresCal, PRESENS_SALINITY); 00090 00091 if (result == NULL) { 00092 ERROR("Result array is null"); 00093 return; 00094 } 00095 00096 L3=1; 00097 00098 // read the each data packet 00099 00100 while (presenseComm.readable() != 1); 00101 00102 //waiting until letter 'A' is read 00103 //presens amp get 00104 while (presenseComm.getc() != 65); 00105 00106 amplitude = presensReadFloat(PRESENS_FLOAT_LENGTH); 00107 00108 /* skip the characters semicolon ":" and letter "P" */ 00109 while (presenseComm.getc() != 80); 00110 00111 L4=1; 00112 00113 PRESENS_FLOAT_LENGTH = 4; 00114 phase = presensReadFloat(PRESENS_FLOAT_LENGTH) / 100; 00115 00116 L3 = 0; 00117 00118 // read through the rest of packet to empty out the buffer 00119 00120 while(presenseComm.readable()) { 00121 presenseComm.getc(); 00122 } 00123 00124 // end of the data extraction 00125 00126 L3=1; 00127 00128 DEBUG1("Amplitude=%5.0f Phase=%5.2f", amplitude, phase); 00129 00130 result[0] = amplitude; 00131 result[1] = phase; 00132 result[2] = oxsense.calculate(PHTEMP, phase); 00133 00134 if (amplitude < 600) { 00135 result[2] = 999.99; 00136 } 00137 00138 DEBUG1("Result array:amplitude=%5.0f, phase=%2.2f, OxsenseData=%3.3f", amplitude, phase, result[2]); 00139 00140 L3=0; 00141 L4=0; 00142 }
Generated on Tue Sep 27 2022 18:47:00 by
1.7.2