//Event Handlers: private void HandleTriggerDown() { //stamp a cube in space: TransmissionObject spawn = Transmission.Spawn("SampleTransmissionObject", controlLocator.Position, controlLocator.Orientation, Vector3.one); _spawned.Add(spawn); }
public void Transmit(ushort address, byte[] data) { TransmissionObject xm = this.transmissionFactory.Create(data, 0); byte[] header_bytes = this.relay.TranmissionFormatter.GetHeaderBytes(xm); if (header_bytes != null) { this.SendRawBytes(address, header_bytes); } int total_byte_count = header_bytes?.Length ?? 0; foreach (TransmissionChunk chunk in xm.Chunks) { byte[] chunk_bytes = chunk.Pack().ToArray(); try { this.SendRawBytes(address, chunk_bytes); total_byte_count += chunk_bytes.Length; } catch (Exception e) { Console.WriteLine($"Failed at chunk {chunk.Header.ID} after {total_byte_count} bytes"); throw e; } } }
private void TryCompleteTransmission(uint id) { int header_index = this.headers.FindIndex(h => h.ID == id); if (header_index < 0) { return; } uint expected_packet_count = this.headers[header_index].PacketCount; IEnumerable <TransmissionChunk> packets = this.chunks.Where(p => p.Header.ObjectID == id); if (packets.Count() < expected_packet_count) { return; } // TODO 5/29/21: assert one of each sequential packet IDs exist TransmissionObject xm = new TransmissionObject(this.headers[header_index], packets); this.headers.RemoveAt(header_index); this.chunks.RemoveAll(p => p.Header.ObjectID == id); this.mutexTransmissions.WaitOne(); this.transmissions.Add(xm); this.mutexTransmissions.ReleaseMutex(); return; }
public byte[] ReceiveTransmission(uint id) { TransmissionObject xm = this.transmissionProcessor.WaitForTransmission(id); this.transmissionProcessor.RemoveTransmission(id); byte[] bytes = this.transmissionFactory.GetData(xm); return(bytes); }
// Start is called before the first frame update void Start() { //cubeColor = GetComponent<Material>(); for (int i = 0; i < 512; i++) { TransmissionObject _sampleCubeInstance = Transmission.Spawn("Transmission Cube", this.transform.position, Quaternion.identity, this.transform.lossyScale);//(GameObject)Instantiate(_cubePrefab); _sampleCubeInstance.transform.localPosition = this.transform.position; _sampleCubeInstance.transform.parent = this.transform; _sampleCubeInstance.name = "SampleCube" + i; this.transform.eulerAngles = new Vector3(0, 0, i * 10); _sampleCubeInstance.transform.position = Vector3.forward; cubes[i] = _sampleCubeInstance; } }
public TransmissionObject WaitForTransmission(uint id) { TransmissionObject desc = null; while (desc == null) { this.mutexTransmissions.WaitOne(); int index = this.transmissions.FindIndex(em => em.Header.ID == id); if (index > -1) { desc = this.transmissions[index]; this.transmissions.RemoveAt(index); } this.mutexTransmissions.ReleaseMutex(); } return(desc); }
//Init: private void Awake() { //hooks: controlLocator.events.OnTriggerDown.AddListener(HandleTriggerDown); controlLocator.events.OnBumperDown.AddListener(HandleBumperDown); //shared head locator: TransmissionObject headTransmissionObject = Transmission.Spawn("SampleTransmissionObject", Vector3.zero, Quaternion.identity, Vector3.one); headTransmissionObject.motionSource = Camera.main.transform; //shared controll locator: TransmissionObject controlTransmissionObject = Transmission.Spawn("SampleTransmissionObject", Vector3.zero, Quaternion.identity, Vector3.one); controlTransmissionObject.motionSource = controlLocator.transform; //sets: _initialInfo = info.text; }
void SpawnAndAttachToPCF(string resourceName, Vector3 objPosition, string pcfid, Vector3 pcfPosition, Quaternion pcfRotation) { // Create a helper game object for the PCF and hide it in the hierarchy var transformHelper = new GameObject("(TransformHelper)").transform; transformHelper.gameObject.hideFlags = HideFlags.HideInHierarchy; transformHelper.SetPositionAndRotation(pcfPosition, pcfRotation); // get the local coordinate system offset to the PCF for the game object we are about to create Vector3 positionOffset = transformHelper.InverseTransformPoint(objPosition); Quaternion rotationOffset = Quaternion.Inverse(transformHelper.rotation) * Quaternion.LookRotation(Vector3.forward); // Tell Transmission to spawn the game object everywhere on all peers on the network. // Note, this is a modified version of MLTK Transmission which specifies a PCF (as the last parameter) // if a PCF string is specified, the passed in position and rotation will be in local space to the PCF (or XRAnchor) specified by the pcfid TransmissionObject characterTransmissionObject = Transmission.Spawn(resourceName, positionOffset, rotationOffset, Vector3.one, pcfid); // save our copy in case we need to update it later attachedGameObjects.Add(characterTransmissionObject.gameObject); }
//Init: private void Awake() { //hooks: controlLocator.OnTriggerDown.AddListener(HandleTriggerDown); controlLocator.OnBumperDown.AddListener(HandleBumperDown); controlLocator.OnTouchDown.AddListener(HandleTouchDown); Transmission.Instance.OnStringMessage.AddListener(HandleStringMessage); //shared head locator: TransmissionObject headTransmissionObject = Transmission.Spawn("SampleTransmissionObject", Vector3.zero, Quaternion.identity, Vector3.one); headTransmissionObject.motionSource = Camera.main.transform; _headRenderer = headTransmissionObject.GetComponentInChildren <Renderer>(); //shared control locator: TransmissionObject controlTransmissionObject = Transmission.Spawn("SampleTransmissionObject", Vector3.zero, Quaternion.identity, Vector3.one); controlTransmissionObject.motionSource = controlLocator.transform; _controlRenderer = controlTransmissionObject.GetComponentInChildren <Renderer>(); //sets: _initialInfo = info.text; }
public void ScrambleAndTransmit() { int expected_byte_count = 1000; uint expected_object_id = 5; byte[] raw_bytes = new byte[expected_byte_count]; for (int i = 0; i < expected_byte_count; i++) { raw_bytes[i] = (byte)i; } using (RelayController ctrl_send = RelayController.ConnectSerial("COM4")) { using (RelayController ctrl_rcv = RelayController.ConnectSerial("COM6")) { ctrl_send.Clear(); ulong long_address = 0x0013A20041B764AD; ushort short_address = ctrl_send.Discover(long_address); // receive "Discover" emission List <byte> rcv_bytes = ctrl_rcv.ReceiveBytes(); Assert.AreEqual("Discover".Length, rcv_bytes.Count); // send actual data try { TransmissionObject xm = transmissionFactory.Create(raw_bytes, expected_object_id); byte[] header_bytes = xm.Header.Pack().ToArray(); ctrl_send.SendRawBytes(short_address, header_bytes); int total_byte_count = header_bytes.Length; Random rnd = new Random(); IEnumerable <TransmissionChunk> chunks = xm.Chunks.OrderBy(c => rnd.Next()); foreach (TransmissionChunk chunk in chunks) { byte[] packet_bytes = chunk.Pack().ToArray(); try { ctrl_send.SendRawBytes(short_address, packet_bytes); total_byte_count += packet_bytes.Length; } catch (Exception e) { Console.WriteLine($"Failed at packet {chunk.Header.ID} after {total_byte_count} bytes"); throw e; } } } catch { // ignored Console.WriteLine("Transmission failed"); } List <EmissionDescriptor> emissions = ctrl_send.GetAllEmissions(); foreach (EmissionDescriptor descriptor in emissions) { Console.WriteLine($"Unused emission with frame type {descriptor.Header.FrameType}"); } // receive actual data byte[] rcv_data_bytes = ctrl_rcv.ReceiveTransmission(expected_object_id); Assert.AreEqual(expected_byte_count, rcv_data_bytes.Length); for (int i = 0; i < expected_byte_count; i++) { Assert.AreEqual(raw_bytes[i], rcv_data_bytes[i]); } } } }