/**************************************************************************/
/*!
    Makes sure sys info commands with an invalid payload are rejected

    Every sysinfo command must have at least a two-byte key. This function
    sends a sysinfo command with a zero-length payload (no key).
*/
/**************************************************************************/
void test_sysinfo_invalid_length_zero(void)
{
  message_cmd = (protMsgCommand_t)
  {
    .msg_type    = PROT_MSGTYPE_COMMAND,
    .cmd_id      = PROT_CMDTYPE_SYSINFO,
    .length      = 0,
    .payload     = { U16_LOW_U8(PROT_CMD_SYSINFO_KEY_CODEBASE_VERSION),  U16_HIGH_U8(PROT_CMD_SYSINFO_KEY_CODEBASE_VERSION) }
  };

  message_error = (protMsgError_t)
  {
    .msg_type = PROT_MSGTYPE_ERROR,
    .error_id = ERROR_PROT_INVALIDPAYLOAD
  };

  fifo_write(&ff_prot_cmd, &message_cmd);

  prot_cmd_received_cb_Expect(&message_cmd);
  prot_cmd_error_cb_Expect(&message_error);
  MOCK_PROT(command_send, _IgnoreAndReturn)(LPC_OK);

  //------------- Code Under Test -------------//
示例#2
0
void prot_task(void * p_para)
{
  if ( !fifo_isEmpty(&ff_prot_cmd) )
  {
    /* If we get here, it means a command was received */
    protMsgCommand_t  message_cmd     = { 0 };
    protMsgResponse_t message_reponse = { 0 };
    uint16_t          command_id;
    error_t           error;

    /* COMMAND PHASE */
    fifo_read(&ff_prot_cmd, &message_cmd);

    /* Command_id is at an odd address ... directly using the value in *
     * message_cmd can lead to alignment issues on the M0              */
    command_id = (message_cmd.cmd_id_high << 8) + message_cmd.cmd_id_low;

    /* Make sure we have a command with a valid ID */
    if ( !(PROT_MSGTYPE_COMMAND == message_cmd.msg_type) )
    {
      error = ERROR_PROT_INVALIDMSGTYPE;
    }
    else if ( !(0 < command_id && command_id < PROT_CMD_COUNT) )
    {
      error = ERROR_PROT_INVALIDCOMMANDID;
    }
    else if (message_cmd.length > (PROT_MAX_MSG_SIZE-4))
    {
      error = ERROR_INVALIDPARAMETER;
    }
    else
    {
      /* Keep track of the command ID for the response message */
      message_reponse.msg_type    = PROT_MSGTYPE_RESPONSE;
      message_reponse.cmd_id_high = message_cmd.cmd_id_high;
      message_reponse.cmd_id_low  = message_cmd.cmd_id_low;

      /* Invoke 'cmd_received' callback before executing command */
      if (prot_cmd_received_cb)
      {
        prot_cmd_received_cb(&message_cmd);
      }

      /* Fire the appropriate handler based on the command ID */
      error = protocol_cmd_tbl[command_id] ( message_cmd.length, message_cmd.payload, &message_reponse );
    }

    /* RESPONSE PHASE */

    // TODO:  Make sure the usb command is ready to send
    // in case there are a bunch of cmds queued in FIFO

    if (error == ERROR_NONE)
    {
      /* Invoke the 'cmd_executed' callback */
      if (prot_cmd_executed_cb)
      {
        prot_cmd_executed_cb(&message_reponse);
      }

      /* Send the response message (cmd successfully executed) */
      command_send( (uint8_t*) &message_reponse, sizeof(protMsgResponse_t));
    }
    else
    {
      /* Something went wrong ... parse the error ID */
      protMsgError_t message_error =
      {
        .msg_type      = PROT_MSGTYPE_ERROR,
      };
      message_error.error_id_high = U16_HIGH_U8(error);
      message_error.error_id_low  = U16_LOW_U8 (error);

      /* Invoke the 'cmd_error' callback */
      if (prot_cmd_error_cb)
      {
        prot_cmd_error_cb(&message_error);
      }

      /* Send back a mandatory error message */
      command_send( (uint8_t*)  &message_error, sizeof(protMsgError_t));
    }
  }