Darien Figueroa / Mbed 2 deprecated repo3

Dependencies:   mbed MAX14720 MAX30205 USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DataLogging.cs Source File

DataLogging.cs

00001 /*******************************************************************************
00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved.
00003 * 
00004 * This software is protected by copyright laws of the United States and
00005 * of foreign countries. This material may also be protected by patent laws
00006 * and technology transfer regulations of the United States and of foreign
00007 * countries. This software is furnished under a license agreement and/or a
00008 * nondisclosure agreement and may only be used or reproduced in accordance
00009 * with the terms of those agreements. Dissemination of this information to
00010 * any party or parties not specified in the license agreement and/or
00011 * nondisclosure agreement is expressly prohibited.
00012 *
00013 * The above copyright notice and this permission notice shall be included
00014 * in all copies or substantial portions of the Software.
00015 *
00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00017 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00019 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00020 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00021 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00022 * OTHER DEALINGS IN THE SOFTWARE.
00023 *
00024 * Except as contained in this notice, the name of Maxim Integrated
00025 * Products, Inc. shall not be used except as stated in the Maxim Integrated
00026 * Products, Inc. Branding Policy.
00027 *
00028 * The mere transfer of this software does not imply any licenses
00029 * of trade secrets, proprietary technology, copyrights, patents,
00030 * trademarks, maskwork rights, or any other form of intellectual
00031 * property whatsoever. Maxim Integrated Products, Inc. retains all
00032 * ownership rights.
00033 *******************************************************************************
00034 */
00035 
00036 using System;
00037 using System.Collections.Generic;
00038 using System.Linq;
00039 using System.Text;
00040 using RPCSupport.Devices;
00041 using System.Globalization;
00042 using System.Runtime.Serialization.Formatters.Binary;
00043 using System.IO;
00044 using System.Threading;
00045 
00046 namespace RPCSupport.DataLogging
00047 {
00048     public class DataLogging : ClientDevice
00049     {
00050 
00051         public class cParametersEcg : cDeviceMethodParameters
00052         {
00053             public cParametersEcg(String className, String methodName) : base(className, methodName) { }
00054             public int En_ecg;
00055             public int Openp;
00056             public int Openn;
00057             public int Pol;
00058             public int Calp_sel;
00059             public int Caln_sel;
00060             public int E_fit;
00061             public int Rate;
00062             public int Gain;
00063             public int Dhpf;
00064             public int Dlpf;
00065 
00066             public override void AssignByIntArray(int[] intArray)
00067             {
00068                 int i = 0;
00069                 En_ecg = intArray[i++];
00070                 Openp = intArray[i++];
00071                 Openn = intArray[i++];
00072                 Pol = intArray[i++];
00073                 Calp_sel = intArray[i++];
00074                 Caln_sel = intArray[i++];
00075                 E_fit = intArray[i++];
00076                 Rate = intArray[i++];
00077                 Gain = intArray[i++];
00078                 Dhpf = intArray[i++];
00079                 Dlpf = intArray[i++];
00080             }
00081             public override int[] ToIntArray()
00082             {
00083                 int i = 0;
00084                 List<int> intArray = new List<int>();
00085                 intArray.Add(En_ecg);
00086                 intArray.Add(Openp);
00087                 intArray.Add(Openn);
00088                 intArray.Add(Pol);
00089                 intArray.Add(Calp_sel);
00090                 intArray.Add(Caln_sel);
00091                 intArray.Add(E_fit);
00092                 intArray.Add(Rate);
00093                 intArray.Add(Gain);
00094                 intArray.Add(Dhpf);
00095                 intArray.Add(Dlpf);
00096                 return intArray.ToArray();
00097             }
00098 
00099             public void AssignByValue(
00100                 int En_ecg,
00101                 int Openp,
00102                 int Openn,
00103                 int Pol,
00104                 int Calp_sel,
00105                 int Caln_sel,
00106                 int E_fit,
00107                 int Rate,
00108                 int Gain,
00109                 int Dhpf,
00110                 int Dlpf)
00111             {
00112                 this.En_ecg = En_ecg;
00113                 this.Openp = Openp;
00114                 this.Openn = Openn;
00115                 this.Pol = Pol;
00116                 this.Calp_sel = Calp_sel;
00117                 this.Caln_sel = Caln_sel;
00118                 this.E_fit = E_fit;
00119                 this.Rate = Rate;
00120                 this.Gain = Gain;
00121                 this.Dhpf = Dhpf;
00122                 this.Dlpf = Dlpf;
00123             }
00124         }
00125 //        public cParametersEcg ParametersMAX30001Ecg = new cParametersEcg();
00126         
00127         public class cParametersBioz : cDeviceMethodParameters
00128         {
00129             public cParametersBioz(String className, String methodName) : base(className, methodName) { }
00130             public int En_bioz;
00131             public int Openp;
00132             public int Openn;
00133             public int Calp_sel;
00134             public int Caln_sel;
00135             public int CG_mode;
00136             public int B_fit;
00137             public int Rate;
00138             public int Ahpf;
00139             public int Ext_rbias;
00140             public int Gain;
00141             public int Dhpf;
00142             public int Dlpf;
00143             public int Fcgen;
00144             public int Cgmon;
00145             public int Cgmag;
00146             public int Phoff;
00147             public override void AssignByIntArray(int[] intArray)
00148             {
00149                 int i = 0;
00150                 En_bioz = intArray[i++];
00151                 Openp = intArray[i++];
00152                 Openn = intArray[i++];
00153                 Calp_sel = intArray[i++];
00154                 Caln_sel = intArray[i++];
00155                 CG_mode = intArray[i++];
00156                 B_fit = intArray[i++];
00157                 Rate = intArray[i++];
00158                 Ahpf = intArray[i++];
00159                 Ext_rbias = intArray[i++];
00160                 Gain = intArray[i++];
00161                 Dhpf = intArray[i++];
00162                 Dlpf = intArray[i++];
00163                 Fcgen = intArray[i++];
00164                 Cgmon = intArray[i++];
00165                 Cgmag = intArray[i++];
00166                 Phoff = intArray[i++];
00167             }
00168 
00169             public override int[] ToIntArray()
00170             {
00171                 int i = 0;
00172                 List<int> intArray = new List<int>();
00173                 intArray.Add(En_bioz);
00174                 intArray.Add(Openp);
00175                 intArray.Add(Openn);
00176                 intArray.Add(Calp_sel);
00177                 intArray.Add(Caln_sel);
00178                 intArray.Add(CG_mode);
00179                 intArray.Add(B_fit);
00180                 intArray.Add(Rate);
00181                 intArray.Add(Ahpf);
00182                 intArray.Add(Ext_rbias);
00183                 intArray.Add(Gain);
00184                 intArray.Add(Dhpf);
00185                 intArray.Add(Dlpf);
00186                 intArray.Add(Fcgen);
00187                 intArray.Add(Cgmon);
00188                 intArray.Add(Cgmag);
00189                 intArray.Add(Phoff);
00190                 return intArray.ToArray();
00191             }
00192 
00193             public void AssignByValue(
00194                 int En_bioz,
00195                 int Openp,
00196                 int Openn,
00197                 int Calp_sel,
00198                 int Caln_sel,
00199                 int CG_mode,
00200                 int B_fit,
00201                 int Rate,
00202                 int Ahpf,
00203                 int Ext_rbias,
00204                 int Gain,
00205                 int Dhpf,
00206                 int Dlpf,
00207                 int Fcgen,
00208                 int Cgmon,
00209                 int Cgmag,
00210                 int Phoff)
00211             {
00212                 this.En_bioz = En_bioz;
00213                 this.Openp = Openp;
00214                 this.Openn = Openn;
00215                 this.Calp_sel = Calp_sel;
00216                 this.Caln_sel = Caln_sel;
00217                 this.CG_mode = CG_mode;
00218                 this.B_fit = B_fit;
00219                 this.Rate = Rate;
00220                 this.Ahpf = Ahpf;
00221                 this.Ext_rbias = Ext_rbias;
00222                 this.Gain = Gain;
00223                 this.Dhpf = Dhpf;
00224                 this.Dlpf = Dlpf;
00225                 this.Fcgen = Fcgen;
00226                 this.Cgmon = Cgmon;
00227                 this.Cgmag = Cgmag;
00228                 this.Phoff = Phoff;
00229             }
00230         }
00231         //public cParametersBioz ParametersMAX30001Bioz = new cParametersBioz();
00232 
00233         public class cParametersRtoR : cDeviceMethodParameters
00234         {
00235             public cParametersRtoR(String className, String methodName) : base(className, methodName) { }
00236             public int En_rtor;
00237             public int Wndw;
00238             public int Gain;
00239             public int Pavg;
00240             public int Ptsf;
00241             public int Hoff;
00242             public int Ravg;
00243             public int Rhsf;
00244             public int Clr_rrint;
00245             public override void AssignByIntArray(int[] intArray)
00246             {
00247                 int i = 0;
00248                 En_rtor = intArray[i++];
00249                 Wndw = intArray[i++];
00250                 Gain = intArray[i++];
00251                 Pavg = intArray[i++];
00252                 Ptsf = intArray[i++];
00253                 Hoff = intArray[i++];
00254                 Ravg = intArray[i++];
00255                 Rhsf = intArray[i++];
00256                 Clr_rrint = intArray[i++];
00257             }
00258 
00259             public override int[] ToIntArray()
00260             {
00261                 int i = 0;
00262                 List<int> intArray = new List<int>();
00263                 intArray.Add(En_rtor);
00264                 intArray.Add(Wndw);
00265                 intArray.Add(Gain);
00266                 intArray.Add(Pavg);
00267                 intArray.Add(Ptsf);
00268                 intArray.Add(Hoff);
00269                 intArray.Add(Ravg);
00270                 intArray.Add(Rhsf);
00271                 intArray.Add(Clr_rrint);
00272                 return intArray.ToArray();
00273             }
00274 
00275             public void AssignByValue(
00276                 int En_rtor,
00277                 int Wndw,
00278                 int Gain,
00279                 int Pavg,
00280                 int Ptsf,
00281                 int Hoff,
00282                 int Ravg,
00283                 int Rhsf,
00284                 int Clr_rrint)
00285             {
00286                 this.En_rtor = En_rtor;
00287                 this.Wndw = Wndw;
00288                 this.Gain = Gain;
00289                 this.Pavg = Pavg;
00290                 this.Ptsf = Ptsf;
00291                 this.Hoff = Hoff;
00292                 this.Ravg = Ravg;
00293                 this.Rhsf = Rhsf;
00294                 this.Clr_rrint = Clr_rrint;
00295             }
00296         }
00297         //public cParametersRtoR ParametersMAX30001RtoR = new cParametersRtoR();
00298 
00299         public class cParametersPace : cDeviceMethodParameters
00300         {
00301             public cParametersPace(String className, String methodName) : base(className, methodName) { }
00302             public int En_pace;
00303             public int Clr_pedge;
00304             public int Pol;
00305             public int Gn_diff_off;
00306             public int Gain;
00307             public int Aout_lbw;
00308             public int Aout;
00309             public int Dacp;
00310             public int Dacn;
00311             public override void AssignByIntArray(int[] intArray)
00312             {
00313                 int i = 0;
00314                 En_pace = intArray[i++];
00315                 Clr_pedge = intArray[i++];
00316                 Pol = intArray[i++];
00317                 Gn_diff_off = intArray[i++];
00318                 Gain = intArray[i++];
00319                 Aout_lbw = intArray[i++];
00320                 Aout = intArray[i++];
00321                 Dacp = intArray[i++];
00322                 Dacn = intArray[i++];
00323             }
00324 
00325             public override int[] ToIntArray()
00326             {
00327                 int i = 0;
00328                 List<int> intArray = new List<int>();
00329                 intArray.Add(En_pace);
00330                 intArray.Add(Clr_pedge);
00331                 intArray.Add(Pol);
00332                 intArray.Add(Gn_diff_off);
00333                 intArray.Add(Gain);
00334                 intArray.Add(Aout_lbw);
00335                 intArray.Add(Aout);
00336                 intArray.Add(Dacp);
00337                 intArray.Add(Dacn);
00338                 return intArray.ToArray();
00339             }
00340 
00341             public void AssignByValue(
00342                 int En_pace,
00343                 int Clr_pedge,
00344                 int Pol,
00345                 int Gn_diff_off,
00346                 int Gain,
00347                 int Aout_lbw,
00348                 int Aout,
00349                 int Dacp,
00350                 int Dacn)
00351             {
00352                 this.En_pace = En_pace;
00353                 this.Clr_pedge = Clr_pedge;
00354                 this.Pol = Pol;
00355                 this.Gn_diff_off = Gn_diff_off;
00356                 this.Gain = Gain;
00357                 this.Aout = Aout;
00358                 this.Dacp = Dacp;
00359                 this.Dacn = Dacn;
00360             }
00361         }
00362 
00363         public class cParametersCal : cDeviceMethodParameters
00364         {
00365             public cParametersCal(String className, String methodName) : base(className, methodName) { }
00366             public int parameter1;
00367             public int parameter2;
00368             public int parameter3;
00369             public int parameter4;
00370             public int parameter5;
00371             public int parameter6;
00372             public override void AssignByIntArray(int[] intArray)
00373             {
00374                 int i = 0;
00375                 parameter1 = intArray[i++];
00376                 parameter2 = intArray[i++];
00377                 parameter3 = intArray[i++];
00378                 parameter4 = intArray[i++];
00379                 parameter5 = intArray[i++];
00380                 parameter6 = intArray[i++];
00381             }
00382 
00383             public override int[] ToIntArray()
00384             {
00385                 int i = 0;
00386                 List<int> intArray = new List<int>();
00387                 intArray.Add(parameter1);
00388                 intArray.Add(parameter2);
00389                 intArray.Add(parameter3);
00390                 intArray.Add(parameter4);
00391                 intArray.Add(parameter5);
00392                 intArray.Add(parameter6);
00393                 return intArray.ToArray();
00394             }
00395 
00396             public void AssignByValue(
00397                 int parameter1,
00398                 int parameter2,
00399                 int parameter3,
00400                 int parameter4,
00401                 int parameter5,
00402                 int parameter6
00403                 )
00404 
00405             {
00406                 this.parameter1 = parameter1;
00407                 this.parameter2 = parameter2;
00408                 this.parameter3 = parameter3;
00409                 this.parameter4 = parameter4;
00410                 this.parameter5 = parameter5;
00411                 this.parameter6 = parameter6;
00412             }
00413         }
00414        
00415         //        public cParametersPace ParametersMAX30001Pace = new cParametersPace();
00416         public class cParametersTemp : cDeviceMethodParameters
00417         {
00418             public cParametersTemp(String className, String methodName, int deviceNumber) : base(className, methodName) { this.deviceNumber = deviceNumber; }
00419             public int sampleTime;  // seconds
00420             private int deviceNumber;
00421             public override void AssignByIntArray(int[] intArray)
00422             {
00423                 int i = 0;
00424                 sampleTime = intArray[i++];
00425             }
00426 
00427             public override int[] ToIntArray()
00428             {
00429                 int i = 0;
00430                 List<int> intArray = new List<int>();
00431                 intArray.Add(sampleTime);
00432                 return intArray.ToArray();
00433             }
00434         }
00435 //        public cParametersTemp1 ParametersMAX31725_1 = new cParametersTemp1();
00436 
00437 //        public cParametersTemp2 ParametersMAX31725_2 = new cParametersTemp2();
00438 
00439         public class cParametersPressure : cDeviceMethodParameters
00440         {
00441             public cParametersPressure(String className, String methodName) : base(className, methodName) { }
00442             public int sampleTime;  // seconds
00443             public override void AssignByIntArray(int[] intArray)
00444             {
00445                 int i = 0;
00446                 sampleTime = intArray[i++];
00447             }
00448 
00449             public override int[] ToIntArray()
00450             {
00451                 int i = 0;
00452                 List<int> intArray = new List<int>();
00453                 intArray.Add(sampleTime);
00454                 return intArray.ToArray();
00455             }
00456         }
00457 //        public cParametersPressure ParametersBMP280 = new cParametersPressure();
00458 
00459         public class cParametersAccel : cDeviceMethodParameters
00460         {
00461             public cParametersAccel(String className, String methodName) : base(className, methodName) { fifoDepth = 1; }
00462             public int sampleRate;  // Hz
00463             public int fifoDepth; 
00464             public override void AssignByIntArray(int[] intArray)
00465             {
00466                 int i = 0;
00467                 sampleRate = intArray[i++];
00468                 fifoDepth = intArray[i++];
00469             }
00470 
00471             public override int[] ToIntArray()
00472             {
00473                 int i = 0;
00474                 List<int> intArray = new List<int>();
00475                 intArray.Add(sampleRate);
00476                 intArray.Add(fifoDepth);
00477                 return intArray.ToArray();
00478             }
00479         }
00480 //        public cParametersAccel ParametersLIS2DH = new cParametersAccel();
00481 
00482         public class cParameterOpticalSpO2 : cDeviceMethodParameters
00483         {
00484             public cParameterOpticalSpO2(String className, String methodName) : base(className, methodName) { }
00485             public int fifo_waterlevel_mark;
00486             public int sample_avg;
00487             public int sample_rate;
00488             public int pulse_width;
00489             public int red_led_current;
00490             public int ir_led_current;
00491             public override void AssignByIntArray(int[] intArray)
00492             {
00493                 int i = 0;
00494                 fifo_waterlevel_mark = intArray[i++];
00495                 sample_avg = intArray[i++];
00496                 sample_rate = intArray[i++];
00497                 pulse_width = intArray[i++];
00498                 red_led_current = intArray[i++];
00499                 ir_led_current = intArray[i++];
00500             }
00501 
00502             public override int[] ToIntArray()
00503             {
00504                 int i = 0;
00505                 List<int> intArray = new List<int>();
00506                 intArray.Add(fifo_waterlevel_mark);
00507                 intArray.Add(sample_avg);
00508                 intArray.Add(sample_rate);
00509                 intArray.Add(pulse_width);
00510                 intArray.Add(red_led_current);
00511                 intArray.Add(ir_led_current);
00512                 return intArray.ToArray();
00513             }
00514         }
00515 //        public cParameterOpticalSpO2 ParameterMAX30101SpO2 = new cParameterOpticalSpO2();
00516 
00517         public class cParameterOpticalHR : cDeviceMethodParameters
00518         {
00519             public cParameterOpticalHR(String className, String methodName) : base(className, methodName) { }
00520             public int fifo_waterlevel_mark;
00521             public int sample_avg;
00522             public int sample_rate;
00523             public int pulse_width;
00524             public int red_led_current;
00525             public override void AssignByIntArray(int[] intArray)
00526             {
00527                 int i = 0;
00528                 fifo_waterlevel_mark = intArray[i++];
00529                 sample_avg = intArray[i++];
00530                 sample_rate = intArray[i++];
00531                 pulse_width = intArray[i++];
00532                 red_led_current = intArray[i++];
00533             }
00534 
00535             public override int[] ToIntArray()
00536             {
00537                 int i = 0;
00538                 List<int> intArray = new List<int>();
00539                 intArray.Add(fifo_waterlevel_mark);
00540                 intArray.Add(sample_avg);
00541                 intArray.Add(sample_rate);
00542                 intArray.Add(pulse_width);
00543                 intArray.Add(red_led_current);
00544                 return intArray.ToArray();
00545             }
00546         }
00547 //        public cParameterOpticalHR ParameterMAX30101HR = new cParameterOpticalHR();
00548 
00549         public class cParameterOpticalMulti : cDeviceMethodParameters
00550         {
00551             public cParameterOpticalMulti(String className, String methodName) : base(className, methodName) { }
00552             public int fifo_waterlevel_mark;
00553             public int sample_avg;
00554             public int sample_rate;
00555             public int pulse_width;
00556             public int red_led_current;
00557             public int ir_led_current;
00558             public int green_led_current;
00559             public int slot_1;
00560             public int slot_2;
00561             public int slot_3;
00562             public int slot_4;
00563             public override void AssignByIntArray(int[] intArray)
00564             {
00565                 int i = 0;
00566                 fifo_waterlevel_mark = intArray[i++];
00567                 sample_avg = intArray[i++];
00568                 sample_rate = intArray[i++];
00569                 pulse_width = intArray[i++];
00570                 red_led_current = intArray[i++];
00571                 ir_led_current = intArray[i++];
00572                 green_led_current = intArray[i++];
00573                 slot_1 = intArray[i++];
00574                 slot_2 = intArray[i++];
00575                 slot_3 = intArray[i++];
00576                 slot_4 = intArray[i++];
00577             }
00578 
00579             public override int[] ToIntArray()
00580             {
00581                 int i = 0;
00582                 List<int> intArray = new List<int>();
00583                 intArray.Add(fifo_waterlevel_mark);
00584                 intArray.Add(sample_avg);
00585                 intArray.Add(sample_rate);
00586                 intArray.Add(pulse_width);
00587                 intArray.Add(red_led_current);
00588                 intArray.Add(ir_led_current);
00589                 intArray.Add(green_led_current);
00590                 intArray.Add(slot_1);
00591                 intArray.Add(slot_2);
00592                 intArray.Add(slot_3);
00593                 intArray.Add(slot_4);
00594                 return intArray.ToArray();
00595             }
00596         }
00597 
00598         public class cParametersRbiasFmstr : cDeviceMethodParameters
00599         {
00600             public cParametersRbiasFmstr(String className, String methodName) : base(className, methodName) { }
00601 
00602             public int en_rbias;
00603             public int rbias;
00604             public int rbiasp;
00605             public int rbiasn;
00606             public int fmstr;
00607 
00608             public override void AssignByIntArray(int[] intArray)
00609             {
00610                 int i = 0;
00611                 en_rbias = intArray[i++];
00612                 rbias = intArray[i++];
00613                 rbiasp = intArray[i++];
00614                 rbiasn = intArray[i++];
00615                 fmstr = intArray[i++];
00616             }
00617 
00618             public override int[] ToIntArray()
00619             {
00620                 int i = 0;
00621 
00622                 List<int> intArray = new List<int>();
00623                 intArray.Add(en_rbias);
00624                 intArray.Add(rbias);
00625                 intArray.Add(rbiasp);
00626                 intArray.Add(rbiasn);
00627                 intArray.Add(fmstr);
00628 
00629                 return intArray.ToArray();
00630             }
00631 
00632         }
00633 
00634         //PreCommand
00635         public class cRawRPCCommand : cDeviceMethodParameters
00636         {
00637            public String cmdString;
00638            public cRawRPCCommand(String className, String methodName) : base(className, methodName) { }
00639            public void Define(String str)
00640            {
00641                String inStr = str.Trim();
00642                if (inStr.CompareTo("null") == 0) str = "";
00643                cmdString = str;
00644            }
00645            public override void AssignByIntArray(int[] intArray)
00646             {
00647                 throw new NotImplementedException();
00648             }
00649 
00650             public override int[] ToIntArray()
00651             {
00652                 throw new NotImplementedException();
00653             }
00654             public override String GenerateRpcCommandString()
00655             {
00656                 String str = cmdString;
00657                 if (String.IsNullOrWhiteSpace(cmdString)) str = "null";
00658                 String cmd = String.Format("\"{0}\"", str);
00659                 //Console.WriteLine("cmd string  = '" + cmd + "'");
00660                 //Console.WriteLine("cmd string length = " + cmd.Length.ToString());
00661                 return cmd;
00662             }
00663         }
00664         public cParametersEcg MAX30001_Ecg = new cParametersEcg("MAX30001", "ECG_InitStart");
00665         public cParametersBioz MAX30001_Bioz = new cParametersBioz("MAX30001", "BIOZ_InitStart");
00666         public cParametersRtoR MAX30001_RtoR = new cParametersRtoR("MAX30001", "RtoR_InitStart");
00667         public cParametersPace MAX30001_Pace = new cParametersPace("MAX30001", "PACE_InitStart");
00668         public cParametersCal MAX30001_Cal = new cParametersCal("MAX30001", "CAL_InitStart");
00669         public cRawRPCCommand MAX30001_Rbias = new cRawRPCCommand("", "");
00670         public cParametersRbiasFmstr MAX30001_Rbias_Fmstr = new cParametersRbiasFmstr("MAX30001", "Rbias_FMSTR_Init");
00671         public cParametersTemp MAX31725_1 = new cParametersTemp("MAX30205_1", "InitStart", 1);
00672         public cParametersTemp MAX31725_2 = new cParametersTemp("MAX30205_2", "InitStart", 2);
00673         public cParametersPressure BMP280 = new cParametersPressure("BMP280", "InitStart");
00674         public cParametersAccel LIS2DH = new cParametersAccel("LIS2DH", "InitStart");
00675         public cParameterOpticalSpO2 MAX30101_SpO2 = new cParameterOpticalSpO2("MAX30101", "SpO2mode_InitStart");
00676         public cParameterOpticalHR MAX30101_HR = new cParameterOpticalHR("MAX30101", "HRmode_InitStart");
00677         public cParameterOpticalMulti MAX30101_Multi = new cParameterOpticalMulti("MAX30101", "Multimode_InitStart");
00678         public cRawRPCCommand PreCommand = new cRawRPCCommand("", "");
00679         public cRawRPCCommand PostCommand = new cRawRPCCommand("", "");
00680 
00681         const string CLASSNAME = "Logging";
00682         public DataLogging(RPCClient client)
00683             : base(client)
00684         {
00685             InitRpcCommandList();
00686         }
00687         /*
00688         public void StartLoggingUsb()
00689         {
00690             string reply;
00691             reply = Call(CLASSNAME, "StartLoggingUsb");
00692         }
00693         */
00694         private void InitStreaming()
00695         {
00696             client.pipeline.Discard();
00697             client.streaming.Init(client.pipeline);
00698             client.streaming.Start();
00699             //Call(CLASSNAME, "StreamTest");
00700             //CallNoReply(CLASSNAME, "StreamTest");
00701         }
00702 
00703         public void StartStreaming()
00704         {
00705             client.pipeline.Discard();
00706             InitStreaming();
00707             CallNoReply(CLASSNAME, "StartLoggingUsb");
00708             //Call(CLASSNAME, "StartTest");
00709         }
00710 
00711         public void StopStreaming()
00712         {
00713             StopStreaming(true);
00714         }
00715 
00716         public void StopStreaming(bool connected)
00717         {
00718             //if (connected)
00719                 client.pipeline.SendSingleByte(' ');
00720 
00721             client.streaming.Stop();
00722 
00723             //if (connected)
00724             {
00725                 client.pipeline.Discard();
00726                 Thread.Sleep(500);
00727                 client.pipeline.Discard();
00728             }
00729         }
00730 
00731         public void MissionRead()
00732         {
00733             int val;
00734             string reply;
00735 
00736             reply = Call(CLASSNAME, "ReadMission");
00737             reply = reply.Trim(new char[] { '\n', '\r', ' ', ':' });
00738             String[] cmds = reply.Split(new char[] { ':' });
00739             int i = 1;
00740             foreach (String str in cmds)
00741             {
00742                 String cmd = str.Trim();
00743                 if (!String.IsNullOrEmpty(cmd))
00744                 {
00745                     Console.WriteLine(i.ToString() + ": " + cmd);
00746                     i++;
00747                 }
00748             }
00749             //reply = Call(CLASSNAME, "ReadMission");
00750             //reply = "/MAX30001/ECG_InitStart 01 01 01 00 02 03 1F 00 02 00 01\r\n/BMP280/InitStart 01\r\n";
00751 
00752             // clear where it exists in mission flag
00753             foreach (cDeviceMethodParameters cmd in rpcCommandList)
00754             {
00755                 cmd.ClearExistsInDeviceMission();
00756             }
00757             PreCommand.ClearExistsInDeviceMission();
00758             PostCommand.ClearExistsInDeviceMission();
00759             //reply[0]
00760             ParseRPCReadSequence(reply);
00761         }
00762 
00763         public string[] MissionStrings()
00764         {
00765             string reply;
00766 
00767             reply = Call(CLASSNAME, "ReadMission");
00768             reply = reply.Trim(new char[] { '\n', '\r', ' ', ':' });
00769             string[] cmds = reply.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries);
00770 
00771             return cmds;
00772         }
00773 
00774         int debugMissionCmdCount;
00775         public void MissionStartDefinition()
00776         {
00777             string reply;
00778             reply = Call(CLASSNAME, "StartMissionDefine");
00779             debugMissionCmdCount = 0;
00780         }
00781         public void MissionAppend(cDeviceMethodParameters device)
00782         {
00783             String cmd;
00784             cmd = device.GenerateRpcCommandString();
00785             Call(CLASSNAME, "AppendMissionCmd", cmd);
00786             debugMissionCmdCount++;
00787             Console.WriteLine(debugMissionCmdCount.ToString() + ": " + cmd);
00788         }
00789         public void MissionAppend(String cmdStr)
00790         {
00791             Call(CLASSNAME, "AppendMissionCmd", "\"" + cmdStr + "\"");
00792             debugMissionCmdCount++;
00793             Console.WriteLine(debugMissionCmdCount.ToString() + ": " + cmdStr);
00794         }
00795         public void MissionWrite()
00796         {
00797             int val;
00798             string cmd;
00799             string reply;
00800             StringBuilder sbTest = new StringBuilder();
00801 
00802             reply = Call(CLASSNAME, "EndMissionDefine");
00803             reply = Call(CLASSNAME, "WriteMission");
00804              //reply = Call(CLASSNAME, "ReadReg", addr.ToString("X2"));
00805             //int.TryParse(reply, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val);
00806 //            Console.WriteLine(sbTest.ToString());
00807         }
00808 
00809         // "/MAX30001/ECG_InitStart 01 01 01 00 02 03 1F 00 02 00 01/r/n/BMP280/InitStart 01 01 01 00 02 03 1F 00 02 00 01/r/n"
00810         private void ParseRPCReadSequence(String cmds)
00811         {
00812             int count = 0;
00813             cmds = cmds.Trim(new char[] { '\n', '\r', ' ', ':' });
00814             String[] cmdStrings = cmds.Split(new char[] { ':' });
00815             int lastCount = cmdStrings.Length - 1;
00816             foreach (String cmd in cmdStrings)
00817             {
00818                 if (count == 0)
00819                 {
00820                     PreCommand.Define(cmd);
00821                     PreCommand.existsInDeviceMission = true;
00822                 }
00823                 else
00824                     if (count == lastCount)
00825                     {
00826                         PostCommand.Define(cmd);
00827                         PostCommand.existsInDeviceMission = true;
00828                     }
00829                     else
00830                         ProcessRPCCmd(cmd);
00831                 count++;
00832             }
00833         }
00834 
00835         List<cDeviceMethodParameters> rpcCommandList = new List<cDeviceMethodParameters>();
00836 
00837         private void InitRpcCommandList()
00838         {
00839             rpcCommandList.Add(MAX30001_Ecg);
00840             rpcCommandList.Add(MAX30001_Bioz);
00841             rpcCommandList.Add(MAX30001_RtoR);
00842             rpcCommandList.Add(MAX30001_Pace);
00843             rpcCommandList.Add(MAX30001_Cal);
00844             rpcCommandList.Add(MAX31725_1);
00845             rpcCommandList.Add(MAX31725_2);
00846             rpcCommandList.Add(BMP280);
00847             rpcCommandList.Add(LIS2DH);
00848             rpcCommandList.Add(MAX30101_SpO2);
00849             rpcCommandList.Add(MAX30101_HR);
00850             rpcCommandList.Add(MAX30101_Multi);
00851             rpcCommandList.Add(MAX30001_Rbias_Fmstr);
00852         }
00853 
00854         private void ProcessRPCCmd(String str)
00855         {
00856             if (String.IsNullOrEmpty(str)) return;
00857             String trimmed = str.Trim(new char[] { '\r', '\n', ' ' });
00858             if (String.IsNullOrEmpty(trimmed)) return;
00859             if (trimmed[0] != '/') return;
00860             String trimmed2 = trimmed.Trim(new char[] { '\r', '\n', '/', ' ' });
00861             String[] parts = trimmed2.Split(new char[] { '/' });
00862             String className = parts[0];
00863             String methodNameParameters = parts[1];
00864             String methodName = methodNameParameters.Substring(0,methodNameParameters.IndexOf(' '));
00865             String parameters = methodNameParameters.Substring(methodNameParameters.IndexOf(' ')).Trim();
00866             foreach (cDeviceMethodParameters cmd in rpcCommandList)
00867             {
00868                 if (cmd.AssignIfMatch(className, methodName, parameters) == true) break;
00869             }
00870         }
00871 
00872         private int[] ParseHexString(String hexStr)
00873         {
00874             int val;
00875             List<int> intList = new List<int>();
00876             String[] strings = hexStr.Split(new char[] { ' ' });
00877             foreach (String str in strings)
00878             {
00879                 if (int.TryParse(str, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val))
00880                 {
00881                     intList.Add(val);
00882                 }
00883                 else
00884                 {
00885                     throw new Exception(String.Format("Error In hex string \"{0}\" in \"{1}\"", str, hexStr));
00886                 }
00887             }
00888             return intList.ToArray();
00889         }
00890 
00891         public void EraseMission()
00892         {
00893             int val;
00894             string cmd;
00895             string reply;
00896 
00897             reply = Call(CLASSNAME, "EraseMission");
00898         }
00899 
00900         public void TestMission()
00901         {
00902             int val;
00903             string cmd;
00904             string reply;
00905 
00906             reply = Call(CLASSNAME, "TestStartMission");
00907         }
00908 
00909         public void TestWriteLog()
00910         {
00911             throw new NotImplementedException();
00912         }
00913 
00914         public void TestReadLog()
00915         {
00916             throw new NotImplementedException();
00917         }
00918 
00919         public void TestBulkErase()
00920         {
00921             throw new NotImplementedException();
00922         }
00923 
00924         public void TestLogSectorsErase()
00925         {
00926             throw new NotImplementedException();
00927         }
00928 
00929         public string ReadPageToString(int page, out bool allOnes)
00930         {
00931             String returnStr = "";
00932             returnStr = CallBinary("S25FS512", "ReadPagesBinary", out allOnes, new String[] { page.ToString("X2"), page.ToString("X2") });
00933             return returnStr;
00934         }
00935 
00936         public void EraseWrittenSectors()
00937         {
00938             int val;
00939             string cmd;
00940             string reply;
00941 
00942             reply = Call(CLASSNAME, "EraseWrittenSectors");
00943         }
00944     }
00945 
00946     public abstract class cDeviceMethodParameters 
00947     {
00948         public String className;
00949         public String methodName;
00950         public abstract void AssignByIntArray(int[] intArray);
00951         public abstract int[] ToIntArray();
00952         public bool existsInDeviceMission;
00953         public bool IsExistsInDeviceMission()
00954         {
00955             return existsInDeviceMission;
00956         }
00957         public void ClearExistsInDeviceMission()
00958         {
00959             existsInDeviceMission = false;
00960         }
00961         public String ParametersToString()
00962         {
00963             StringBuilder sb = new StringBuilder();
00964             int[] intArray = ToIntArray();
00965             foreach (int val in intArray)
00966             {
00967                 sb.Append(val.ToString("X2") + " ");
00968             }
00969             return sb.ToString().Trim(new char[] { ' ', ',' });
00970         }
00971         public virtual String GenerateRpcCommandString()
00972         {
00973             String cmd = String.Format("\"/{0}/{1} {2}\"", className, methodName, ParametersToString());
00974             //Console.WriteLine("cmd string  = '" + cmd + "'");
00975             //Console.WriteLine("cmd string length = " + cmd.Length.ToString());
00976             return cmd;
00977         }
00978         public cDeviceMethodParameters(String className, String methodName)
00979             {
00980                 existsInDeviceMission = false;
00981                 this.className = className;
00982                 this.methodName = methodName;
00983             }
00984         public bool AssignIfMatch(String className, String methodName, String parameterStr)
00985         {
00986             bool match = false;
00987             if (this.className.Equals(className) && this.methodName.Equals(methodName))
00988             {
00989                 match = true;
00990                 existsInDeviceMission = true;
00991                 AssignByIntArray(ParseHexString(parameterStr));
00992             }
00993             return match;
00994         }
00995         private int[] ParseHexString(String hexStr)
00996         {
00997             int val;
00998             List<int> intList = new List<int>();
00999             String[] strings = hexStr.Split(new char[] { ' ' });
01000             foreach (String str in strings)
01001             {
01002                 if (int.TryParse(str, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val))
01003                 {
01004                     intList.Add(val);
01005                 }
01006                 else
01007                 {
01008                     throw new Exception(String.Format("Error In hex string \"{0}\" in \"{1}\"", str, hexStr));
01009                 }
01010             }
01011             return intList.ToArray();
01012         }
01013     }
01014 }