FACT++  1.0
void ConnectionDrive::HandleReceivedData ( const boost::system::error_code &  err,
size_t  bytes_received,
int   
)
inlineprivatevirtual

Reimplemented from Connection.

Definition at line 1020 of file drivectrl.cc.

References data, Error(), and str.

Referenced by StartReadReport().

1021  {
1022  // Do not schedule a new read if the connection failed.
1023  if (bytes_received!=11 || fData[0]!=10 || err)
1024  {
1025  if (err==ba::error::eof)
1026  Warn("Connection closed by remote host (cosy).");
1027 
1028  // 107: Transport endpoint is not connected (bs::error_code(107, bs::system_category))
1029  // 125: Operation canceled
1030  if (err && err!=ba::error::eof && // Connection closed by remote host
1031  err!=ba::error::basic_errors::not_connected && // Connection closed by remote host
1032  err!=ba::error::basic_errors::operation_aborted) // Connection closed by us
1033  {
1034  ostringstream str;
1035  str << "Reading from " << URL() << ": " << err.message() << " (" << err << ")";// << endl;
1036  Error(str);
1037  }
1038  PostClose(err!=ba::error::basic_errors::operation_aborted);
1039  return;
1040  }
1041 
1042  Time now;
1043 
1044  const uint16_t desc = fData[1]<<8 | fData[2];
1045  const uint16_t cobid = desc>>5;
1046 
1047  const uint8_t *data = fData.data()+3;
1048 
1049  const uint16_t fcode = cobid >> 7;
1050  const uint8_t node = cobid & 0x1f;
1051 
1052  switch (fcode)
1053  {
1054  case kRxNodeguard:
1055  Out() << "Received nodeguard" << endl;
1056  //HandleNodeguard(node, now);
1057  break;
1058 
1059  case kRxSdo:
1060  {
1061  const uint8_t cmd = data[0];
1062  const uint16_t idx = data[1] | (data[2]<<8);
1063  const uint8_t subidx = data[3];
1064  const uint32_t dat = data[4] | (data[5]<<8) | (data[6]<<16) | (data[7]<<24);
1065 
1066  const auto it = find(fTimeouts.begin(), fTimeouts.end(), SDO(node, cmd, idx, subidx));
1067  if (it!=fTimeouts.end())
1068  {
1069  // This will call the handler and in turn remove the object from the list
1070  it->cancel();
1071  }
1072  else
1073  {
1074  ostringstream str;
1075  str << hex;
1076  str << "Unexpected SDO (";
1077  str << uint32_t(node) << ": ";
1078  str << ((cmd&0xf)==kTxSdo?"RX ":"TX ");
1079  str << idx << "/" << uint32_t(subidx) << ")";
1080 
1081  Warn(str);
1082  }
1083 
1084  switch (cmd)
1085  {
1086  case kRxSdo4: // answer to 0x40 with 4 bytes of data
1087  HandleSdo(node, idx, subidx, dat, now);
1088  break;
1089 
1090  case kRxSdo2: // answer to 0x40 with 2 bytes of data
1091  HandleSdo(node, idx, subidx, dat&0xffff, now);
1092  break;
1093 
1094  case kRxSdo1: // answer to 0x40 with 1 byte of data
1095  HandleSdo(node, idx, subidx, dat&0xff, now);
1096  break;
1097 
1098  case kRxSdoOk: // answer to a SDO_TX message
1099  HandleSdoOk(node, idx, subidx, now);
1100  break;
1101 
1102  case kRxSdoErr: // error message
1103  HandleSdoError(node, idx, subidx, now);
1104  break;
1105 
1106  default:
1107  {
1108  ostringstream out;
1109  out << "Invalid SDO command code " << hex << cmd << " received.";
1110  Error(out);
1111  PostClose(false);
1112  return;
1113  }
1114  }
1115  }
1116  break;
1117 
1118  case kRxPdo1:
1119  HandlePdo1(node, data, now);
1120  break;
1121 
1122  case kRxPdo2:
1123  HandlePdo2(node, data, now);
1124  break;
1125 
1126  case kRxPdo3:
1127  HandlePdo3(node, data, now);
1128  break;
1129 
1130  default:
1131  {
1132  ostringstream out;
1133  out << "Invalid function code " << hex << fcode << " received.";
1134  Error(out);
1135  PostClose(false);
1136  return;
1137  }
1138  }
1139 
1140  StartReadReport();
1141  }
Definition: dns.c:26
void PostClose(bool restart=true)
Definition: Connection.cc:125
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
void HandlePdo1(const uint8_t &node, const uint8_t *data, const Time &tv)
Definition: drivectrl.cc:748
std::list< Timeout_t > fTimeouts
Definition: drivectrl.cc:1016
void StartReadReport()
Definition: cosyctrl.cc:541
void HandleSdo(const uint8_t &node, const uint16_t &idx, const uint8_t &subidx, const uint32_t &val, const Time &tv)
Definition: drivectrl.cc:587
std::ostream & Out()
Definition: Connection.h:51
void HandleSdoOk(const uint8_t &node, const uint16_t &idx, const uint8_t &subidx, const Time &)
Definition: drivectrl.cc:659
std::string URL() const
Definition: Connection.h:151
int Error(const std::string &str)
Definition: MessageImp.h:49
int Warn(const std::string &str)
Definition: MessageImp.h:48
void HandlePdo3(const uint8_t &node, const uint8_t *data, const Time &tv)
Definition: drivectrl.cc:787
void HandleSdoError(const uint8_t &node, const uint16_t &idx, const uint8_t &subidx, const Time &)
Definition: drivectrl.cc:728
float data[4 *1440]
void HandlePdo2(const uint8_t &node, const uint8_t *data, const Time &)
Definition: drivectrl.cc:977
vector< uint8_t > fData
Definition: drivectrl.cc:1018

+ Here is the call graph for this function:

+ Here is the caller graph for this function: