339 lines
16 KiB
C#
339 lines
16 KiB
C#
using Aurora.Api;
|
|
using Aurora.Api.Devices;
|
|
using Hermes;
|
|
using System;
|
|
using WeldingCommon;
|
|
using WeldingCommon.Data;
|
|
|
|
namespace ILSOS_SampleWeldEquipment.Sequences
|
|
{
|
|
internal class SeqStreamTest
|
|
{
|
|
static readonly Logger Log = new Logger("SeqStreamTest");
|
|
|
|
public const string SEQ_STREAM_RPC_CONNECT_CHECK = "StreamRPCConnectCheck";
|
|
public const string SEQ_STREAM_RPC_INITIALIZE = "StreamRPCInitialize";
|
|
public const string SEQ_STREAM_PUB_SUB_INITIALIZE = "StreamPubSubInitialize";
|
|
public const string SEQ_STREAM_BROADCAST_INITIALIZE = "StreamBroadcastInitialize";
|
|
|
|
public const string SEQ_STREAM_RPC_SEND = "StreamRPCSend";
|
|
public const string SEQ_STREAM_RPC_SEND_LBAD = "StreamRPCSendLbad";
|
|
public const string SEQ_STREAM_PUB_TEST = "StreamPubTest";
|
|
|
|
public const string SEQ_STREAM_BROADCAST_TEST = "StreamBroadcastTest";
|
|
|
|
private static StreamServer _Server;
|
|
private static StreamClient _Client;
|
|
private static StreamPub _StreamPub;
|
|
private static StreamSub _StreamSub;
|
|
private static StreamBroadcastPub _BroadcastPub;
|
|
private static StreamBroadcastSub _BroadcastSub;
|
|
private static LBAD_Reulst_List _InputdataLBAD;
|
|
|
|
public static SequenceBuilder Builder()
|
|
{
|
|
|
|
SequenceBuilder sb = new SequenceBuilder(1000);
|
|
|
|
sb.AddAction(SEQ_STREAM_RPC_CONNECT_CHECK, StreamRPCConnectCheck);
|
|
sb.AddAction(SEQ_STREAM_RPC_INITIALIZE, StreamRPCInitialize);
|
|
sb.AddAction(SEQ_STREAM_RPC_SEND, StreamRPCSend);
|
|
sb.AddAction(SEQ_STREAM_RPC_SEND_LBAD, StreamRPCSendLBAD);
|
|
|
|
sb.AddAction(SEQ_STREAM_PUB_SUB_INITIALIZE, StreamPubSubInitialize);
|
|
sb.AddAction(SEQ_STREAM_PUB_TEST, StreamPubTest);
|
|
|
|
sb.AddAction(SEQ_STREAM_BROADCAST_INITIALIZE, StreamBroadcastInitialize);
|
|
sb.AddAction(SEQ_STREAM_BROADCAST_TEST, StreamBroadcastTest);
|
|
|
|
//RPC
|
|
//sb.Flows(sb.Init > sb[SEQ_STREAM_RPC_CONNECT_CHECK] > sb[SEQ_STREAM_RPC_INITIALIZE] > sb[SEQ_STREAM_RPC_SEND] > sb[SEQ_STREAM_RPC_SEND_LBAD] > sb.Final);
|
|
|
|
//PubSub
|
|
//sb.Flows(sb.Init > sb[SEQ_STREAM_RPC_CONNECT_CHECK] > sb[SEQ_STREAM_PUB_SUB_INITIALIZE] > sb[SEQ_STREAM_PUB_TEST] > sb.Final);
|
|
|
|
//MessageBroadCast
|
|
sb.Flows(sb.Init > sb[SEQ_STREAM_RPC_CONNECT_CHECK] > sb[SEQ_STREAM_BROADCAST_INITIALIZE] > sb[SEQ_STREAM_BROADCAST_TEST] > sb.Final);
|
|
|
|
return sb;
|
|
|
|
}
|
|
private static SequenceActionResult StreamRPCConnectCheck(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
//RPC
|
|
//StreamServer 설정
|
|
_Server = context.Devices[CommonServiceIds.StreamServerTest] as StreamServer;
|
|
//StreamClient 설정
|
|
_Client = context.Devices[CommonServiceIds.StreamClientTest] as StreamClient;
|
|
|
|
//PubSub
|
|
_StreamPub = context.Devices[CommonServiceIds.StreamPubTest] as StreamPub;
|
|
_StreamSub = context.Devices[CommonServiceIds.StreamSubTest] as StreamSub;
|
|
|
|
//MessageBroadcasting
|
|
_BroadcastPub = context.Devices[CommonServiceIds.StreamBroadcastPub] as StreamBroadcastPub;
|
|
_BroadcastSub = context.Devices[CommonServiceIds.StreamBroadcastSub] as StreamBroadcastSub;
|
|
|
|
|
|
var ret = E1.OK;
|
|
if (!_Server.IsActivated) {
|
|
ret = _Server.Activate();
|
|
if (ret != E1.OK) {
|
|
Log.E($"Stream{CommonServiceIds.StreamServerTest} activate failed");
|
|
return null;
|
|
}
|
|
}
|
|
if (!_Client.IsActivated) {
|
|
ret = _Client.Activate();
|
|
if (ret != E1.OK) {
|
|
Log.E($"Stream{CommonServiceIds.StreamClientTest} activate failed");
|
|
return null;
|
|
}
|
|
}
|
|
if (!_StreamPub.IsActivated) {
|
|
ret = _StreamPub.Activate();
|
|
if (ret != E1.OK) {
|
|
Log.E($"Stream{CommonServiceIds.StreamPubTest} activate failed");
|
|
return null;
|
|
}
|
|
}
|
|
if (!_StreamSub.IsActivated) {
|
|
ret = _StreamSub.Activate();
|
|
if (ret != E1.OK) {
|
|
Log.E($"Stream{CommonServiceIds.StreamSubTest} activate failed");
|
|
return null;
|
|
}
|
|
}
|
|
if (!_BroadcastPub.IsActivated) {
|
|
ret = _BroadcastPub.Activate();
|
|
if (ret != E1.OK) {
|
|
Log.E($"Stream{CommonServiceIds.StreamBroadcastPub} activate failed");
|
|
return null;
|
|
}
|
|
}
|
|
if (!_BroadcastSub.IsActivated) {
|
|
ret = _BroadcastSub.Activate();
|
|
if (ret != E1.OK) {
|
|
Log.E($"Stream{CommonServiceIds.StreamBroadcastSub} activate failed");
|
|
return null;
|
|
}
|
|
}
|
|
return SequenceAction.Ok();
|
|
|
|
}
|
|
|
|
private static SequenceActionResult StreamBroadcastInitialize(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
_BroadcastPub.AddParser(CommonStreamTopicNames.TOPIC1, new StreamNumberParser<int>());
|
|
_BroadcastSub.AddParser(CommonStreamTopicNames.TOPIC1, new StreamNumberParser<int>());
|
|
|
|
_BroadcastSub.SetListener(OnBroadcastTopic);
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static void OnBroadcastTopic(string from, string replyTo, string topic, object data)
|
|
{
|
|
switch (topic)
|
|
{
|
|
case CommonStreamTopicNames.TOPIC1:
|
|
var replyParsed = (int)data;
|
|
Log.I($"Stream Reply Result : {replyParsed}");
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static SequenceActionResult StreamBroadcastTest(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
int reqData = 1;
|
|
var res = _BroadcastPub.Publish(reqData, CommonStreamTopicNames.TOPIC1);
|
|
if (!res) {
|
|
Log.E("Publish Error : Topic1");
|
|
}
|
|
return SequenceAction.Ok();
|
|
}
|
|
private static SequenceActionResult StreamPubSubInitialize(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
//PubSub Parser 등록
|
|
_StreamPub.AddParser(CommonStreamTopicNames.TOPIC1, new StreamJsonParser<Stream_LBAD_Result_List>());
|
|
_StreamSub.AddParser(CommonStreamTopicNames.TOPIC1, new StreamJsonParser<Stream_LBAD_Result_List>());
|
|
|
|
//구독해두면 Publish하면 핸들러로 받아온다
|
|
_StreamSub.SetListener(OnSubscribeTopic);
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
|
|
private static SequenceActionResult StreamPubTest(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
_InputdataLBAD = new LBAD_Reulst_List();
|
|
|
|
_InputdataLBAD.nRecipeID = 1;
|
|
_InputdataLBAD.LotID = "Test_LotID_1";
|
|
_InputdataLBAD.CellID = "Test_CellID_1";
|
|
_InputdataLBAD.nResultFlag = "OK";
|
|
_InputdataLBAD.dRateDifference = 1.0f;
|
|
_InputdataLBAD.dCenterX = 2.0f;
|
|
_InputdataLBAD.dCenterY = 3.0f;
|
|
_InputdataLBAD.dCircularity = 4.0f;
|
|
_InputdataLBAD.dOuterDiameter = 5.0f;
|
|
|
|
Stream_LBAD_Result_List lbadResultList = new Stream_LBAD_Result_List(_InputdataLBAD);
|
|
|
|
var res = _StreamPub.Publish(lbadResultList, CommonStreamTopicNames.TOPIC1);
|
|
if (!res) {
|
|
Log.E("Publish Error : Topic1");
|
|
}
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
private static void OnSubscribeTopic(string from, string topic, object data)
|
|
{
|
|
switch (topic) {
|
|
case CommonStreamTopicNames.TOPIC1:
|
|
var replyParsed = data as Stream_LBAD_Result_List;
|
|
Log.I($"Stream Reply Result : " +
|
|
$"nRecipeID {replyParsed.LBADResultList[0].nRecipeID}, LotID {replyParsed.LBADResultList[0].LotID}, CellID {replyParsed.LBADResultList[0].CellID}, nResultFlag {replyParsed.LBADResultList[0].nResultFlag}, " +
|
|
$"dRateDifference {replyParsed.LBADResultList[0].dRateDifference}, dCenterX {replyParsed.LBADResultList[0].dCenterX}, dCenterY {replyParsed.LBADResultList[0].dCenterY}, " +
|
|
$"dCircularity {replyParsed.LBADResultList[0].dCircularity}, dOuterDiameter {replyParsed.LBADResultList[0].dOuterDiameter}");
|
|
break;
|
|
}
|
|
}
|
|
|
|
private static SequenceActionResult StreamRPCInitialize(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
_Server.AddParser(StreamMessageNames.MESSAGE_NAME_DOUBLE, new StreamNumberParser<double>(), new StreamNumberParser<double>());
|
|
_Client.AddParser(StreamMessageNames.MESSAGE_NAME_DOUBLE, new StreamNumberParser<double>(), new StreamNumberParser<double>());
|
|
|
|
//우선 LBAD 결과를 JSON 파서로 등록해서 받아지는지 확인해보자.. 이후에 List로 변경
|
|
//StreamServer Parser 등록
|
|
_Server.AddParser(StreamMessageNames.MESSAGE_NAME_JSON, new StreamJsonParser<LBAD_Reulst_List>(), new StreamJsonParser<LBAD_Reulst_List>());
|
|
//StreamClient Parser 등록
|
|
_Client.AddParser(StreamMessageNames.MESSAGE_NAME_JSON, new StreamJsonParser<LBAD_Reulst_List>(), new StreamJsonParser<LBAD_Reulst_List>());
|
|
|
|
//LBAD List Test
|
|
//StreamServer Parser 등록
|
|
_Server.AddParser(StreamMessageNames.MESSAGE_NAME_LBAD, new StreamStringParser(), new StreamJsonParser<Stream_LBAD_Result_List>());
|
|
//StreamClient Parser 등록
|
|
_Client.AddParser(StreamMessageNames.MESSAGE_NAME_LBAD, new StreamStringParser(), new StreamJsonParser<Stream_LBAD_Result_List>());
|
|
|
|
//Client의 Rquest 처리를 위한 Handler 설정
|
|
_Server.SetListener(OnStreamRequest);
|
|
|
|
return SequenceAction.Ok();
|
|
}
|
|
|
|
|
|
private static object OnStreamRequest(string from, string messageId, string topic, object data)
|
|
{
|
|
//파서가 잘못 등록되면 CommonStreamMessageNames가 맞아도 핸들러에 들어오지 않음..
|
|
switch (messageId) {
|
|
case StreamMessageNames.MESSAGE_NAME_DOUBLE:
|
|
double inputNumer = (double)data;
|
|
double outputNumer = inputNumer + 1;
|
|
return outputNumer;
|
|
case StreamMessageNames.MESSAGE_NAME_JSON:
|
|
var inputdataJson = data as LBAD_Reulst_List;
|
|
var outputdataJson = new LBAD_Reulst_List() {
|
|
//무조건 값을 다 넣어줘야 함, 아니면 null return 함
|
|
nRecipeID = inputdataJson.nRecipeID,
|
|
LotID = inputdataJson.LotID + "_stream",
|
|
CellID = inputdataJson.CellID + "_stream",
|
|
nResultFlag = inputdataJson.nResultFlag + "_stream",
|
|
dRateDifference = inputdataJson.dRateDifference + 1.0f,
|
|
dCenterX = inputdataJson.dCenterX + 1.0f,
|
|
dCenterY = inputdataJson.dCenterY + 1.0f,
|
|
dCircularity = inputdataJson.dCircularity + 1.0f,
|
|
dOuterDiameter = inputdataJson.dOuterDiameter + 1.0f
|
|
};
|
|
return outputdataJson;
|
|
case StreamMessageNames.MESSAGE_NAME_LBAD:
|
|
Stream_LBAD_Result_List outputdataLBADList = new Stream_LBAD_Result_List(_InputdataLBAD);
|
|
return outputdataLBADList;
|
|
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static SequenceActionResult StreamRPCSend(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
double requestData = 2.0f;
|
|
var reply = _Client.RequestNReply(requestData, StreamMessageNames.MESSAGE_NAME_DOUBLE);
|
|
|
|
if (reply != null) {
|
|
var replyParsed = (double)reply;
|
|
Log.I($"Stream Reply Result : {replyParsed}");
|
|
} else {
|
|
Log.E("Stream reply is null!");
|
|
}
|
|
|
|
//JSON Test
|
|
//데이터 클래스는 시퀀스에 선언하지말고 따로 관리해야 할 듯.. LBAD Device View에서도 사용해야하니깐 어디서 생성해줄지 고민 필요
|
|
//나중에는 List로 관리해야 할듯.. 근데 RPC로 쓸 필요가 있을까.. LBAD Data는 Subscribe만 가능하면 될 듯 한데..
|
|
//IO를 RCP로 대체하는건 가능할듯... 신호를 주고 받아야하니깐..
|
|
var requestDateJson = new LBAD_Reulst_List();
|
|
requestDateJson.nRecipeID = 1;
|
|
requestDateJson.LotID = "Test_LotID_1";
|
|
requestDateJson.CellID = "Test_CellID_1";
|
|
requestDateJson.nResultFlag = "OK";
|
|
requestDateJson.dRateDifference = 1.0f;
|
|
requestDateJson.dCenterX = 2.0f;
|
|
requestDateJson.dCenterY = 3.0f;
|
|
requestDateJson.dCircularity = 4.0f;
|
|
requestDateJson.dOuterDiameter = 5.0f;
|
|
|
|
var replyJson = _Client.RequestNReply(requestDateJson, StreamMessageNames.MESSAGE_NAME_JSON);
|
|
|
|
if (replyJson != null) {
|
|
var replyParsed = replyJson as LBAD_Reulst_List;
|
|
Log.I($"Stream Reply Result : " +
|
|
$"nRecipeID {replyParsed.nRecipeID}, LotID {replyParsed.LotID}, CellID {replyParsed.CellID}, nResultFlag {replyParsed.nResultFlag}, " +
|
|
$"dRateDifference {replyParsed.dRateDifference}, dCenterX {replyParsed.dCenterX}, dCenterY {replyParsed.dCenterY}, dCircularity {replyParsed.dCircularity}, dOuterDiameter {replyParsed.dOuterDiameter}");
|
|
} else {
|
|
Log.E("Stream reply is null!");
|
|
}
|
|
|
|
return SequenceAction.Ok();
|
|
|
|
}
|
|
|
|
private static SequenceActionResult StreamRPCSendLBAD(SequenceContext context, string id, SequenceActionResult param)
|
|
{
|
|
_InputdataLBAD = new LBAD_Reulst_List();
|
|
|
|
_InputdataLBAD.nRecipeID = 1;
|
|
_InputdataLBAD.LotID = "Test_LotID_1";
|
|
_InputdataLBAD.CellID = "Test_CellID_1";
|
|
_InputdataLBAD.nResultFlag = "OK";
|
|
_InputdataLBAD.dRateDifference = 1.0f;
|
|
_InputdataLBAD.dCenterX = 2.0f;
|
|
_InputdataLBAD.dCenterY = 3.0f;
|
|
_InputdataLBAD.dCircularity = 4.0f;
|
|
_InputdataLBAD.dOuterDiameter = 5.0f;
|
|
|
|
|
|
string requestString = "1";
|
|
var replyList = _Client.RequestNReply(requestString, StreamMessageNames.MESSAGE_NAME_LBAD);
|
|
|
|
if (replyList != null) {
|
|
var replyParsed = replyList as Stream_LBAD_Result_List;
|
|
//Log.I($"Stream Reply Result : " +
|
|
// $"nRecipeID {replyParsed.LBADResultList[0].}, LotID {replyParsed.LotID}, CellID {replyParsed.CellID}, nResultFlag {replyParsed.nResultFlag}, " +
|
|
// $"dRateDifference {replyParsed.dRateDifference}, dCenterX {replyParsed.dCenterX}, dCenterY {replyParsed.dCenterY}, dCircularity {replyParsed.dCircularity}, dOuterDiameter {replyParsed.dOuterDiameter}");
|
|
if (replyParsed.LBADResultList.Count == 1)
|
|
Log.I($"Stream Reply Result : " + $"nRecipeID_[0] : {replyParsed.LBADResultList[0].nRecipeID}");
|
|
else if (replyParsed.LBADResultList.Count == 2)
|
|
Log.I($"Stream Reply Result : " + $"nRecipeID_[0] : {replyParsed.LBADResultList[0].nRecipeID}, nRecipeID_[1] : {replyParsed.LBADResultList[1].nRecipeID}");
|
|
} else {
|
|
Log.E("Stream reply is null!");
|
|
}
|
|
|
|
return SequenceAction.Ok();
|
|
|
|
}
|
|
}
|
|
}
|