1 | #include "EquipmentAccessPort.h" |
---|
2 | #include <iostream> |
---|
3 | |
---|
4 | #include "Helper/Singleton.h" |
---|
5 | #include "Logger/Logger.h" |
---|
6 | #include "Helper/Decoders.h" |
---|
7 | #include "UpperTestAdapter.h" |
---|
8 | #include "Ports/MessagesIdentifiers.h" |
---|
9 | |
---|
10 | using namespace std; |
---|
11 | using namespace t3devlib; |
---|
12 | using namespace UpperTestAdapter; |
---|
13 | |
---|
14 | EquipmentAccessPort::EquipmentAccessPort (PortId& portId) : Port (portId) |
---|
15 | { |
---|
16 | stringstream ss; |
---|
17 | ss << "EquipmentAccessPort ctor()" << portId; |
---|
18 | Logger::Instance().LogDebug(ss.str()); |
---|
19 | } |
---|
20 | |
---|
21 | EquipmentAccessPort::~EquipmentAccessPort() |
---|
22 | { |
---|
23 | Logger::Instance().LogDebug("EquipmentAccessPort dtor() not implemented"); |
---|
24 | } |
---|
25 | |
---|
26 | bool EquipmentAccessPort::Map (const PortId& connected_port_id) |
---|
27 | { |
---|
28 | stringstream ss; |
---|
29 | ss << "EquipmentAccessPort::Map(): " << connected_port_id << " - " << connected_port_id.GetComponentId(); |
---|
30 | Logger::Instance().LogDebug(ss.str()); |
---|
31 | |
---|
32 | Singleton<UpperTestAdapter::UpperTestAdapter>::Instance().RegisterEquipmentAccessPort((PortId *)&connected_port_id, &connected_port_id.GetComponentId()); |
---|
33 | |
---|
34 | return true; |
---|
35 | } |
---|
36 | |
---|
37 | bool EquipmentAccessPort::Unmap (const PortId& connected_port_id) |
---|
38 | { |
---|
39 | //TODO: unregister filter; remove from m_connectedPorts |
---|
40 | Logger::Instance().LogError("EquipmentAccessPort::Unmap() not implemented"); |
---|
41 | return true; |
---|
42 | } |
---|
43 | |
---|
44 | bool EquipmentAccessPort::Send (const ComponentId& from,const Bitstring& msg) |
---|
45 | { |
---|
46 | stringstream ss; |
---|
47 | ss << "EquipmentAccessPort Send: " << from; |
---|
48 | Logger::Instance().LogInfo(ss.str()); |
---|
49 | |
---|
50 | unsigned char processDone = 0x00; // Processing result code - Set to 0 on success, set to 2 otherwise. |
---|
51 | |
---|
52 | // Retrieve and convert parameters. |
---|
53 | ss.str(""); |
---|
54 | ss << "##### bsMsg(HEXA value): " << msg.GetValueHexa(); |
---|
55 | Logger::Instance().LogInfo(ss.str()); |
---|
56 | int length; |
---|
57 | string frame = msg.GetValueHexa(); |
---|
58 | int offset = 0; |
---|
59 | |
---|
60 | int messageType = static_cast<int>(Decoders::Instance().DecodeByte(frame, &offset)); |
---|
61 | ss.str(""); |
---|
62 | ss << "EquipmentAccessPort::Send: messageType=" << messageType << " - " << offset; |
---|
63 | Logger::Instance().LogDebug(ss.str()); |
---|
64 | // Trigger command. |
---|
65 | string trigger = Decoders::Instance().DecodeLengthPlusString(frame, &offset, &length); |
---|
66 | ss.str(""); |
---|
67 | ss << "EquipmentAccessPort::Send: trigger=" << trigger << " - " << offset << " - " << length; |
---|
68 | Logger::Instance().LogDebug(ss.str()); |
---|
69 | |
---|
70 | // Number of items in the parameters list. |
---|
71 | short paramsNum = Decoders::Instance().DecodeParamsNum(frame, &offset); |
---|
72 | ss.str(""); |
---|
73 | ss << "EquipmentAccessPort::Send: paramsNum=" << paramsNum << " - " << offset << " - " << length; |
---|
74 | Logger::Instance().LogDebug(ss.str()); |
---|
75 | |
---|
76 | // Extract parameters. |
---|
77 | std::vector<string> parameterList; |
---|
78 | for (short counter = 0; counter < paramsNum; counter++) |
---|
79 | { |
---|
80 | parameterList.push_back(Decoders::Instance().DecodeLengthPlusString(frame, &offset, &length)); |
---|
81 | ss.str(""); |
---|
82 | ss << "EquipmentAccessPort::Send: parameter added: " << parameterList[parameterList.size() - 1] << " - " << offset << " - " << length; |
---|
83 | Logger::Instance().LogDebug(ss.str()); |
---|
84 | } |
---|
85 | |
---|
86 | int result = Singleton<UpperTestAdapter::UpperTestAdapter>::Instance().ProcessTriggerCommand(from, trigger, parameterList); |
---|
87 | |
---|
88 | // Prepare the response. |
---|
89 | Bitstring buffer; |
---|
90 | // Get message index |
---|
91 | unsigned char idx = MessagesIdentifiers::GetIdx(MessagesIdentifiers::EquipmentOperationRsp); |
---|
92 | if (idx == 0xff) { |
---|
93 | std::string errmsg ("unsupported response message value EquipmentOperationRsp'\n"); |
---|
94 | throw errmsg; |
---|
95 | Logger::Instance().LogError(errmsg); |
---|
96 | } |
---|
97 | // Set message index |
---|
98 | Unsigned fieldLength(8); // 1 octet length |
---|
99 | fieldLength.SetValue(idx); |
---|
100 | buffer.Append(fieldLength); |
---|
101 | //Set status |
---|
102 | Unsigned responseBuffer(8, result); |
---|
103 | buffer.Append(responseBuffer); |
---|
104 | // Set reason |
---|
105 | Unsigned reasonLength(2 * 8, 0); // omitted |
---|
106 | buffer.Append(reasonLength); |
---|
107 | // Send the response. |
---|
108 | ss.str(""); |
---|
109 | ss << "EquipmentAccessPort::Send: buffer=" << buffer; |
---|
110 | Logger::Instance().LogDebug(ss.str()); |
---|
111 | PortId *port = Singleton<UpperTestAdapter::UpperTestAdapter>::Instance().GetEquipmentAccessPortIdFromComponent(from); |
---|
112 | ss.str(""); |
---|
113 | ss << "EquipmentAccessPort::Send: Send response to " << port << " - " << *port; |
---|
114 | Logger::Instance().LogInfo(ss.str()); |
---|
115 | clog << "EquipmentAccessPort::Send: Call EnqueueMsg" << std::endl; |
---|
116 | EnqueueMsg (*port, buffer); |
---|
117 | |
---|
118 | return true; |
---|
119 | } |
---|
120 | |
---|
121 | void EquipmentAccessPort::ProcessTriggerCommandsComplete(const ComponentId &to) |
---|
122 | { |
---|
123 | //std::cerr << "EquipmentAccessPort::ProcessTriggerCommandsComplete() not implemented" << std::endl; |
---|
124 | } |
---|
125 | |
---|