Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using UnityEngine;
- using System.Collections;
- public class DJISimulatorReceiver : MonoBehaviour {
- private const int listenPort = 5566;
- bool done;
- UdpClient listener = null;
- IPEndPoint groupEP = null;
- string received_data;
- byte[] receive_byte_array;
- Thread receiveThread;
- void Start () {
- done = false;
- listener = new UdpClient(listenPort);
- groupEP = new IPEndPoint(IPAddress.Any, listenPort);
- receiveThread = new Thread(new ThreadStart(ReceiveData));
- receiveThread.IsBackground = true;
- receiveThread.Start();
- }
- void Update () {
- // TODO 2: UPDATE VIRTUAL DRONE's POSITION!!
- }
- void ReceiveData()
- {
- while(true)
- {
- try
- {
- receive_byte_array = listener.Receive(ref groupEP);
- received_data = Encoding.ASCII.GetString(receive_byte_array, 0, receive_byte_array.Length);
- Debug.Log(">>" + received_data);
- // TODO 1: RESEARCH HOW TO PROCESS received_data (JSON). FORMAT:
- // { “Roll”: 0.0, “Pitch”: 0.0, “Yaw”: 0.0, “WorldX”: 0.0, “WorldY”: 0.0, “WorldZ”: 0.0, “WorldLatitude”: 0.0, “WorldLongitude”: 0.0, “VelocityX”: 0.0, “VelocityY”: 0.0, “VelocityZ”: 0.0, “Time”: 0, “TransformState”: 0, “MotorStarted”: 0, “FlyingState”: 0 “ProductType”: 0, “SimulatorCommand”: 0 }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- }
- }
- void OnApplicationQuit()
- {
- listener.Close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement