public override void DeviceRemoved(AbstractDevice devrec) { if ((devrec is VarDevice) | (devrec is DateDevice) | (devrec is DelayDevice)) { devrec.UninitDevice(); } }
public DeviceClient(ClientConf clientConf, AbstractDevice device) { this.CheckClientConf(clientConf); this.clientConf = clientConf; this.deviceId = clientConf.DeviceId; this.connection = new MqttConnection(clientConf, this, this); this.device = device; this.rawMessageListenerDic = new Dictionary <string, RawMessageListener>(); }
public static void GetBusAndDevice(string name, out AbstractBus bus, out AbstractDevice device) { string[] pathParts = name.Split('_'); string busName = pathParts[1]; string deviceName = pathParts[2]; bus = App.Instance.FlightBusManager.GetBus(busName); device = (AbstractDevice)bus.GetItem(deviceName); }
public void AddConnectedDevice(AbstractDevice device) { bool reconnected = false; if (connectedDevicesByName.ContainsKey(device.GetDeviceName())) { connectedDevicesByName.Remove(device.GetDeviceName()); reconnected = true; } connectedDevicesByName.Add(device.GetDeviceName(), device); Debug.Log("Device " + device.GetDeviceName() + ((reconnected) ? " re" : " ") + "connected"); }
public VFSCore(AbstractDevice device) { this.device = device; this.deviceSize = device.Size(); // 初始化超级块 this.superBlock = SuperBlock.Load(this); if (IsFormated()) { loadBitmaps(); Console.WriteLine("载入镜像成功。"); Console.WriteLine("SuperBlock: {0}", superBlock.ToString()); } }
static void Main(string[] args) { Shop shop = new Shop(); Console.Write("Enter a device name, please: "); string deviceName = Console.ReadLine(); Console.WriteLine(); AbstractDevice device = shop.GetDevice(deviceName); device.GetDeviceInformation(); Console.ReadKey(); }
//界面以boardType,boardNo,channelType,channelCount来标识唯一性。 //core中bus,device等也应该包含这个几个属性,用它来标识唯一性 public static AbstractDevice GetSeletecedDevice(string boardName, string deviceName) { //获取当前选择的Bus AbstractBus bus = App.Instance.FlightBusManager.GetBus(boardName); //获取当前选择Device AbstractDevice selectedDevice = null; if (bus != null) { selectedDevice = (AbstractDevice)bus.GetItem(deviceName); } return(selectedDevice); }
private void OnExportBoardSetting(object o, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.RestoreDirectory = true; saveFileDialog.Filter = @"xml files(*.devcfg)|*.devcfg"; DialogResult result = saveFileDialog.ShowDialog(); if (result == DialogResult.OK) { string fileName = saveFileDialog.FileName; AbstractDevice selectedDevice = StaticMethods.GetSeletecedDevice(_busName, _deviceName); IParameter parameter = selectedDevice.Parameter; string content = SimpleSerializer.Serialize(parameter); File.WriteAllText(fileName, content); } }
private void OnImportBoardSetting(object o, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.RestoreDirectory = true; openFileDialog.Filter = @"xml files(*.devcfg)|*.devcfg"; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { string fileName = openFileDialog.FileName; if (File.Exists(fileName)) { string content = File.ReadAllText(fileName); AbstractDevice selectedDevice = StaticMethods.GetSeletecedDevice(_busName, _deviceName); IParameter parameter = selectedDevice.Parameter; IParameter para = SimpleSerializer.Deserialize(parameter.GetType(), content) as IParameter; parameter.UpdateParameter(para); } } }
protected override bool SendCommand(AbstractDevice devrec, string command, string[] cmdParams) { writeLog("Command: " + command); foreach (string param in cmdParams) { writeLog("Param: " + param); } if ( (devrec is VarDevice) | (devrec is DateDevice) | (devrec is DelayDevice) ) { if (devrec is DateDevice) { DateDevice device = devrec as DateDevice; switch (command) { case "CURRENT": device.tellServerDate(); break; default: break; } } else if (devrec is VarDevice) { VarDevice device = devrec as VarDevice; switch (command) { case "TOGGLE": device.toggle(); break; case "TURNON": device.turnOn(); break; case "TURNOFF": case "SETZERO": device.turnOff(); break; case "INCREMENT": device.increment(); break; case "DECREMENT": device.decrement(); break; default: break; } } else if (devrec is DelayDevice) { DelayDevice device = devrec as DelayDevice; switch (command) { case "START": device.start(); break; case "STOP": device.stop(); break; default: break; } } } return false; }
private void Window_Loaded(object sender, RoutedEventArgs e) { if (Properties.Settings.Default["vfsfile"] == null || ((String)(Properties.Settings.Default["vfsfile"])).Length == 0) { var r = System.Windows.Forms.MessageBox.Show("首次启动 VFS 需要在磁盘上建立一个虚拟磁盘镜像文件,镜像文件大小为 1GB。\n点击确定后请选择一个可以写入的位置来建立此文件,点击取消关闭程序。", "磁盘镜像文件未找到", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Information); if (r == System.Windows.Forms.DialogResult.Cancel) { Close(); return; } using (var dialog = new System.Windows.Forms.SaveFileDialog()) { dialog.Title = "保存磁盘镜像文件"; dialog.FileName = "vfs.bin"; var result = dialog.ShowDialog(); if (result == System.Windows.Forms.DialogResult.Cancel) { Close(); return; } else { try { device = new FileAdapter(dialog.FileName, 1 << 10 << 10 << 10); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("打开镜像文件失败,可能您没有权限在该位置写入文件,或您内存不足。程序即将退出,请重新打开程序。"); Close(); return; } // 更新配置 Properties.Settings.Default["vfsfile"] = dialog.FileName; Properties.Settings.Default.Save(); } } } else { device = new FileAdapter((String)Properties.Settings.Default["vfsfile"], 1 << 10 << 10 << 10); } vfs = new VFS(device); if (!vfs.IsFormated()) { var result = System.Windows.Forms.MessageBox.Show("该磁盘镜像文件尚未格式化,是否格式化?", "VFS", System.Windows.Forms.MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { Close(); return; } vfs.Format(device.Size() >> 10, 4); // 写入一个示例文件 var file = vfs.NewFile("/README.txt", VFS.FileMode.Create); file.Write(Encoding.UTF8.GetBytes("Hello world!\r\n\r\n这个文件是格式化时自动建立的,如果你看到了这个文件,说明一切工作正常。\r\n\r\n当你使用记事本修改这个文件并保存以后,它会同步到虚拟文件系统中。\r\n\r\n该虚拟文件系统是索引文件系统,inode 默认占总空间的 10%,理论可支持单一文件最大 2GB。")); System.Windows.Forms.MessageBox.Show("磁盘格式化成功!", "VFS", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); } LoadDirectory("/"); UpdateInfo(); }
public VFS(AbstractDevice device) { vfs = new VFSCore(device); }
public void RemoveDevice(AbstractDevice device) { connectedDevicesByName.Remove(device.GetDeviceName()); }
protected override bool SendCommand(AbstractDevice devrec, string command, string[] cmdParams) { writeLog("Command: " + command); foreach (string param in cmdParams) { writeLog("Param: " + param); } if ((devrec is VarDevice) | (devrec is DateDevice) | (devrec is DelayDevice)) { if (devrec is DateDevice) { DateDevice device = devrec as DateDevice; switch (command) { case "CURRENT": device.tellServerDate(); break; default: break; } } else if (devrec is VarDevice) { VarDevice device = devrec as VarDevice; switch (command) { case "TOGGLE": device.toggle(); break; case "TURNON": device.turnOn(); break; case "TURNOFF": case "SETZERO": device.turnOff(); break; case "INCREMENT": device.increment(); break; case "DECREMENT": device.decrement(); break; default: break; } } else if (devrec is DelayDevice) { DelayDevice device = devrec as DelayDevice; switch (command) { case "START": device.start(); break; case "STOP": device.stop(); break; default: break; } } } return(false); }
private void OnResetBoardSetting(object o, EventArgs e) { AbstractDevice selectedDevice = StaticMethods.GetSeletecedDevice(_busName, _deviceName); selectedDevice.ResetParamter(); }