ITS
caReceptionManagement.cpp
Go to the documentation of this file.
2 
4 {
5  quint16 port = network->camDestinationPort(), portInfo = network->camDestinationPortInfo();
6  cam2app = new QUdpSocket(this);
7  m_internalSocket = new QUdpSocket(this);
8  m_internalSocket->bind();
9  cam2app->bind();
10  network->addPort("CAMReceptionManagement", cam2app->localPort());
11  network->addBTPPort(port, portInfo, m_internalSocket->localPort());
12  qDebug() << network->internalBTPPort(port, portInfo);
13  QObject::connect(m_internalSocket, SIGNAL(readyRead()), this, SLOT(readDatagram()));
14  appPort = network->internalPort("Application");
15  qDebug() << "appPort" << appPort;
16 }
17 
19 {
20  cam2app->close();
21  m_internalSocket->close();
22 }
23 
24 //void caReceptionManagement::execute(){}
25 
27 {
28  QNetworkDatagram data;
29 
30  while(m_internalSocket->hasPendingDatagrams())
31  {
32  qDebug() << "Receiving CAM";
33  data = m_internalSocket->receiveDatagram();
34 
35  if(decodeCam(data.data()))
36  {
37  camEventIndication(data.data());
38  }
39  }
40 }
41 
42 bool caReceptionManagement::decodeCam(QByteArray data)
43 {
44  CAM_t *receivedCAM = 0;
45  asn_dec_rval_t rval;
46 
47  print_hexa((unsigned char*)data.data(), data.length());
48  rval = uper_decode_complete(NULL, &asn_DEF_CAM, (void**)&receivedCAM, data.data(), data.length());
49  if(rval.code != RC_OK)
50  {
51  fprintf(stderr, "Unable to decode CAM: %s\n", rval.code == RC_FAIL ? "RC_FAIL" : "RC_WMORE");
52  return false;
53  }
54 
55  if(receivedCAM->header.protocolVersion != protocolVersion_currentVersion)
56  {
57  fprintf(stderr, "CAM received has wrong protocol version: %ld instead of %d\n", receivedCAM->header.protocolVersion, protocolVersion_currentVersion);
58  return false;
59  }
60 
61  if(receivedCAM->header.messageID != messageID_cam)
62  {
63  fprintf(stderr, "CAM received has wrong message ID: %ld instead of %d\n", receivedCAM->header.messageID, messageID_cam);
64  return false;
65  }
66 
67  printf("CAM decoded :\n");
68  //asn_fprint(stdout, &asn_DEF_CAM, receivedCAM);
69 
70  return true;
71 }
72 
74 {
76 
77  QByteArray resUt;
78  QDataStream ds(&resUt, QIODevice::WriteOnly);
79  ds << mt;
80  ds << (quint16)packet.length();
81  ds.writeRawData(packet.data(), packet.length());
82  qDebug() << packet.length() << "bytes sent to" << appPort;
83  qDebug() << resUt.toHex();
84 
85  cam2app->writeDatagram(resUt, QHostAddress::LocalHost, appPort);
86 }
asn_TYPE_descriptor_t asn_DEF_CAM
Definition: CAM.c:45
Definition: CAM.h:23
quint16 camDestinationPortInfo() const
camDestinationPortInfo CAM destination port info getter.
asn_dec_rval_t uper_decode_complete(struct asn_codec_ctx_s *opt_codec_ctx, struct asn_TYPE_descriptor_s *type_descriptor, void **struct_ptr, const void *buffer, size_t size)
Definition: per_decoder.c:11
void print_hexa(const unsigned char *msg, int l, FILE *stream=stdout)
print_hexa Print a byte array.
Definition: api.cpp:89
~caReceptionManagement()
~caReceptionManagement caReceptionManagement destructor.
void addBTPPort(quint16 port, quint16 portInfo, quint16 internal)
addBTPPort Add BTP port to the internal BTP ports.
quint16 internalPort(QString service)
internalPort Get the internal BTP port from service name.
void addPort(QString service, quint16 port)
addPort Add BTP port to the internal BTP ports from service name.
CAM reception management.
caReceptionManagement(ParameterNetwork *network)
quint16 internalBTPPort(quint16 port, quint16 portInfo)
internalBTPPort Get the internal BTP port.
void camEventIndication(QByteArray packet)
camEventIndication Notify the Application of receiving a CAM.
void readDatagram()
readDatagram Slot used when a datagram is received.
quint16 camDestinationPort() const
camDestinationPort CAM destination port getter.
bool decodeCam(QByteArray data)
decodeCam Try to decode received CAM.