CogniBoost/sw/libCogniBoost/cbLibDev.c
static int cbSendReq(cbHnd_T      hnd,
                     cbTid_T      uTidReq,
                     cbMsgId_T    eReqMsgId,
                     byte_t       bufReqPkt[],
                     size_t       uReqMsgLen)
{
  cbPktHdr_T  hdrReq;       // request packet header
  int         nReqPktLen;
  int         n;

  CHK_EXPR(hnd, (uReqMsgLen >= CB_MSG_MIN_SIZE), CB_LIB_ECODE_TOO_SMALL,
      "Request %s(%d) length=%zu < message minimum=%zu.",
      CB_MSG_NAME_ID(eReqMsgId), uReqMsgLen, CB_MSG_MIN_SIZE);

  CHK_EXPR(hnd, (uReqMsgLen <= CB_MSG_MAX_SIZE), CB_LIB_ECODE_TOO_BIG,
      "Request %s(%d) length=%zu > message maximum=%zu.",
      CB_MSG_NAME_ID(eReqMsgId), uReqMsgLen, CB_MSG_MAX_SIZE);
  
  // fill request packet header
  hdrReq.m_hdrMagic   = (byte_t)CB_HDR_MAGIC;
  hdrReq.m_hdrTid     = (byte_t)uTidReq;
  hdrReq.m_hdrMsgLen  = (ushort_t)uReqMsgLen;

  // packet size
  nReqPktLen = CB_PKT_HDR_SIZE + (int)uReqMsgLen;

  // prepend header to request buffer
  n = cbPackPktHdr(hnd, &hdrReq, bufReqPkt, CB_PKT_HDR_SIZE);

  CHK_ECODE(hnd, n,
      "Failed to pack request packet header into packet for message %s(%d).",
      CB_MSG_NAME_ID(eReqMsgId));

  // send the message to the server
  n = cbDeviceWrite(hnd, bufReqPkt, (size_t)nReqPktLen, CB_TUNE_T_WRITE);

  CHK_EXPR(hnd, (n == nReqPktLen), CB_LIB_ECODE_SEND,
      "Failed to send request packet for message %s(%d).",
      CB_MSG_NAME_ID(eReqMsgId));

  // log successful request sent event
  CB_LOG_PKT(hnd, "REQ", &hdrReq, eReqMsgId);

  return nReqPktLen;
}
/*!
 * \brief Send a request packet to the server.
 *
 * \param hnd             CogniBoost device handle.
 * \param uTidReq         Transaction id.
 * \param eReqMsgId       Request message id.
 * \param [in] bufReqPkt  Packet buffer with the prepacked request message.
 *                        The buffer has empty head space for the packet header.
 * \param uReqMsgLen      Length of request message (prepacked in packet).
 *
 * \return 
 * On success, returns the length of the sent request packet.\n
 * \copydoc doc_return_ecode
 */
\brief Send a request packet to the server.
\param hnd             CogniBoost device handle.
\param uTidReq         Transaction id.
\param eReqMsgId       Request message id.
\param [in] bufReqPkt  Packet buffer with the prepacked request message.
The buffer has empty head space for the packet header.
\param uReqMsgLen      Length of request message (prepacked in packet).

