public async Task SaveEeprom(byte[] eeprom) { var chunk = new byte[32]; var chunks = eeprom.Length / chunk.Length; var offset = 0; var wasOpen = false; ExceptionDispatchInfo capturedException = null; try { wasOpen = Serial.IsOpen; Serial.OpenPort(); for (var chunkN = 0; chunkN < chunks; chunkN++) { Buffer.BlockCopy(eeprom, offset, chunk, 0, chunk.Length); var res = await Serial.JsonCommand(CBTCommand.SaveEeprom(chunkN, chunk)); if (!res.ContainsKey("result") || res["result"] != "success") { throw new Exception("Error saving EEPROM."); } offset += chunk.Length; } } catch (Exception ex) { capturedException = ExceptionDispatchInfo.Capture(ex); } if (Serial.IsOpen && !wasOpen) { await Serial.ClosePort(); } capturedException?.Throw(); }
public async Task SetCanMode(int bus, CanMode mode) { var res = await Serial.JsonCommand(CBTCommand.SetCanMode(bus, mode)); if (!res.ContainsKey("mode") || res["mode"] != Enum.GetName(typeof(CanMode), mode)) { throw new Exception("Error changing CAN mode."); } }
public async Task SleepTimerToggle(bool activate) { await Serial.BlindCommand(CBTCommand.SleepTimer(activate)); }
public async Task EnableBluetoothPassthrough(bool enabled = true) { await Serial.BlindCommand(CBTCommand.BluetoothPassthrough(enabled)); }
public async Task SetBluetoothMsgFilter(int bus, bool enabled, int msgFilter1 = 0, int msgFilter2 = 0) { await Serial.BlindCommand(CBTCommand.BluettothFilter(bus, enabled, msgFilter1, msgFilter2)); }
public async Task <bool> EnableLogWithMask(int bus, int msgFilter1, int mask1, int msgFilter2 = 0, int mask2 = 0) { return(await Serial.OkCommand(CBTCommand.BusLogMask(bus, msgFilter1, mask1, msgFilter2, mask2))); }
public async Task <bool> EnableLog(int bus, int msgFilter1 = 0, int msgFilter2 = 0) { return(await Serial.OkCommand(CBTCommand.BusLog(bus, true, msgFilter1, msgFilter2))); }
public async Task <bool> DisableLog(int bus) { return(await Serial.OkCommand(CBTCommand.BusLog(bus, false))); }
public async Task SendCanPacket(CanMessage msg) { await Serial.BlindCommand(CBTCommand.CanPacket(msg)); }
public async Task <CanMode> GetCanMode(int bus) { var res = await Serial.JsonCommand(CBTCommand.GetCanMode(bus)); return(res.ContainsKey("mode")? (CanMode)Enum.Parse(typeof(CanMode), res["mode"], true) : CanMode.Unknown); }
public async Task <Dictionary <string, string> > GetBusStatus(int bus) { return(await Serial.JsonCommand(CBTCommand.BusStatus(bus))); }
public async Task <Dictionary <string, string> > SetBaudRate(int bus, int baud) { return(await Serial.JsonCommand(CBTCommand.BitRate(bus, baud))); }
public async Task <Dictionary <string, string> > AutoBaudRate(int bus) { return(await Serial.JsonCommand(CBTCommand.AutoBaudRate(bus))); }