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
RPCClient.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.Pipelines; 00041 using RPCSupport.Devices; 00042 using RPCSupport.Dialogs; 00043 00044 namespace RPCSupport 00045 { 00046 public class RPCClient 00047 { 00048 public enum ePipeline 00049 { 00050 eHid, 00051 eSerial, 00052 eHttp, 00053 eSerialWrap 00054 } 00055 00056 //SerialPipeline serialPipeline; 00057 const string SPINAME = "Spi"; 00058 I2cDevice i2cDevice; 00059 SpiDevice spiDevice; 00060 bool rpcLogShown = false; 00061 public RPCSupport.Streaming.Streaming streaming; 00062 00063 public Pipeline pipeline; 00064 00065 public Pipeline Pipeline 00066 { 00067 get { return pipeline; } 00068 } 00069 00070 LIS2HD lis2hd; 00071 public LIS2HD LIS2HD 00072 { 00073 get { return lis2hd; } 00074 set { lis2hd = value; } 00075 } 00076 00077 public I2cDevice I2cDevice 00078 { 00079 get { return i2cDevice; } 00080 set { i2cDevice = value; } 00081 } 00082 public SpiDevice SpiDevice 00083 { 00084 get { return spiDevice; } 00085 set { spiDevice = value; } 00086 } 00087 00088 MAX30101 max30101; 00089 public MAX30101 MAX30101 00090 { 00091 get { return max30101; } 00092 set { max30101 = value; } 00093 } 00094 00095 MAX30001 max30001; 00096 public MAX30001 MAX30001 00097 { 00098 get { return max30001; } 00099 set { max30001 = value; } 00100 } 00101 00102 MAX30205 max30205; 00103 public MAX30205 MAX30205 00104 { 00105 get { return max30205; } 00106 set { max30205 = value; } 00107 } 00108 00109 DataLogging.DataLogging dataLogging; 00110 public DataLogging.DataLogging DataLogging 00111 { 00112 get { return dataLogging; } 00113 set { dataLogging = value; } 00114 } 00115 00116 Devices.Led led; 00117 public Devices.Led Led 00118 { 00119 get { return led; } 00120 set { led = value; } 00121 } 00122 00123 Devices.Testing testing; 00124 public Devices.Testing Testing 00125 { 00126 get { return testing; } 00127 set { testing = value; } 00128 } 00129 00130 Devices.S25FS512 s25FS512; 00131 public Devices.S25FS512 S25FS512 00132 { 00133 get { return s25FS512; } 00134 set { s25FS512 = value; } 00135 } 00136 00137 public RPCClient(ePipeline pipelineType) 00138 { 00139 switch (pipelineType) 00140 { 00141 case ePipeline.eHid: 00142 pipeline = new HidPipeline(); 00143 break; 00144 case ePipeline.eSerial: 00145 pipeline = new SerialPipeline(); 00146 break; 00147 case ePipeline.eHttp: 00148 break; 00149 case ePipeline.eSerialWrap: 00150 pipeline = new SerialWrapPipeline(); 00151 break; 00152 } 00153 ShowRpcLog(false); 00154 LogCallback(new RPCSupport.Pipelines.Pipeline.RawRpcRequest(LogRpcRequest), new RPCSupport.Pipelines.Pipeline.RawRpcReply(LogRpcReply), new RPCSupport.Pipelines.Pipeline.RawRpcStream(LogRpcStream)); 00155 streaming = new Streaming.Streaming(); 00156 } 00157 00158 void LogRpcRequest(string request) 00159 { 00160 rpcLog.LogRpcRequest(request); 00161 } 00162 00163 void LogRpcReply(string reply) 00164 { 00165 rpcLog.LogRpcReply(reply); 00166 } 00167 00168 void LogRpcStream(string stream) 00169 { 00170 rpcLog.LogRpcStream(stream); 00171 } 00172 00173 public void LogCallback(RPCSupport.Pipelines.Pipeline.RawRpcRequest request, RPCSupport.Pipelines.Pipeline.RawRpcReply reply, RPCSupport.Pipelines.Pipeline.RawRpcStream stream) 00174 { 00175 pipeline.LogCallback(request, reply, stream); 00176 } 00177 00178 public void Connect(string param) { 00179 pipeline.Connect(param); 00180 } 00181 00182 public void Disconnect() 00183 { 00184 pipeline.Disconnect(); 00185 } 00186 00187 public string[] ScanAvailablePortNames() { 00188 return pipeline.ScanAvailablePortNames(); 00189 } 00190 00191 public bool InitPipeline() 00192 { 00193 bool ret = pipeline.Init(); 00194 return ret; 00195 } 00196 00197 public bool IsConnected() 00198 { 00199 return pipeline.IsConnected(); 00200 } 00201 00202 public String RawRpcCall(String request, bool reply) 00203 { 00204 return pipeline.RawRpcCall(request, reply); 00205 } 00206 00207 public Devices.MAX30101 Init_MAX30101(int slaveAddress) 00208 { 00209 MAX30101 = new RPCSupport.Devices.MAX30101(this, slaveAddress); 00210 return MAX30101; 00211 } 00212 00213 public Devices.MAX30001 Init_MAX30001() 00214 { 00215 MAX30001 = new RPCSupport.Devices.MAX30001(this); 00216 return MAX30001; 00217 } 00218 00219 public Devices.MAX30205 Init_MAX30205(int slaveAddress) 00220 { 00221 MAX30205 = new RPCSupport.Devices.MAX30205(this, slaveAddress); 00222 return MAX30205; 00223 } 00224 00225 public Devices.LIS2HD Init_LIS2HD(int slaveAddress) 00226 { 00227 LIS2HD = new RPCSupport.Devices.LIS2HD(this, slaveAddress); 00228 return LIS2HD; 00229 } 00230 00231 public Devices.I2cDevice Init_I2cDevice() 00232 { 00233 I2cDevice = new RPCSupport.Devices.I2cDevice(this); 00234 return I2cDevice; 00235 } 00236 00237 public Devices.SpiDevice Init_SpiDevice() 00238 { 00239 SpiDevice = new RPCSupport.Devices.SpiDevice(this); 00240 return SpiDevice; 00241 } 00242 00243 public DataLogging.DataLogging Init_Logging() 00244 { 00245 dataLogging = new RPCSupport.DataLogging.DataLogging(this); 00246 return dataLogging; 00247 } 00248 00249 public RPCSupport.Devices.Led Init_Led() 00250 { 00251 led = new RPCSupport.Devices.Led(this); 00252 return led; 00253 } 00254 00255 public RPCSupport.Devices.Testing Init_Testing() 00256 { 00257 testing = new RPCSupport.Devices.Testing(this); 00258 return testing; 00259 } 00260 00261 public RPCSupport.Devices.S25FS512 Init_S25FS512() 00262 { 00263 s25FS512 = new RPCSupport.Devices.S25FS512(this); 00264 return s25FS512; 00265 } 00266 00267 00268 public void ReadRegister(DeviceSupport.DeviceDetails deviceDetails, DeviceSupport.RegisterInfo reg) 00269 { 00270 int hex; 00271 00272 switch (deviceDetails.type) 00273 { 00274 case DeviceSupport.DeviceDetails.eType.eI2c: 00275 i2cDevice.ReadReg(deviceDetails, reg); 00276 break; 00277 case DeviceSupport.DeviceDetails.eType.eSpi: 00278 spiDevice.ReadReg(deviceDetails, reg); 00279 break; 00280 case DeviceSupport.DeviceDetails.eType.eMAX30001: 00281 //reg.data[0] = max30001.ReadReg((byte)reg.address); 00282 hex = max30001.ReadReg((byte)reg.address); 00283 reg.data[0] = (hex >> 16) & 0xFF; 00284 reg.data[1] = (hex >> 8) & 0xFF; 00285 reg.data[2] = hex & 0xFF; 00286 break; 00287 case DeviceSupport.DeviceDetails.eType.eMAX30205: 00288 //reg.data[0] = max30001.ReadReg((byte)reg.address); 00289 hex = max30205.ReadReg((byte)reg.address); 00290 reg.data[0] = (hex >> 8) & 0xFF; 00291 reg.data[1] = hex & 0xFF; 00292 break; 00293 } 00294 } 00295 00296 public void WriteRegister(DeviceSupport.DeviceDetails deviceDetails, DeviceSupport.RegisterInfo reg) 00297 { 00298 switch (deviceDetails.type) 00299 { 00300 case DeviceSupport.DeviceDetails.eType.eI2c: 00301 i2cDevice.WriteReg(deviceDetails, reg); 00302 break; 00303 case DeviceSupport.DeviceDetails.eType.eSpi: 00304 spiDevice.WriteReg(deviceDetails, reg); 00305 break; 00306 case DeviceSupport.DeviceDetails.eType.eMAX30001: 00307 //max30001.WriteReg((byte)reg.address, reg.data[0]); 00308 max30001.WriteReg((byte)reg.address, reg.data[2] | reg.data[1] << 8 | reg.data[0] << 16); 00309 break; 00310 case DeviceSupport.DeviceDetails.eType.eMAX30205: 00311 max30001.WriteReg((byte)reg.address, reg.data[1] | reg.data[0] << 8); 00312 break; 00313 } 00314 } 00315 00316 RpcLog rpcLog; 00317 public void ShowRpcLog(bool state) 00318 { 00319 if (rpcLog == null) 00320 { 00321 rpcLog = new RpcLog(); 00322 } 00323 rpcLogShown = state; 00324 if (state == true) 00325 rpcLog.Show(); 00326 else 00327 rpcLog.Hide(); 00328 } 00329 00330 public bool IsRpcLogShown() 00331 { 00332 return rpcLogShown; 00333 } 00334 00335 public string Version() 00336 { 00337 return RawRpcCall("/System/ReadVer\r\n", true); 00338 } 00339 } 00340 }
Generated on Thu Jul 28 2022 18:07:15 by
1.7.2