\return
On success, returns the length of the sent request packet.\n
\copydoc doc_return_ecode
\ brief Send a request packet to the server . \ param hnd CogniBoost device handle . \ param uTidReq Transaction id . \ param eReqMsgId Request message id . \ param [ in ] bufReqPkt Packet buffer with the prepacked request message . The buffer has empty head space for the packet header . \ param uReqMsgLen Length of request message ( prepacked in packet ) . \ return On success returns the length of the sent request packet . \ n \ copydoc doc_return_ecode
static int cbSendReq(cbHnd_T      hnd,
                     cbTid_T      uTidReq,
                     cbMsgId_T    eReqMsgId,
                     byte_t       bufReqPkt[],
                     size_t       uReqMsgLen)
{
  cbPktHdr_T  hdrReq;       
  int         nReqPktLen;
  int         n;
  CHK_EXPR(hnd, (uReqMsgLen >= CB_MSG_MIN_SIZE), CB_LIB_ECODE_TOO_SMALL,
      "Request %s(%d) length=%zu < message minimum=%zu.",
      CB_MSG_NAME_ID(eReqMsgId), uReqMsgLen, CB_MSG_MIN_SIZE);
  CHK_EXPR(hnd, (uReqMsgLen <= CB_MSG_MAX_SIZE), CB_LIB_ECODE_TOO_BIG,
      "Request %s(%d) length=%zu > message maximum=%zu.",
      CB_MSG_NAME_ID(eReqMsgId), uReqMsgLen, CB_MSG_MAX_SIZE);
  hdrReq.m_hdrMagic   = (byte_t)CB_HDR_MAGIC;
  hdrReq.m_hdrTid     = (byte_t)uTidReq;
  hdrReq.m_hdrMsgLen  = (ushort_t)uReqMsgLen;
  nReqPktLen = CB_PKT_HDR_SIZE + (int)uReqMsgLen;
  n = cbPackPktHdr(hnd, &hdrReq, bufReqPkt, CB_PKT_HDR_SIZE);
  CHK_ECODE(hnd, n,
      "Failed to pack request packet header into packet for message %s(%d).",
      CB_MSG_NAME_ID(eReqMsgId));
  n = cbDeviceWrite(hnd, bufReqPkt, (size_t)nReqPktLen, CB_TUNE_T_WRITE);
  CHK_EXPR(hnd, (n == nReqPktLen), CB_LIB_ECODE_SEND,
      "Failed to send request packet for message %s(%d).",
      CB_MSG_NAME_ID(eReqMsgId));
  CB_LOG_PKT(hnd, "REQ", &hdrReq, eReqMsgId);
  return nReqPktLen;
}
static int cbSendReq ( cbHnd_T hnd , cbTid_T uTidReq , cbMsgId_T eReqMsgId , byte_t bufReqPkt [ ] , size_t uReqMsgLen ) { cbPktHdr_T hdrReq ; int nReqPktLen ; int n ; CHK_EXPR ( hnd , ( uReqMsgLen >= CB_MSG_MIN_SIZE ) , CB_LIB_ECODE_TOO_SMALL , " " , CB_MSG_NAME_ID ( eReqMsgId ) , uReqMsgLen , CB_MSG_MIN_SIZE ) ; CHK_EXPR ( hnd , ( uReqMsgLen <= CB_MSG_MAX_SIZE ) , CB_LIB_ECODE_TOO_BIG , " " , CB_MSG_NAME_ID ( eReqMsgId ) , uReqMsgLen , CB_MSG_MAX_SIZE ) ; hdrReq . m_hdrMagic = ( byte_t ) CB_HDR_MAGIC ; hdrReq . m_hdrTid = ( byte_t ) uTidReq ; hdrReq . m_hdrMsgLen = ( ushort_t ) uReqMsgLen ; nReqPktLen = CB_PKT_HDR_SIZE + ( int ) uReqMsgLen ; n = cbPackPktHdr ( hnd , & hdrReq , bufReqPkt , CB_PKT_HDR_SIZE ) ; CHK_ECODE ( hnd , n , " " , CB_MSG_NAME_ID ( eReqMsgId ) ) ; n = cbDeviceWrite ( hnd , bufReqPkt , ( size_t ) nReqPktLen , CB_TUNE_T_WRITE ) ; CHK_EXPR ( hnd , ( n == nReqPktLen ) , CB_LIB_ECODE_SEND , " " , CB_MSG_NAME_ID ( eReqMsgId ) ) ; CB_LOG_PKT ( hnd , " " , & hdrReq , eReqMsgId ) ; return nReqPktLen ; }
\brief Send a request packet to the server.
\ brief Send a request packet to the server .
// request packet header // fill request packet header // packet size // prepend header to request buffer // send the message to the server // log successful request sent event