cec: moved cec_adapter_message to CCECAdapterMessage
[deb_libcec.git] / src / lib / AdapterCommunication.cpp
index 2e330d3fe1005596714019952db40e6f5572a019..0439100bf60e4938b026a9be22392bb153d518b5 100644 (file)
@@ -155,7 +155,7 @@ void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
 void CAdapterCommunication::WriteNextCommand(void)
 {
   CLockObject lock(&m_commMutex);
-  cec_adapter_message msg;
+  CCECAdapterMessage msg;
   if (m_outBuffer.Pop(msg))
   {
     if (m_port->Write(msg) != (int32_t) msg.size())
@@ -172,13 +172,13 @@ void CAdapterCommunication::WriteNextCommand(void)
   }
 }
 
-bool CAdapterCommunication::Write(const cec_adapter_message &data)
+bool CAdapterCommunication::Write(const CCECAdapterMessage &data)
 {
   m_outBuffer.Push(data);
   return true;
 }
 
-bool CAdapterCommunication::Read(cec_adapter_message &msg, uint32_t iTimeout)
+bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout)
 {
   CLockObject lock(&m_bufferMutex);
 
@@ -240,11 +240,10 @@ bool CAdapterCommunication::StartBootloader(void)
     return false;
 
   m_controller->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
-  cec_adapter_message output;
-  output.clear();
+  CCECAdapterMessage output;
 
   output.push_back(MSGSTART);
-  PushEscaped(output, MSGCODE_START_BOOTLOADER);
+  output.push_escaped(MSGCODE_START_BOOTLOADER);
   output.push_back(MSGEND);
 
   if (!Write(output))
@@ -256,19 +255,6 @@ bool CAdapterCommunication::StartBootloader(void)
   return true;
 }
 
-void CAdapterCommunication::PushEscaped(cec_adapter_message &vec, uint8_t byte)
-{
-  if (byte >= MSGESC && byte != MSGSTART)
-  {
-    vec.push_back(MSGESC);
-    vec.push_back(byte - ESCOFFSET);
-  }
-  else
-  {
-    vec.push_back(byte);
-  }
-}
-
 bool CAdapterCommunication::SetAckMask(uint16_t iMask)
 {
   if (!IsRunning())
@@ -278,13 +264,12 @@ bool CAdapterCommunication::SetAckMask(uint16_t iMask)
   strLog.Format("setting ackmask to %2x", iMask);
   m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
 
-  cec_adapter_message output;
-  output.clear();
+  CCECAdapterMessage output;
 
   output.push_back(MSGSTART);
-  PushEscaped(output, MSGCODE_SET_ACK_MASK);
-  PushEscaped(output, iMask >> 8);
-  PushEscaped(output, (uint8_t)iMask);
+  output.push_escaped(MSGCODE_SET_ACK_MASK);
+  output.push_escaped(iMask >> 8);
+  output.push_escaped((uint8_t)iMask);
   output.push_back(MSGEND);
 
   if (!Write(output))
@@ -302,11 +287,10 @@ bool CAdapterCommunication::PingAdapter(void)
     return false;
 
   m_controller->AddLog(CEC_LOG_DEBUG, "sending ping");
-  cec_adapter_message output;
-  output.clear();
+  CCECAdapterMessage output;
 
   output.push_back(MSGSTART);
-  PushEscaped(output, MSGCODE_PING);
+  output.push_escaped(MSGCODE_PING);
   output.push_back(MSGEND);
 
   if (!Write(output))
@@ -325,46 +309,3 @@ bool CAdapterCommunication::IsOpen(void) const
 {
   return !IsStopped() && m_port->IsOpen();
 }
-
-void CAdapterCommunication::FormatAdapterMessage(const cec_command &command, cec_adapter_message &packet)
-{
-  packet.clear();
-
-  //set ack polarity to high when transmitting to the broadcast address
-  //set ack polarity low when transmitting to any other address
-  packet.push_back(MSGSTART);
-  PushEscaped(packet, MSGCODE_TRANSMIT_ACK_POLARITY);
-  if (command.destination == CECDEVICE_BROADCAST)
-    PushEscaped(packet, CEC_TRUE);
-  else
-    PushEscaped(packet, CEC_FALSE);
-  packet.push_back(MSGEND);
-
-  // add source and destination
-  packet.push_back(MSGSTART);
-  PushEscaped(packet, MSGCODE_TRANSMIT);
-  packet.push_back(((uint8_t)command.initiator << 4) + (uint8_t)command.destination);
-  packet.push_back(MSGEND);
-
-  // add opcode
-  packet.push_back(MSGSTART);
-  PushEscaped(packet, command.parameters.empty() ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT);
-  packet.push_back((uint8_t) command.opcode);
-  packet.push_back(MSGEND);
-
-  // add parameters
-  for (int8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
-  {
-    packet.push_back(MSGSTART);
-
-    if (iPtr == command.parameters.size - 1)
-      PushEscaped(packet, MSGCODE_TRANSMIT_EOM);
-    else
-      PushEscaped(packet, MSGCODE_TRANSMIT);
-
-    PushEscaped(packet, command.parameters[iPtr]);
-
-    packet.push_back(MSGEND);
-  }
-}
-