public override async Task ConnectAsync() { // don't do this again if we're already connected :O if (Connected) { return; } var protocolInfo = await commandClient.GetAsAsync <ProtocolInformation>("get_protocol_info"); this.instanceProtocolVersion = protocolInfo.GetProtocolVersion(); this.SensorInformation = await FetchConfigObject <BasicSensorInformation>(); this.SensorCapabilities = await FetchConfigObject <SensorCapabilitiesInformation>(); this.EthernetConfiguration = await FetchConfigObject <EthernetConfigurationInformation>(); this.MeasurementConfiguration = await FetchConfigObject <MeasuringConfigurationInformation>(); // start the periodical fetching if required if (fetchStatusInterval > 0) { this.fetchStatusCts = new CancellationTokenSource(); this.fetchStatusThread = new Thread(ThreadFetchStatusPeriodically); this.fetchStatusThread.Start(); } // Note: well... yes this is somewhat stupid, but hey(!) we managed to talk with // the R2000, so everything's fine and dandy this.connected = true; }
public R2000ParameterInfoAttribute( R2000ParameterType parameterAccessType, R2000ProtocolVersion minVersion = R2000ProtocolVersion.Any, R2000ProtocolVersion maxVersion = R2000ProtocolVersion.Any) { this.AccessType = parameterAccessType; this.MinProtocolVersion = minVersion; this.MaxProtocolVersion = maxVersion; }
public TCPConnector( HttpClient httpc, IPAddress address, bool enableWatchdog = true, int watchdogTimeout = 10000, R2000ProtocolVersion protocolVersion = R2000ProtocolVersion.v100) { this.observers = new List <IObserver <ScanFramePoint> >(); this.statusObservers = new List <IObserver <LidarStatusEvent> >(); this.httpClient = httpc; this.r2000IpAddress = address; this.watchdogEnabled = enableWatchdog; this.watchdogTimeout = watchdogTimeout; this.protocolVersion = protocolVersion; }
/// <summary> /// Get the list of "R2000 parameters" in this type /// </summary> /// <param name="type"></param> /// <returns></returns> public static string[] GetR2000ParametersList( this Type type, R2000ProtocolVersion protocolVersion, R2000ParameterType accessorTypes = R2000ParameterType.All) { var fieldNames = type.GetRuntimeProperties() // get only fields where we find a R2000ParameterTypeAttribute with the required filter .Where(field => { var parameterTypeAttribute = field.GetCustomAttributes <R2000ParameterInfoAttribute>(); if (!parameterTypeAttribute.Any()) { return(false); } var accessorsOk = parameterTypeAttribute.All(x => accessorTypes.HasFlag(x.AccessType)); var minVersionOk = parameterTypeAttribute.All(x => x.MinProtocolVersion == R2000ProtocolVersion.Any || x.MinProtocolVersion <= protocolVersion); var maxVersionOk = parameterTypeAttribute.All(x => x.MaxProtocolVersion == R2000ProtocolVersion.Any || x.MaxProtocolVersion >= protocolVersion); return(accessorsOk && minVersionOk && maxVersionOk); }) // select either the JsonProperty.PropertyName or the Fields true name as fallback .Select(field => { var jsonAttribute = field.GetCustomAttribute <JsonPropertyAttribute>(); if (jsonAttribute != null) { return(jsonAttribute.PropertyName); } else { return(field.Name); } }); return(fieldNames.ToArray()); }