public static bool ShowBox(Window parent, BLE_DataType dataType, ScriptItem cmdItem) { BLECmdEdit win = new BLECmdEdit(parent, dataType, cmdItem); win.ShowDialog(); return(win.saveItem); }
public static string ToStr(this BLE_DataType dataType) { return(dataType switch { BLE_DataType.Bool => "Bool", BLE_DataType.UInt_2bit => "UInt2", BLE_DataType.UInt_4bit => "UInt4", BLE_DataType.UInt_8bit => "UInt8", BLE_DataType.UInt_12bit => "UInt12", BLE_DataType.UInt_16bit => "UInt16", BLE_DataType.UInt_24bit => "UInt24", BLE_DataType.UInt_32bit => "UInt32", BLE_DataType.UInt_48bit => "UInt48", BLE_DataType.UInt_64bit => "UInt64", BLE_DataType.UInt_128bit => "UInt128", BLE_DataType.Int_8bit => "Int8", BLE_DataType.Int_12bit => "Int12", BLE_DataType.Int_16bit => "Int16", BLE_DataType.Int_24bit => "Int24", BLE_DataType.Int_32bit => "Int32", BLE_DataType.Int_48bit => "Int48", BLE_DataType.Int_64bit => "Int64", BLE_DataType.Int_128bit => "Int128", BLE_DataType.IEEE_754_32bit_floating_point => "Float32", BLE_DataType.IEEE_754_64bit_floating_point => "Float64", BLE_DataType.IEEE_11073_16bit_SFLOAT => "Float16", BLE_DataType.IEEE_11073_32bit_FLOAT => "Float32", BLE_DataType.IEEE_20601_format => "TwoUInt16", BLE_DataType.UTF8_String => "UTF8 String", BLE_DataType.UTF16_String => "UTF 16 String (Unicode)", BLE_DataType.OpaqueStructure => "OpaqueStructure - Not Handled", _ => string.Format("{0} - Not handled", dataType.ToString()), });
public DataTypeDisplay(BLE_DataType dataType, string min, string max) { this.DataTypeEnum = dataType; this.DataType = dataType.ToStr().UnderlineToSpaces(); this.Min = min; this.Max = max; }
public BLECommandSetDataModel( List <ScriptItem> scripts, string characteristicName, BLE_DataType dataType, string display) : this(scripts) { this.CharacteristicName = characteristicName; this.DataType = dataType; this.Display = display; }
public void CreateBLECmds(string display, BLE_DataType dataType, List <ScriptItem> items, Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, "Failure on CreateBLEBoolDemoCmds", () => { BLECommandSetDataModel dm = new BLECommandSetDataModel(items, "", dataType, display); this.CreateBLECmdSet( dm.Display, dm, new BLECmdIndexExtraInfo(dm), idx => onSuccess(), onError); }); }
private BLECommandsEdit(Window parent, IIndexItem <BLECmdIndexExtraInfo> index, UseType useType, BLE_DataType dataType) { this.parent = parent; this.index = index; this.useType = useType; this.dataType = dataType; InitializeComponent(); this.Init(); this.widthManager = new ButtonGroupSizeSyncManager(this.btnCancel, this.btnOk); this.widthManager.PrepForChange(); this.SizeToContent = SizeToContent.WidthAndHeight; }
public void BLE_GetShortRangeDisplay(BLE_DataType dataType, Action <string> onSuccess, OnErr onError) { try { DataTypeDisplay display = this.validator.GetRange(dataType); onSuccess( string.Format("{0}, {1}: {2}, {3}: {4}", display.DataType, this.GetText(MsgCode.Min), display.Min, this.GetText(MsgCode.Max), display.Max)); } catch (Exception e) { this.log.Exception(9999, "", e); WrapErr.SafeAction(() => { onError.Invoke(this.GetText(MsgCode.UnhandledError)); }); } }
private BLECmdEdit(Window parent, BLE_DataType dataType, ScriptItem cmdItem) { this.parent = parent; this.dataType = dataType; this.cmdItem = cmdItem; InitializeComponent(); if (this.dataType == BLE_DataType.UInt_32bit) { this.grdValueCol.MinWidth = 320; } DI.Wrapper.BLE_GetShortRangeDisplay( this.dataType, str => this.txtRange.Content = str, this.onFailure); this.widthManager = new ButtonGroupSizeSyncManager(this.btnCancel, this.btnOk); this.widthManager.PrepForChange(); this.Setup(); this.SizeToContent = SizeToContent.WidthAndHeight; }
public void ValidateBLECmdItem(BLE_DataType dataType, ScriptItem item, Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (item.Display.Length > 0) { this.ValidateBLEValue(dataType, item.Command, onSuccess, onError); } else { onError.Invoke(this.GetText(MsgCode.EmptyName)); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.UnknownError)); } }
public static DataTypeDisplay GetRange(BLE_DataType dataType) { DataTypeDisplay result = WrapErr.ToErrReport(out ErrReport report, 9999, () => string.Format("Failure retrieving range for data type:{0}", dataType), () => { return(dataType switch { BLE_DataType.Bool => new DataTypeDisplay(BLE_DataType.Bool, "0", "1"), BLE_DataType.UInt_2bit => new DataTypeDisplay(BLE_DataType.UInt_2bit, "0", "3"), BLE_DataType.UInt_4bit => new DataTypeDisplay(BLE_DataType.UInt_4bit, "0", "15"), BLE_DataType.UInt_8bit => new DataTypeDisplay(BLE_DataType.UInt_8bit, Byte.MinValue.ToString(), Byte.MaxValue.ToString()), BLE_DataType.UInt_12bit => new DataTypeDisplay(BLE_DataType.UInt_12bit, "0", "4095"), BLE_DataType.UInt_16bit => new DataTypeDisplay(BLE_DataType.UInt_16bit, UInt16.MinValue.ToString(), UInt16.MaxValue.ToString()), BLE_DataType.UInt_24bit => new DataTypeDisplay(BLE_DataType.UInt_24bit, "0", "16777215"), BLE_DataType.UInt_32bit => new DataTypeDisplay(BLE_DataType.UInt_32bit, UInt32.MinValue.ToString(), UInt32.MaxValue.ToString()), BLE_DataType.UInt_48bit => new DataTypeDisplay(BLE_DataType.UInt_48bit, "0", "281474976710655"), BLE_DataType.UInt_64bit => new DataTypeDisplay(BLE_DataType.UInt_64bit, UInt64.MinValue.ToString(), UInt64.MaxValue.ToString()), BLE_DataType.UInt_128bit => new DataTypeDisplay(BLE_DataType.UInt_128bit, "0", "340282366920938463463374607431768211455"), BLE_DataType.Int_8bit => new DataTypeDisplay(BLE_DataType.Int_8bit, SByte.MinValue.ToString(), SByte.MaxValue.ToString()), BLE_DataType.Int_12bit => new DataTypeDisplay(BLE_DataType.Int_12bit, "-2048", "2047"), BLE_DataType.Int_16bit => new DataTypeDisplay(BLE_DataType.Int_16bit, Int16.MinValue.ToString(), Int16.MaxValue.ToString()), BLE_DataType.Int_24bit => new DataTypeDisplay(BLE_DataType.Int_24bit, "-8388608", "8388607"), BLE_DataType.Int_32bit => new DataTypeDisplay(BLE_DataType.Int_32bit, Int32.MinValue.ToString(), Int32.MaxValue.ToString()), BLE_DataType.Int_48bit => new DataTypeDisplay(BLE_DataType.Int_48bit, "-140737488355328", "140737488355327"), BLE_DataType.Int_64bit => new DataTypeDisplay(BLE_DataType.Int_64bit, Int64.MinValue.ToString(), Int64.MaxValue.ToString()), BLE_DataType.Int_128bit => new DataTypeDisplay(BLE_DataType.Int_128bit, "-170141183460469231731687303715884105728", "170141183460469231731687303715884105727"), BLE_DataType.IEEE_754_32bit_floating_point => new DataTypeDisplay(BLE_DataType.IEEE_754_32bit_floating_point, Single.MinValue.ToString(), Single.MaxValue.ToString()), BLE_DataType.IEEE_754_64bit_floating_point => new DataTypeDisplay(BLE_DataType.IEEE_754_64bit_floating_point, Double.MinValue.ToString(), Double.MaxValue.ToString()), BLE_DataType.IEEE_11073_16bit_SFLOAT => new DataTypeDisplay(BLE_DataType.IEEE_11073_16bit_SFLOAT, "0", "0"), // Require some bit shifting. TBD BLE_DataType.IEEE_11073_32bit_FLOAT => new DataTypeDisplay(BLE_DataType.IEEE_11073_32bit_FLOAT, "0", "0"), // Require some bit shifting. TBD BLE_DataType.IEEE_20601_format => new DataTypeDisplay( BLE_DataType.IEEE_20601_format, string.Format("{0}|{0}", UInt16.MinValue), string.Format("{0}|{0}", UInt16.MaxValue)), // this is 2 Uint16 in one Uint32 block need to handle both pieces as UINT16 BLE_DataType.UTF8_String => new DataTypeDisplay(BLE_DataType.UTF8_String, "1", "VAR"), BLE_DataType.UTF16_String => new DataTypeDisplay(BLE_DataType.UTF16_String, "1", "VAR"), BLE_DataType.Reserved0x00 => new DataTypeDisplay(BLE_DataType.Reserved0x00, "0", "0"), _ => new DataTypeDisplay(BLE_DataType.Unhandled, "0", "0"), }); });
public void ValidateBLEValue(BLE_DataType dataType, string command, Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { this.log.Info("", () => string.Format("Validate:{0} '{1}'", dataType.ToStr(), command)); RangeValidationResult result = this.bleRangeValidator.Validate(command, dataType); if (result.Status == BLE_DataValidationStatus.Success) { onSuccess.Invoke(); } else { onError.Invoke(this.Translate(result)); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.UnknownError)); } }
public void GetFilteredBLECmdList( BLE_DataType dataType, string characteristic, Action <List <IIndexItem <BLECmdIndexExtraInfo> >, List <IIndexItem <BLECmdIndexExtraInfo> > > onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, "Failure on GetFilteredBLECmdList", () => { this.RetrieveIndex( this.bleCmdStorage, (idx) => { List <IIndexItem <BLECmdIndexExtraInfo> > generalResult = new List <IIndexItem <BLECmdIndexExtraInfo> >(); List <IIndexItem <BLECmdIndexExtraInfo> > specificResult = new List <IIndexItem <BLECmdIndexExtraInfo> >(); if (idx.Count > 0) { foreach (var item in idx) { if (item.ExtraInfoObj.DataType == dataType) { generalResult.Add(item); if (!string.IsNullOrWhiteSpace(characteristic) && item.ExtraInfoObj.CharacteristicName == characteristic) { specificResult.Add(item); } } } } onSuccess.Invoke(generalResult, specificResult); }, onError); }); if (report.Code != 0) { WrapErr.SafeAction(() => onError(this.GetText(MsgCode.UnknownError))); } }
GetFilteredCommandList(string name, BLE_DataType dataType, int generalCount, int specificCount) { List <IIndexItem <BLECmdIndexExtraInfo> > general = null; List <IIndexItem <BLECmdIndexExtraInfo> > specific = null; string error = string.Empty; TDI.Wrapper.GetFilteredBLECmdList( dataType, name, (ndxG, ndxS) => { general = ndxG; specific = ndxS; }, (err) => { error = err; }); Assert.AreEqual(string.Empty, error); Assert.NotNull(general); Assert.NotNull(specific); Assert.AreEqual(generalCount, general.Count, string.Format("{0} GetFilteredCommandList general index count", dataType)); Assert.AreEqual(specificCount, specific.Count, string.Format("{0} GetFilteredCommandList Specific index count", dataType)); return(new Tuple <List <IIndexItem <BLECmdIndexExtraInfo> >, List <IIndexItem <BLECmdIndexExtraInfo> > >(general, specific)); }
public void Update(BLECommandSetDataModel dm) { this.CharacteristicName = dm.CharacteristicName; this.DataTypeDisplay = dm.DataType.ToStr(); this.DataType = dm.DataType; }
private IIndexItem <BLECmdIndexExtraInfo> CreateItem(List <ScriptItem> items, string characteristicName, BLE_DataType dataType, string display, string errExpected) { IIndexItem <BLECmdIndexExtraInfo> index = null; string error = string.Empty; BLECommandSetDataModel dm = new BLECommandSetDataModel( items, characteristicName, dataType, display); TDI.Wrapper.CreateBLECmdSet(dm.Display, dm, new BLECmdIndexExtraInfo(dm), (ndx) => { index = ndx; }, (err) => { error = err; }); Assert.AreEqual(errExpected, error); //Assert.NotNull(index, "Did not return index"); return(index); }
public static void ShowBox(Window parent, BLE_DataType dataType) { BLECommandsEdit win = new BLECommandsEdit(parent, null, UseType.New, dataType); win.ShowDialog(); }