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.
Dependencies: mbed MAX14720 MAX30205 USBDevice
Pipeline.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 System.Globalization; 00041 using System.Collections; 00042 00043 namespace RPCSupport.Pipelines 00044 { 00045 public abstract class Pipeline 00046 { 00047 public delegate void RawRpcRequest(string s); 00048 public delegate void RawRpcReply(string s); 00049 public delegate void RawRpcStream(string s); 00050 internal RawRpcRequest rawRpcRequest; 00051 internal RawRpcReply rawRpcReply; 00052 internal RawRpcStream rawRpcStream; 00053 public virtual bool Init() 00054 { 00055 return true; 00056 } 00057 00058 public abstract string RawRpcCall(string request, bool reply); 00059 public abstract void SendSingleByte(char ch); 00060 public abstract void Discard(); 00061 public abstract string RawRpcCallBinary(string request, bool reply, out bool allOnes); 00062 00063 public void LogStream(string stream) 00064 { 00065 if (rawRpcStream != null) 00066 { 00067 rawRpcStream(stream); 00068 } 00069 } 00070 00071 /*public virtual bool IsConnected() 00072 { 00073 return false; 00074 }*/ 00075 public abstract bool IsConnected(); 00076 00077 public void LogCallback(RawRpcRequest request, RawRpcReply reply, RawRpcStream stream) 00078 { 00079 rawRpcRequest = request; 00080 rawRpcReply = reply; 00081 rawRpcStream = stream; 00082 } 00083 00084 public String Call(string name, string method, params string[] args) 00085 { 00086 return SendRPC(name, method, args); 00087 } 00088 00089 public String CallBinary(string name, string method, out bool allOnes, params string[] args) 00090 { 00091 return SendRPCBinary(name, method, out allOnes, args); 00092 } 00093 00094 public String CallNoReply(string name, string method, params string[] args) 00095 { 00096 return SendRPCNoReply(name, method, args); 00097 } 00098 00099 public virtual void Connect(string name) 00100 { 00101 } 00102 00103 public virtual void Disconnect() 00104 { 00105 } 00106 00107 public virtual String[] ScanAvailablePortNames() 00108 { 00109 return null; 00110 } 00111 00112 public byte GetReturnValue_Byte() 00113 { 00114 return 0; 00115 } 00116 00117 public String GetReturnValue() 00118 { 00119 return ""; 00120 } 00121 00122 private String TrimArgument(String str) 00123 { 00124 String strOut = "0"; 00125 String strIn = str.TrimStart(new char[] { '0' }); 00126 if (String.IsNullOrEmpty(strIn) == false) 00127 { 00128 strOut = strIn; 00129 } 00130 return strOut; 00131 } 00132 00133 public String SendRPC(String Name, String Method, params String[] Args) 00134 { 00135 //write to serial port and receive result 00136 String Arguments = ""; 00137 00138 if (Args != null) 00139 { 00140 for (int i = 0; i < Args.Length; i++) 00141 { 00142 Arguments = Arguments + " " + TrimArgument(Args[i]); 00143 } 00144 } 00145 00146 String request = "/" + Name + "/" + Method + Arguments + "\r\n"; 00147 Console.WriteLine(request); 00148 String reply = RawRpcCall(request, true); 00149 00150 return reply; 00151 } 00152 00153 public String SendRPCNoReply(String Name, String Method, params String[] Args) 00154 { 00155 //write to serial port and receive result 00156 String Arguments = ""; 00157 00158 if (Args != null) 00159 { 00160 for (int i = 0; i < Args.Length; i++) 00161 { 00162 Arguments = Arguments + " " + Args[i]; 00163 } 00164 } 00165 00166 String request = "/" + Name + "/" + Method + Arguments + "\r\n"; 00167 String reply = RawRpcCall(request, false); 00168 00169 return reply; 00170 } 00171 00172 public String SendRPCBinary(String Name, String Method, out bool allOnes, params String[] Args) 00173 { 00174 //write to serial port and receive result 00175 String Arguments = ""; 00176 00177 if (Args != null) 00178 { 00179 for (int i = 0; i < Args.Length; i++) 00180 { 00181 Arguments = Arguments + " " + Args[i]; 00182 } 00183 } 00184 00185 String request = "/" + Name + "/" + Method + Arguments + "\r\n"; 00186 String reply = RawRpcCallBinary(request, false, out allOnes); 00187 00188 return reply; 00189 } 00190 00191 00192 public byte StringToByte(String reply) 00193 { 00194 byte val = 0xFF; 00195 if (byte.TryParse(reply, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val)) 00196 { 00197 } 00198 return val; 00199 } 00200 00201 00202 internal byte[] StringToMultiBytes(string reply, byte numBytes) 00203 { 00204 byte[] data = new Byte[numBytes]; 00205 string[] strings = reply.Split(new char[] { ' ' }); 00206 for (int i = 0; i < numBytes; i++) 00207 { 00208 data[i] = StringToByte(strings[i]); 00209 } 00210 return data; 00211 } 00212 00213 public abstract string ReadString(); 00214 public abstract int Read(char[] buffer, int offset, int count); 00215 } 00216 }
Generated on Thu Jul 28 2022 18:07:15 by
 1.7.2