/// <summary> /// Initialise the threads /// </summary> private void ConfigureThreads() { cameraSockets = new CameraSocket[config.CameraCount]; cameraThreads = new Thread[config.CameraCount]; threadConfiguration = new CameraThread[config.CameraCount]; for (int i = 0; i < config.CameraCount; i++) { //check that the camera is avalible cameraSockets[i] = new CameraSocket { DataSocket = new WSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), Config = config.Cameras[i] }; if (cameraSockets[i].Setup()) { Console.WriteLine("Connected to camera " + config.Cameras[i].Id + " assigning a thread"); CameraThread threadTask = new CameraThread(cameraSockets[i], savePath); threadConfiguration[i] = threadTask; cameraThreads[i] = new Thread(threadTask.Start); cameraThreads[i].Name = "CameraThread " + cameraSockets[i].Config.Id; cameraThreads[i].Start(); } else { Console.WriteLine("Failed to connect to camera " + config.Cameras[i].Id + "!!"); cameraSockets[i] = null; } } }
public void OnSocketPositionChanged(CameraSocket socket) { if (socket == this.socket) { transform.position = socket.transform.position; transform.rotation = socket.transform.rotation; } }
public void SetupTestException() { CameraSocket testSocket = new CameraSocket { DataSocket = new WSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), Config = new CameraConfiguration() }; bool threw = false; try { testSocket.Setup(); } catch (Exception e) { Assert.IsTrue(e is InvalidOperationException); Assert.IsTrue(e.Message.Equals("Configuration address not configured")); threw = true; } Assert.IsTrue(threw); threw = false; IPAddress address = NetworkHelpers.GrabIpv4(); testSocket.Config.Address = address.Address; try { testSocket.Setup(); } catch (Exception e) { Assert.IsTrue(e is InvalidOperationException); Assert.IsTrue(e.Message.Equals("Configuration port not configured")); threw = true; } Assert.IsTrue(threw); testSocket.Config.Port = 700; try { Assert.IsFalse(testSocket.Setup()); } catch (Exception) { Assert.Fail("Shouldn't throw an exception"); } }
//[Test] public void CameraThreadConnectionTest() { Thread camServer = new Thread(new Listener().StartListening); camServer.Name = "CameraServer"; camServer.Start(); CameraConfiguration testConfig = new CameraConfiguration { #pragma warning disable 618 Address = NetworkHelpers.GrabIpv4(Dns.GetHostEntry(Dns.GetHostName())).Address, #pragma warning restore 618 Port = 11003, CamFileIdentity = "testCam", Id = -1 }; CameraSocket testSocket = new CameraSocket { DataSocket = new WSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), Config = testConfig }; //start initialising the camera thread Assert.IsTrue(testSocket.Setup()); CameraThread threadTask = new CameraThread(testSocket); Thread camThread = new Thread(threadTask.Start); camThread.Name = "CameraThread"; camThread.Start(); //Tell the camera to send a test image threadTask.Request = CameraRequest.SendTestImage; Thread.Sleep(32); while (threadTask.Request != CameraRequest.Alive) { Thread.Sleep(10); } camThread.Join(); camServer.Join(); }
public void GetterSetterTest() { CameraSocket testCameraSocket = new CameraSocket(); #region socket Assert.IsNull(testCameraSocket.DataSocket); WSocket testSocket = new WSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); testCameraSocket.DataSocket = testSocket; Assert.IsTrue(testCameraSocket.DataSocket != null); Assert.IsTrue(testCameraSocket.DataSocket.Equals(testSocket)); ISocket testSocketget = testCameraSocket.DataSocket; Assert.IsTrue(testSocket.Equals(testSocketget)); #endregion #region config CameraConfiguration camConfigTest = new CameraConfiguration { Id = 233, CamFileIdentity = "superTest string" }; Assert.IsNull(testCameraSocket.Config); testCameraSocket.Config = camConfigTest; Assert.IsTrue(testCameraSocket.Config.Id == 233); Assert.IsTrue(testCameraSocket.Config.CamFileIdentity == "superTest string"); #endregion }
public CameraThread(CameraSocket socket, string saveLocation) { config = socket; connection = new SynchronousNet(socket.DataSocket); SavePath = saveLocation; }
public CameraThread(CameraSocket socket) { config = socket; connection = new SynchronousNet(socket.DataSocket); SavePath = Constants.DefualtHubSaveLocation(); }