Skip to content

Commit

Permalink
Merge pull request #25 from lge-ros2/develop
Browse files Browse the repository at this point in the history
Merge 'develop' branch into 'master'
  • Loading branch information
hyunseok-yang authored Aug 14, 2020
2 parents df99163 + bbf3e02 commit ccb1630
Show file tree
Hide file tree
Showing 29 changed files with 705 additions and 620 deletions.
18 changes: 14 additions & 4 deletions Assets/Scripts/DevicePlugins/CameraPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,23 @@ private void Response()
var requestMessage = ParsingCameraInfoRequest(ref memoryStreamForCameraInfo, receivedBuffer);

// Debug.Log(subPartName + receivedString);
if (requestMessage != null && requestMessage.Name.Equals("request_camera_info"))
if (requestMessage != null)
{
var cameraInfoMessage = cam.GetCameraInfo();
switch (requestMessage.Name)
{
case "request_camera_info":

SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage);
var cameraInfoMessage = cam.GetCameraInfo();

SendResponse(memoryStreamForCameraInfo);
SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage);

SendResponse(memoryStreamForCameraInfo);

break;

default:
break;
}
}
}
}
Expand Down
172 changes: 83 additions & 89 deletions Assets/Scripts/DevicePlugins/ElevatorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,11 @@ public ElevatorTask(in int index)
private const int NON_ELEVATOR_INDEX = -1;

private bool isRunningThread = true;
private MemoryStream memoryStreamForService = null;
private Param responseMessage = null;
private Dictionary<string, float> floorList;
private Dictionary<int, ElevatorEntity> elevatorList;
private ConcurrentQueue<ElevatorTask> elevatorTaskQueue;

ElevatorSystem()
{
memoryStreamForService = new MemoryStream();
responseMessage = new Param();
floorList = new Dictionary<string, float>();
elevatorList = new Dictionary<int, ElevatorEntity>();
elevatorTaskQueue = new ConcurrentQueue<ElevatorTask>();
}
private MemoryStream memoryStreamForService = new MemoryStream();
private Param responseMessage = new Param();
private Dictionary<string, float> floorList = new Dictionary<string, float>();
private Dictionary<int, ElevatorEntity> elevatorList = new Dictionary<int, ElevatorEntity>();
private ConcurrentQueue<ElevatorTask> elevatorTaskQueue = new ConcurrentQueue<ElevatorTask>();

protected override void OnAwake()
{
Expand Down Expand Up @@ -220,34 +211,34 @@ public string GetFloorName(in float targetFloorHeight)
private void GenerateResponseMessage()
{
var serviceNameParam = new Param
{
Name = "service_name",
Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty }
};
{
Name = "service_name",
Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty }
};

var resultParam = new Param
{
Name = "result",
Value = new Any { Type = Any.ValueType.Boolean, BoolValue = false }
};
{
Name = "result",
Value = new Any { Type = Any.ValueType.Boolean, BoolValue = false }
};

var elevatorIndexParam = new Param
{
Name = "elevator_index",
Value = new Any { Type = Any.ValueType.Int32, IntValue = NON_ELEVATOR_INDEX }
};
{
Name = "elevator_index",
Value = new Any { Type = Any.ValueType.Int32, IntValue = NON_ELEVATOR_INDEX }
};

var floorParam = new Param
{
Name = "current_floor",
Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty }
};
{
Name = "current_floor",
Value = new Any { Type = Any.ValueType.String, StringValue = string.Empty }
};

var heightParam = new Param
{
Name = "height",
Value = new Any { Type = Any.ValueType.Double, DoubleValue = 0 }
};
{
Name = "height",
Value = new Any { Type = Any.ValueType.Double, DoubleValue = 0 }
};

responseMessage.Name = string.Empty;
responseMessage.Childrens.Add(serviceNameParam);
Expand Down Expand Up @@ -350,47 +341,49 @@ private MemoryStream HandleServiceRequest(in Param receivedMessage)

