internal static byte[] ControllerHeader(Command cmd, ScopeController ctrl, int address, int length, byte[] data = null) { // 1 byte controller // 2 bytes address // 2 bytes length byte[] res; int len = 5; if (data != null) { len += length; } res = cmd.msgHeader(len); int offset = HDR_SZ; res[offset++] = (byte)ctrl; res[offset++] = (byte)(address); res[offset++] = (byte)(address >> 8); res[offset++] = (byte)(length); res[offset++] = (byte)(length >> 8); if (data != null) { Buffer.BlockCopy(data, 0, res, offset, length); } return(res); }
public void SetControllerRegister(ScopeController ctrl, uint address, byte[] data) { if (data != null && data.Length > I2C_MAX_WRITE_LENGTH) { int offset = 0; if (ctrl != ScopeController.AWG) { //Chop up in smaller chunks int bytesLeft = data.Length; while (bytesLeft > 0) { int length = bytesLeft > I2C_MAX_WRITE_LENGTH ? I2C_MAX_WRITE_LENGTH : bytesLeft; byte[] newData = new byte[length]; Array.Copy(data, offset, newData, 0, length); SetControllerRegister(ctrl, (uint)(address + offset), newData); offset += length; bytesLeft -= length; } return; } byte[] toSend = new byte[32]; //Begin I2C - send start condition usb.WriteControlBytes(UsbCommandHeader(ctrl, Operation.WRITE_BEGIN, address, 0), false); while (offset < data.Length) { int length = Math.Min(data.Length - offset, I2C_MAX_WRITE_LENGTH_BULK); byte[] header = UsbCommandHeader(ctrl, Operation.WRITE_BODY, address, (uint)length); Array.Copy(header, toSend, header.Length); Array.Copy(data, offset, toSend, header.Length, length); usb.WriteControlBytes(toSend, false); offset += length; } usb.WriteControlBytes(UsbCommandHeader(ctrl, Operation.WRITE_END, address, 0), false); } else { uint length = data != null ? (uint)data.Length : 0; byte[] header = UsbCommandHeader(ctrl, Operation.WRITE, address, length); //Paste header and data together and send it byte[] toSend = new byte[header.Length + length]; Array.Copy(header, toSend, header.Length); if (length > 0) { Array.Copy(data, 0, toSend, header.Length, data.Length); } usb.WriteControlBytes(toSend, false); } }
public void Start() { _scopePool = new ObjectPool(() => Manager.CreateScope(false, false).gameObject); _canTakeInput = GetComponent <CanTakeInput>(); _finalScope = Manager.CreateScope(false, true); _energy = GetComponent <HasEnergy>(); _character = GetComponent <Character>(); _canTakeInput.SwitchedOff += InputTurnedOff; if (Manager.Instance.Debug) { _hasEverShot = true; } }
internal static void ParseControllerHeader(byte[] buffer, out ScopeController ctrl, out int address, out int length, out byte[] data) { ctrl = (ScopeController)buffer[0]; address = buffer[1] + (buffer[2] << 8); length = buffer[3] + (buffer[4] << 8); int dataLength = buffer.Length - 5; if (dataLength > 0) { data = new byte[dataLength]; Buffer.BlockCopy(buffer, 5, data, 0, dataLength); } else { data = null; } }
public void GetControllerRegister(ScopeController ctrl, uint address, uint length, out byte[] data) { //In case of FPGA (I2C), first write address we're gonna read from to FPGA //FIXME: this should be handled by the PIC firmware if (ctrl == ScopeController.FPGA) { SetControllerRegister(ctrl, address, null); } if (ctrl == ScopeController.FLASH && (address + length) > (FLASH_USER_ADDRESS_MASK + 1)) { throw new ScopeIOException(String.Format("Can't read flash rom beyond 0x{0:X8}", FLASH_USER_ADDRESS_MASK)); } byte[] header = UsbCommandHeader(ctrl, Operation.READ, address, length); usb.WriteControlBytes(header, false); //EP3 always contains 16 bytes xxx should be linked to constant //FIXME: use endpoint length or so, or don't pass the argument to the function byte[] readback = ReadControlBytes(16); if (readback == null) { data = null; LabNation.Common.Logger.Error("Failde to read back bytes"); return; } int readHeaderLength; if (ctrl == ScopeController.FLASH) { readHeaderLength = 5; } else { readHeaderLength = 4; } //strip away first 4 bytes as these are not data data = new byte[length]; Array.Copy(readback, readHeaderLength, data, 0, length); }
public static void SetControllerRegister(this ISmartScopeUsbInterface i, ScopeController ctrl, uint address, byte[] data) { if (data != null && data.Length > I2C_MAX_WRITE_LENGTH) { if (ctrl != ScopeController.AWG) { throw new Exception(String.Format("Can't do writes of this length ({0}) to controller {1:G}", data.Length, ctrl)); } int offset = 0; byte[] toSend = new byte[32]; //Begin I2C - send start condition i.WriteControlBytes(UsbCommandHeader(ctrl, Operation.WRITE_BEGIN, address, 0), false); while (offset < data.Length) { int length = Math.Min(data.Length - offset, I2C_MAX_WRITE_LENGTH_BULK); byte[] header = UsbCommandHeader(ctrl, Operation.WRITE_BODY, address, (uint)length); Array.Copy(header, toSend, header.Length); Array.Copy(data, offset, toSend, header.Length, length); i.WriteControlBytes(toSend, false); offset += length; } i.WriteControlBytes(UsbCommandHeader(ctrl, Operation.WRITE_END, address, 0), false); } else { uint length = data != null ? (uint)data.Length : 0; byte[] header = UsbCommandHeader(ctrl, Operation.WRITE, address, length); //Paste header and data together and send it byte[] toSend = new byte[header.Length + length]; Array.Copy(header, toSend, header.Length); if (length > 0) { Array.Copy(data, 0, toSend, header.Length, data.Length); } i.WriteControlBytes(toSend, false); } }
public static void SetControllerRegister(this ISmartScopeUsbInterface i, ScopeController ctrl, uint address, byte[] data) { if (data != null && data.Length > I2C_MAX_WRITE_LENGTH) { if (ctrl != ScopeController.AWG) throw new Exception(String.Format("Can't do writes of this length ({0}) to controller {1:G}", data.Length, ctrl)); int offset = 0; byte[] toSend = new byte[32]; //Begin I2C - send start condition i.WriteControlBytes(UsbCommandHeader(ctrl, Operation.WRITE_BEGIN, address, 0), false); while (offset < data.Length) { int length = Math.Min(data.Length - offset, I2C_MAX_WRITE_LENGTH_BULK); byte[] header = UsbCommandHeader(ctrl, Operation.WRITE_BODY, address, (uint)length); Array.Copy(header, toSend, header.Length); Array.Copy(data, offset, toSend, header.Length, length); i.WriteControlBytes(toSend, false); offset += length; } i.WriteControlBytes(UsbCommandHeader(ctrl, Operation.WRITE_END, address, 0), false); } else { uint length = data != null ? (uint)data.Length : 0; byte[] header = UsbCommandHeader(ctrl, Operation.WRITE, address, length); //Paste header and data together and send it byte[] toSend = new byte[header.Length + length]; Array.Copy(header, toSend, header.Length); if (length > 0) Array.Copy(data, 0, toSend, header.Length, data.Length); i.WriteControlBytes(toSend, false); } }
public static void GetControllerRegister(this ISmartScopeUsbInterface i, ScopeController ctrl, uint address, uint length, out byte[] data) { //In case of FPGA (I2C), first write address we're gonna read from to FPGA //FIXME: this should be handled by the PIC firmware if (ctrl == ScopeController.FPGA || ctrl == ScopeController.FPGA_ROM) i.SetControllerRegister(ctrl, address, null); if (ctrl == ScopeController.FLASH && (address + length) > (FLASH_USER_ADDRESS_MASK + 1)) { throw new ScopeIOException(String.Format("Can't read flash rom beyond 0x{0:X8}", FLASH_USER_ADDRESS_MASK)); } byte[] header = UsbCommandHeader(ctrl, Operation.READ, address, length); i.WriteControlBytes(header, false); //EP3 always contains 16 bytes xxx should be linked to constant //FIXME: use endpoint length or so, or don't pass the argument to the function byte[] readback = i.ReadControlBytes(16); if(readback == null) { data = null; LabNation.Common.Logger.Error("Failde to read back bytes"); return; } int readHeaderLength; if (ctrl == ScopeController.FLASH) readHeaderLength = 5; else readHeaderLength = 4; //strip away first 4 bytes as these are not data data = new byte[length]; Array.Copy(readback, readHeaderLength, data, 0, length); }
public static byte[] UsbCommandHeader(ScopeController ctrl, Operation op, uint address, uint length) { byte[] header = null; if (ctrl == ScopeController.PIC) { if (op == Operation.WRITE) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.PIC_WRITE, (byte)(address), (byte)(length) //first I2C byte: FPGA i2c address (5) + '0' as LSB, indicating write operation }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.PIC_READ, (byte)(address), (byte)(length) //first I2C byte: FPGA i2c address (5) + '0' as LSB, indicating write operation }; } } else if (ctrl == ScopeController.ROM) { if (op == Operation.WRITE) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.EEPROM_WRITE, (byte)(address), (byte)(length) }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.EEPROM_READ, (byte)(address), (byte)(length) }; } } else if (ctrl == ScopeController.FLASH) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.FLASH_ROM_WRITE, (byte)(address), (byte)(length), (byte)(address >> 8), }; } else if (op == Operation.READ) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.FLASH_ROM_READ, (byte)(address), (byte)(length), (byte)(address >> 8), }; } } else if (ctrl == ScopeController.FPGA) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE, (byte)(length + 2), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA (byte)(FPGA_I2C_ADDRESS_SETTINGS << 1), //first I2C byte: FPGA i2c address bit shifted and LSB 0 indicating write (byte)address //second I2C byte: address of the register inside the FPGA }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_READ, (byte)(FPGA_I2C_ADDRESS_SETTINGS), //first I2C byte: FPGA i2c address bit shifted and LSB 1 indicating read (byte)(length) }; } } else if (ctrl == ScopeController.FPGA_ROM) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE, (byte)(length + 2), (byte)((FPGA_I2C_ADDRESS_ROM << 1) + 0), //first I2C byte: FPGA i2c address bit shifted and LSB 1 indicating read (byte)address, }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_READ, (byte)(FPGA_I2C_ADDRESS_ROM), //first I2C byte: FPGA i2c address, not bitshifted (byte)(length) }; } } else if (ctrl == ScopeController.AWG) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE, (byte)(length + 2), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA (byte)(FPGA_I2C_ADDRESS_AWG << 1), //first I2C byte: FPGA i2c address bit shifted and LSB 0 indicating write (byte)address //second I2C byte: address of the register inside the FPGA }; } if (op == Operation.WRITE_BEGIN) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_START, (byte)(length + 2), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA (byte)(FPGA_I2C_ADDRESS_AWG << 1), //first I2C byte: FPGA i2c address bit shifted and LSB 0 indicating write (byte)address //second I2C byte: address of the register inside the FPGA }; } if (op == Operation.WRITE_BODY) { header = new byte[3] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_BULK, (byte)(length), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA }; } if (op == Operation.WRITE_END) { header = new byte[3] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_STOP, (byte)(length) }; } else if (op == Operation.READ) { throw new Exception("Can't read out AWG"); } } return header; }
private static byte[] UsbCommandHeader(ScopeController ctrl, Operation op, uint address, uint length) { byte[] header = null; if (ctrl == ScopeController.PIC) { if (op == Operation.WRITE) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.PIC_WRITE, (byte)(address), (byte)(length) //first I2C byte: FPGA i2c address (5) + '0' as LSB, indicating write operation }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.PIC_READ, (byte)(address), (byte)(length) //first I2C byte: FPGA i2c address (5) + '0' as LSB, indicating write operation }; } } else if (ctrl == ScopeController.ROM) { if (op == Operation.WRITE) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.EEPROM_WRITE, (byte)(address), (byte)(length) }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.EEPROM_READ, (byte)(address), (byte)(length) }; } } else if (ctrl == ScopeController.FLASH) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.FLASH_ROM_WRITE, (byte)(address), (byte)(length), (byte)(address >> 8), }; } else if (op == Operation.READ) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.FLASH_ROM_READ, (byte)(address), (byte)(length), (byte)(address >> 8), }; } } else if (ctrl == ScopeController.FPGA) // Generic FPGA I2C operation { //Address contains both device address and register address // A[0:7] = reg addr // A[7:14] = device address header = UsbCommandHeaderI2c((byte)((address >> 8) & 0x7F), op, (byte)(address & 0xFF), length); } else if (ctrl == ScopeController.AWG) { if (op == Operation.WRITE) { header = UsbCommandHeaderI2c(FPGA_I2C_ADDRESS_AWG, op, address, length); } if (op == Operation.WRITE_BEGIN) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_START, (byte)(length + 2), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA (byte)(FPGA_I2C_ADDRESS_AWG << 1), //first I2C byte: FPGA i2c address bit shifted and LSB 0 indicating write (byte)address //second I2C byte: address of the register inside the FPGA }; } if (op == Operation.WRITE_BODY) { header = new byte[3] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_BULK, (byte)(length), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA }; } if (op == Operation.WRITE_END) { header = new byte[3] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_STOP, (byte)(length) }; } else if (op == Operation.READ) { throw new Exception("Can't read out AWG"); } } return(header); }
public static byte[] UsbCommandHeader(ScopeController ctrl, Operation op, uint address, uint length) { byte[] header = null; if (ctrl == ScopeController.PIC) { if (op == Operation.WRITE) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.PIC_WRITE, (byte)(address), (byte)(length) //first I2C byte: FPGA i2c address (5) + '0' as LSB, indicating write operation }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.PIC_READ, (byte)(address), (byte)(length) //first I2C byte: FPGA i2c address (5) + '0' as LSB, indicating write operation }; } } else if (ctrl == ScopeController.ROM) { if (op == Operation.WRITE) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.EEPROM_WRITE, (byte)(address), (byte)(length) }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.EEPROM_READ, (byte)(address), (byte)(length) }; } } else if (ctrl == ScopeController.FLASH) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.FLASH_ROM_WRITE, (byte)(address), (byte)(length), (byte)(address >> 8), }; } else if (op == Operation.READ) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.FLASH_ROM_READ, (byte)(address), (byte)(length), (byte)(address >> 8), }; } } else if (ctrl == ScopeController.FPGA) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE, (byte)(length + 2), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA (byte)(FPGA_I2C_ADDRESS_SETTINGS << 1), //first I2C byte: FPGA i2c address bit shifted and LSB 0 indicating write (byte)address //second I2C byte: address of the register inside the FPGA }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_READ, (byte)(FPGA_I2C_ADDRESS_SETTINGS), //first I2C byte: FPGA i2c address bit shifted and LSB 1 indicating read (byte)(length) }; } } else if (ctrl == ScopeController.FPGA_ROM) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE, (byte)(length + 2), (byte)((FPGA_I2C_ADDRESS_ROM << 1) + 0), //first I2C byte: FPGA i2c address bit shifted and LSB 1 indicating read (byte)address, }; } else if (op == Operation.READ) { header = new byte[4] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_READ, (byte)(FPGA_I2C_ADDRESS_ROM), //first I2C byte: FPGA i2c address, not bitshifted (byte)(length) }; } } else if (ctrl == ScopeController.AWG) { if (op == Operation.WRITE) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE, (byte)(length + 2), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA (byte)(FPGA_I2C_ADDRESS_AWG << 1), //first I2C byte: FPGA i2c address bit shifted and LSB 0 indicating write (byte)address //second I2C byte: address of the register inside the FPGA }; } if (op == Operation.WRITE_BEGIN) { header = new byte[5] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_START, (byte)(length + 2), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA (byte)(FPGA_I2C_ADDRESS_AWG << 1), //first I2C byte: FPGA i2c address bit shifted and LSB 0 indicating write (byte)address //second I2C byte: address of the register inside the FPGA }; } if (op == Operation.WRITE_BODY) { header = new byte[3] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_BULK, (byte)(length), //data and 2 more bytes: the FPGA I2C address, and the register address inside the FPGA }; } if (op == Operation.WRITE_END) { header = new byte[3] { HEADER_CMD_BYTE, (byte)PIC_COMMANDS.I2C_WRITE_STOP, (byte)(length) }; } else if (op == Operation.READ) { throw new Exception("Can't read out AWG"); } } return(header); }
void PrepareDataLists() { // Populate all hard-coded combo-box values. cbOpticType.Items.Clear(); foreach (var item in Enum.GetValues(typeof(Optic.OpticTypes))) { cbOpticType.Items.Add(item); } cbScopeMountType.Items.Clear(); foreach (var item in Enum.GetValues(typeof(Scope.MountTypes))) { cbScopeMountType.Items.Add(item); } cbSiteLongtitudeType.Items.Clear(); foreach (var item in Enum.GetValues(typeof(Site.LongtitudeTypes))) { cbSiteLongtitudeType.Items.Add(item); } cbSiteLatitudeType.Items.Clear(); foreach (var item in Enum.GetValues(typeof(Site.LatitudeTypes))) { cbSiteLatitudeType.Items.Add(item); } // Query database for all values. listCameras = CameraController.GetCameras(); listCatalogues = CatalogueController.GetCatalogues(); listColorSpaces = ColorSpaceController.GetColorSpaces(); listFileFormats = FileFormatController.GetFileFormats(); listOptics = OpticsController.GetOptics(); listPhotographers = PhotographerController.GetPhotographers(); listScopes = ScopeController.GetScopes(); listSites = SiteController.GetSites(); // Populate list boxes. lbCameras.Items.Clear(); foreach (var item in listCameras) { lbCameras.Items.Add(item.Id + " " + item.LongName + " " + (item.MaxResolution.Width * item.MaxResolution.Height / 1000000).ToString() + "MP"); } lbCatalogues.Items.Clear(); foreach (var item in listCatalogues) { lbCatalogues.Items.Add(item.Id + " " + item.LongName); } lbColorSpaces.Items.Clear(); foreach (var item in listColorSpaces) { lbColorSpaces.Items.Add(item.Id + " " + item.Name); } lbFileFormats.Items.Clear(); foreach (var item in listFileFormats) { lbFileFormats.Items.Add(item.Id + " " + item.LongName); } lbOptics.Items.Clear(); foreach (var item in listOptics) { lbOptics.Items.Add(item.Id + " " + item.Value + " " + item.OpticType.ToString()); } lbPhotographers.Items.Clear(); foreach (var item in listPhotographers) { lbPhotographers.Items.Add(item.Id + " " + item.LastName + ", " + item.FirstName); } lbScopes.Items.Clear(); foreach (var item in listScopes) { lbScopes.Items.Add(item.Id + " " + item.Manufacturer + " " + item.Name); } lbSites.Items.Clear(); foreach (var item in listSites) { lbSites.Items.Add(item.Id + " " + item.Name); } // Populate specific database fields for every tab. cbCamerasColorSpaces.Items.Clear(); foreach (var item in listColorSpaces) { cbCamerasColorSpaces.Items.Add(item.Name); } }
public void SetControllerRegister(ScopeController ctrl, uint address, byte[] data) { Request(Net.Net.ControllerHeader(Net.Net.Command.SET, ctrl, (int)address, data.Length, data)); }
public void GetControllerRegister(ScopeController ctrl, uint address, uint length, out byte[] data) { data = Request(Net.Net.ControllerHeader(Net.Net.Command.GET, ctrl, (int)address, (int)length, null)); }
// Scopes private void btnScopesSave_Click(object sender, EventArgs e) { // Valiations: // TODO check for valid float values if (tbScopeManufacturer.Text.Length == 0) { errorProvider.SetError(tbScopeManufacturer, "Must provide a value."); } else { errorProvider.SetError(tbScopeManufacturer, ""); } if (tbScopeName.Text.Length == 0) { errorProvider.SetError(tbScopeName, "Must provide a value."); } else { errorProvider.SetError(tbScopeName, ""); } if (tbScopeAperture.Text.Length == 0) { errorProvider.SetError(tbScopeAperture, "Must provide a value."); } else { errorProvider.SetError(tbScopeAperture, ""); } if (tbScopeFocalLength.Text.Length == 0) { errorProvider.SetError(tbScopeFocalLength, "Must provide a value."); } else { errorProvider.SetError(tbScopeFocalLength, ""); } if (tbScopeCentralObstructionDiameter.Text.Length == 0) { errorProvider.SetError(tbScopeCentralObstructionDiameter, "Must provide a value."); } else { errorProvider.SetError(tbScopeCentralObstructionDiameter, ""); } if (!rbScopeRoboticYes.Checked && !rbScopeRoboticNo.Checked) { errorProvider.SetError(rbScopeRoboticNo, "Must provide a value."); } else { errorProvider.SetError(rbScopeRoboticNo, ""); } if (cbScopeMountType.SelectedIndex == -1) { errorProvider.SetError(cbScopeMountType, "Must provide a value."); } else { errorProvider.SetError(cbScopeMountType, ""); } // Save new/changes: int id = 0; string manufacturer = tbScopeManufacturer.Text; string name = tbScopeName.Text; float aperture = float.Parse(tbScopeAperture.Text); float focalLength = float.Parse(tbScopeFocalLength.Text); float centralObstructionDiameter = float.Parse(tbScopeCentralObstructionDiameter.Text); bool robotic = rbScopeRoboticYes.Checked; Scope.MountTypes mountType = (Scope.MountTypes)cbScopeMountType.SelectedIndex; if (emScopes == EditingModes.Add) { id = 0; } else { id = currentScope.Id; } Scope candidate = new Scope(id, manufacturer, name, aperture, focalLength, centralObstructionDiameter, robotic, mountType); if (emScopes == EditingModes.Add) { id = ScopeController.AddScope(candidate); } else { ScopeController.EditScope(id, candidate); } // Reload data: lblStatus.Text = "Issuing scopes saving command... "; currentScope = ScopeController.GetScopes(new List <int>() { id })[0]; LoadScopeData(currentScope); PrepareDataLists(); lblStatus.Text += "Complete."; }
public static void Main(string[] args) { //load settings Settings settings = Settings.Load(); if (settings == null) { Console.WriteLine("Invalid settings - check the Settings.json file"); Console.ReadKey(); return; } settings.Save(); //prepare storage FileBasedControllerStorage controllerStorage = new FileBasedControllerStorage(); FileBasedFirmwareStorage firmwareStorage = new FileBasedFirmwareStorage(); MemoryBasedLedStorage ledStorage = new MemoryBasedLedStorage(); FileBasedGroupStorage groupStorage = new FileBasedGroupStorage(); //initialize storage controllerStorage.Initialize(settings.ControllerPath); firmwareStorage.Initialize(settings.FirmwarePath); ledStorage.Initialize(); groupStorage.Initialize(settings.GroupPath); //initialize business logic (handlers) ControllerHandler controllerHandler = new ControllerHandler(controllerStorage, groupStorage, ledStorage); FirmwareHandler firmwareHandler = new FirmwareHandler(firmwareStorage, settings); LedHandler ledHandler = new LedHandler(ledStorage, controllerStorage); GroupHandler groupHandler = new GroupHandler(groupStorage, ledStorage); TrunkEndpoint trunkEndpoint = new TrunkEndpoint(controllerStorage, ledStorage); //initialize API endpoints (controllers) BaseController baseController = new BaseController(settings.Oauth); ControllerController controllerController = new ControllerController(controllerHandler); ControllerTrunk controllerTrunk = new ControllerTrunk(trunkEndpoint); FirmwareController firmwareController = new FirmwareController(firmwareHandler); LedController ledController = new LedController(ledHandler); GroupController groupController = new GroupController(groupHandler); //initialize web server HttpService service = new DefaultHttpSysService(false, "+", settings.ServerPort); service.AddController(baseController, settings.Multithreaded); service.AddController(controllerController, settings.Multithreaded); service.AddController(controllerTrunk, "Trunk", true); service.AddController(firmwareController, settings.Multithreaded); service.AddController(ledController, settings.Multithreaded); service.AddController(groupController, settings.Multithreaded); //service.GetProcessorPostManipulation(DefaultHttpSysService.INTERNAL_PROCESSING_GROUP).Add(new OptionsPayloadInjector("OptionsInjector")); //if OAuth is enabled... if (settings.Oauth) { //prepare OAuth storage ClientAccountFileStorage clientStorage = new ClientAccountFileStorage(); UserAccountFileStorage userStorage = new UserAccountFileStorage(); RefreshTokenFileStorage refreshTokenStorage = new RefreshTokenFileStorage(); //initialize oauth storage clientStorage.Initialize(settings.ClientPath); refreshTokenStorage.Initialize(settings.RefreshTokenPath); userStorage.Initialize(settings.UserPath); //prepare OAuth core OAuth2 oauth = new OAuth2("fwehnvd3432nfre7r834nfsfiu43kmvrew!"); oauth.ClientCredentialsAuthorization = new ClientCredentialsAuthorization(oauth, clientStorage); oauth.PasswordAuthorization = new PasswordAuthorization(oauth, clientStorage, userStorage); oauth.RefreshTokenAuthorization = new RefreshTokenAuthorization(oauth, clientStorage, userStorage, refreshTokenStorage); service.GetProcessorPreManipulation(false).Add(new CustomizedAccessTokenValidator(oauth.AccessTokenValidator)); //prepare OAuth Webkit IScopeHandler scopeHandler = new ScopeHandler(service, oauth); IClientHandler clientHandler = new ClientHandler(clientStorage); IUserHandler userHandler = new UserHandler(clientStorage, userStorage); //initialize API endpoints (controllers) for OAuth + Webkit service.AddController(new AuthController(oauth)); service.AddController(new ClientController(clientHandler)); service.AddController(new ScopeController(scopeHandler)); service.AddController(new UserController(userHandler)); //assign scopes to OAuth Webkit API endpoints ClientController.AssignScopesToEndpoints(skotstein.app.ledserver.tools.Scopes.AUTH_CLIENT_READ, skotstein.app.ledserver.tools.Scopes.AUTH_CLIENT_WRITE, oauth); ScopeController.AssignScopeToEndpoint(skotstein.app.ledserver.tools.Scopes.AUTH_SCOPE_READ, oauth); UserController.AssignScopesToEndpoints(skotstein.app.ledserver.tools.Scopes.AUTH_USER_READ, skotstein.app.ledserver.tools.Scopes.AUTH_USER_WRITE, oauth); } //generate YAML file OpenApiDocumentBuilder documentBuilder = new OpenApiDocumentBuilder(); OpenApiDocument document = documentBuilder.Build("V1"); if (settings.Oauth) { document = documentBuilder.AddSecuritySchema(document, new List <HttpController> { baseController, controllerController, groupController, ledController, firmwareController }, /*@"http://*****:*****@"http://localhost:4000/api/v1/auth/token"); } string json = documentBuilder.AsJson(document); json = documentBuilder.Replace(json, new ExampleValues()); json = documentBuilder.Replace(json, new HostValue("http://*****:*****@".\OpenApi.json", json); //start server Console.WriteLine(service.Routes); service.Start(); Console.WriteLine("Service is listening on port:" + settings.ServerPort); if (settings.Oauth) { Console.WriteLine("OAuth 2.0 is enabled"); Console.WriteLine("Access Token URL: POST " + restlayer.ApiBase.API_V1 + "/auth/token"); } else { Console.WriteLine("OAuth 2.0 is disabled"); } Console.WriteLine("Press key to terminate"); Console.ReadKey(); }
private void ClearData() { listCameras = CameraController.GetCameras(); listCatalogues = CatalogueController.GetCatalogues(); listColorSpaces = ColorSpaceController.GetColorSpaces(); listFileFormats = FileFormatController.GetFileFormats(); listOptics = OpticsController.GetOptics(); listPhotographers = PhotographerController.GetPhotographers(); listScopes = ScopeController.GetScopes(); listSites = SiteController.GetSites(); tbCollectionId.Text = "(adding)"; tbDateTime.Text = ""; tbComments.Text = ""; tbFile.Text = ""; tbMetadataFile.Text = ""; tbObjectId.Text = ""; tbObjectTitle.Text = ""; tbResolutionX.Text = ""; tbResolutionY.Text = ""; tbTotalFrames.Value = 1; cbCamera.Items.Clear(); foreach (var item in listCameras) { cbCamera.Items.Add(item.LongName); } cbCatalogue.Items.Clear(); foreach (var item in listCatalogues) { cbCatalogue.Items.Add(item.LongName); } cbColorSpace.Items.Clear(); foreach (var item in listColorSpaces) { cbColorSpace.Items.Add(item.Name); } cbFileFormat.Items.Clear(); foreach (var item in listFileFormats) { cbFileFormat.Items.Add(item.LongName); } cbPhotographer.Items.Clear(); foreach (var item in listPhotographers) { cbPhotographer.Items.Add(item.GetInformalName()); } cbScope.Items.Clear(); foreach (var item in listScopes) { cbScope.Items.Add(item.GetScopeName()); } clbOptics.Items.Clear(); foreach (var item in listOptics) { clbOptics.Items.Add(item.Id + "| " + item.GetOpticName()); } cbSite.Items.Clear(); foreach (var item in listSites) { cbSite.Items.Add(item.Name); } lblStatus.Text = "Loaded all assets."; }