/// <summary> /// Adds a single point to the end of the buffer /// </summary> /// <param name="point">Point being added</param> public void AddPoint(Sample point) { lock (this) { // Copy over the value: buffer[nextBufferIndex].copyFrom(point); OpenMedICUtils.debugPrint("Added a point with value " + point.sampleValue + " at position " + nextBufferIndex); // Update nextBufferIndex, WITH WRAPPING: if (nextBufferIndex == (buffer.size - 1)) { nextBufferIndex = 0; } else { nextBufferIndex++; } // update next input index: nextInputIndex++; if (nextInputIndex < 0) { // Overflowed and wrapped around: nextInputIndex = 0; // This is the only practical thing to do... } hasData = true; } }
/// <summary> /// Returns up to MaxCount points added to circular buffer since a given InputIndex /// </summary> /// <param name="SinceIndex">Return points starting at this InputIndex</param> /// <param name="MaxCount">Max. number of points to return; actual returned points may be less!</param> /// <param name="PointsSince">Array in which points are passed back</param> public void GetPointsSince(long SinceIndex, int MaxCount, Samples PointsSince) { int NumPointsSince; // number of points being returned lock (this) // To avoid the buffer changing while we are reading it! { //test for index if (SinceIndex < 0) { //Invalid SinceIndex; throw an exception throw (new ArgumentOutOfRangeException("SinceIndex", SinceIndex, "Invalid SinceIndex: " + SinceIndex.ToString() + ". Must be 0 or greater.")); } //test to see if SinceIndex is too high if (SinceIndex > CurrInputIndex + 1) { //Bad index; throw an exception throw (new ArgumentOutOfRangeException("SinceIndex", SinceIndex, "SinceIndex (" + SinceIndex.ToString() + ") greater than current signal index + 1 (" + (CurrInputIndex + 1).ToString() + ").")); } NumPointsSince = (int)(nextInputIndex - SinceIndex); //test to see if we're being asked to return too many points if (NumPointsSince > buffer.size) { // Too many points; must truncate: NumPointsSince = buffer.size; SinceIndex = nextInputIndex - NumPointsSince; ////too many points; throw an exception //throw (new ArgumentOutOfRangeException("SinceIndex", SinceIndex, "Starting point (" // + SinceIndex + ") implies a range of samples (" + NumPointsSince // + ") greater than circular buffer length (" + buffer.size + ").")); } if (NumPointsSince > PointsSince.maxSize) { //too many points; throw an exception throw (new ArgumentOutOfRangeException("MaxCount", MaxCount, "Requesting more points (" + NumPointsSince + ") greater than passed buffer max. size (" + PointsSince.maxSize + ").")); } //Inputs are OK MaxCount = Math.Min(NumPointsSince, MaxCount); OpenMedICUtils.debugPrint("Returning " + MaxCount + " points starting from " + SinceIndex); //Let's get the points! PointsSince.size = MaxCount; int BuffIndex; //points to the index of the circular buffer that we're operating on for (int i = 0; i != MaxCount; i++) { BuffIndex = (int)((SinceIndex + i) % buffer.size); PointsSince[i].copyFrom(buffer[BuffIndex]); OpenMedICUtils.debugPrint(" - Returning point at index " + BuffIndex + ": value = " + PointsSince[i].sampleValue); } } }
private void readHeader() { ChainInfo.tagValuePair val = new ChainInfo.tagValuePair(); string headerRow; StreamReader fNew = new StreamReader(fPathName); try { // Scan forward to desired starting point: if (curReadStartPos > 0) { // Scan forward to desired starting point: fNew.BaseStream.Seek(curReadStartPos, System.IO.SeekOrigin.Begin); } for (int i = 0; i < 10000; i++) // more than 10K lines of header would be a problem... { headerRow = fNew.ReadLine(); this.curReadStartPos += headerRow.Length + OpenMedICUtils.newLine.Length; if (headerRow == FileHandler.headerEndDelim) { // End of the header // We are done: break; } else if (!headerRow.StartsWith(FileHandler.headerRowLeader)) { // NOT a new header row // Hmmm, this is a continuation of the last value! val.tagValue += FileHandler.headerRowTrailer + headerRow; // Now overwrite what we wrote on the last write: setInitValueByTag(initValues, val); // If there are even more rows, we'll update this again later... } else if (!OpenMedICUtils.isEmpty(headerRow)) { // NOT empty (must be a new header row) val = parseHeaderRow(headerRow); // Update initValues -- this is either the "live" object or // it's the local-only object, depending on our mode: setInitValueByTag(initValues, val); } // Check for run-away (unterminated) headers: if (i > 9998) { // Bad! throw new FileLoadException("The header is not terminated or too big! " + "Already processed " + i + " rows without finding the Header Terminator row (\"" + FileHandler.headerEndDelim + "\")!", this.fPathName); } } } finally { fNew.Close(); } }
/// <summary> /// Creates a duplicate copy of this object and all its data. /// </summary> /// <returns>A new PatientInfo object identical to this one</returns> public PatientInfo clone() { PatientInfo newInfo = new PatientInfo(firstName, middleName, lastName, addr1, addr2, city, state, zip, country); newInfo.age = age; newInfo.dOB = dOB; if (!OpenMedICUtils.isEmpty(fullAddrInt)) { newInfo.fullAddrInt = fullAddrInt; } if (!OpenMedICUtils.isEmpty(fullNameInt)) { newInfo.fullNameInt = fullNameInt; } return(newInfo); }
/// <summary> /// Draws points acquired since last draw /// </summary> public void DrawNew() { if (AutoRedraw) { long StartIndex; lock (this) { //get the points we need from the waveform try { if (wfThis == null) { OpenMedICUtils.debugPrint("wfThis null! In RTDisp.DrawNew()"); } else if (InSamples == null) { OpenMedICUtils.debugPrint("InSamples null! In RTDisp.DrawNew()"); } else { StartIndex = wfThis.getPoints( InSamples, this.xAxisDispMax, lastAbsIndexDisplayed); //Debug.WriteLine(StartIndex.ToString() + ", " + InSamples.size.ToString()); NewGraphPoints(StartIndex, InSamples); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine( "Exception: \n" + e.Message + "\nStack trace:\n\n" + e.StackTrace); } } } }