private void HandleService(in string serviceName, string currentFloor, in string targetFloor, int elevatorIndex)
{
var result = true;
var result = false;
var height = 0f;

if (serviceName.Equals("call_elevator"))
{
elevatorIndex = NON_ELEVATOR_INDEX;
result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex);
if (!result)
{
result = CallElevator(currentFloor, targetFloor);
}
}
else if (serviceName.Equals("get_called_elevator"))
{
result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex);
}
else if (serviceName.Equals("select_elevator_floor"))
{
result = SelectElevatorFloor(elevatorIndex, targetFloor, currentFloor);
}
else if (serviceName.Equals("request_door_open"))
{
result = RequestDoorOpen(elevatorIndex);
}
else if (serviceName.Equals("request_door_close"))
switch (serviceName)
{
result = RequestDoorClose(elevatorIndex);
}
else if (serviceName.Equals("is_door_opened"))
{
result = IsElevatorDoorOpened(elevatorIndex);
}
else if (serviceName.Equals("get_elevator_information"))
{
height = GetElevatorCurrentHeight(elevatorIndex);
currentFloor = GetFloorName(height);
}
else
{
Debug.LogError("Unkown service name: " + serviceName);
result = false;
case "call_elevator":
elevatorIndex = NON_ELEVATOR_INDEX;
result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex);
if (!result)
{
result = CallElevator(currentFloor, targetFloor);
}
break;

case "get_called_elevator":
result = GetCalledElevator(currentFloor, targetFloor, out elevatorIndex);
break;

case "select_elevator_floor":
result = SelectElevatorFloor(elevatorIndex, targetFloor, currentFloor);
break;

case "request_door_open":
result = RequestDoorOpen(elevatorIndex);
break;

case "request_door_close":
result = RequestDoorClose(elevatorIndex);
break;

case "is_door_opened":
result = IsElevatorDoorOpened(elevatorIndex);
break;

case "get_elevator_information":
result = true;
height = GetElevatorCurrentHeight(elevatorIndex);
currentFloor = GetFloorName(height);
break;

default:
Debug.LogError("Unkown service name: " + serviceName);
break;
}

SetResponseMessage(result, elevatorIndex, currentFloor, height);
Expand All @@ -407,24 +400,25 @@ private IEnumerator ServiceLoop()

if (elevatorTaskQueue.TryDequeue(out var task))
{
// Trigger service
if (task.state.Equals(ElevatorTaskState.DOOR_OPEN))
{
DoServiceOpenDoor(ref task);
}
else if (task.state.Equals(ElevatorTaskState.DOOR_CLOSE))
{
DoServiceCloseDoor(ref task);
}
else if (task.state.Equals(ElevatorTaskState.STANDBY))
{
DoServiceInStandby(ref task);
}

// handling service
if (task.state.Equals(ElevatorTaskState.PROCESSING))
switch (task.state)
{
DoServiceInProcess(ref task);
// Trigger service
case ElevatorTaskState.DOOR_OPEN:
DoServiceOpenDoor(ref task);
break;

case ElevatorTaskState.DOOR_CLOSE:
DoServiceCloseDoor(ref task);
break;

case ElevatorTaskState.STANDBY:
DoServiceInStandby(ref task);
break;

// handling service
case ElevatorTaskState.PROCESSING:
DoServiceInProcess(ref task);
break;
}

// finishing service
Expand Down
25 changes: 17 additions & 8 deletions Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,27 @@ private void Response()

var requestMessage = CameraPlugin.ParsingCameraInfoRequest(ref memoryStreamForCameraInfo, receivedBuffer);

if (requestMessage != null && requestMessage.Name.Equals("request_camera_info"))
if (requestMessage != null)
{
var cameraName = requestMessage.Value.StringValue;

if (cameraName != null)
switch (requestMessage.Name)
{
var cameraInfoMessage = cam.GetCameraInfo(cameraName);
case "request_camera_info":

CameraPlugin.SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage);
}
var cameraName = requestMessage.Value.StringValue;
if (cameraName != null)
{
var cameraInfoMessage = cam.GetCameraInfo(cameraName);

CameraPlugin.SetCameraInfoResponse(ref memoryStreamForCameraInfo, cameraInfoMessage);
}

SendResponse(memoryStreamForCameraInfo);
SendResponse(memoryStreamForCameraInfo);

break;

default:
break;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/DevicePlugins/UnityRosInit.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ccb1630

Please sign in to comment.