ble_racp.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
  2. *
  3. * The information contained herein is property of Nordic Semiconductor ASA.
  4. * Terms and conditions of usage are described in detail in NORDIC
  5. * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
  6. *
  7. * Licensees are granted free, non-transferable use of the information. NO
  8. * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
  9. * the file.
  10. */
  11. #include "ble_racp.h"
  12. #include <stdlib.h>
  13. void ble_racp_decode(uint8_t data_len, uint8_t * p_data, ble_racp_value_t * p_racp_val)
  14. {
  15. p_racp_val->opcode = 0xFF;
  16. p_racp_val->operator = 0xFF;
  17. p_racp_val->operand_len = 0;
  18. p_racp_val->p_operand = NULL;
  19. if (data_len > 0)
  20. {
  21. p_racp_val->opcode = p_data[0];
  22. }
  23. if (data_len > 1)
  24. {
  25. p_racp_val->operator = p_data[1]; //lint !e415
  26. }
  27. if (data_len > 2)
  28. {
  29. p_racp_val->operand_len = data_len - 2;
  30. p_racp_val->p_operand = &p_data[2]; //lint !e416
  31. }
  32. }
  33. uint8_t ble_racp_encode(const ble_racp_value_t * p_racp_val, uint8_t * p_data)
  34. {
  35. uint8_t len = 0;
  36. int i;
  37. if (p_data != NULL)
  38. {
  39. p_data[len++] = p_racp_val->opcode;
  40. p_data[len++] = p_racp_val->operator;
  41. for (i = 0; i < p_racp_val->operand_len; i++)
  42. {
  43. p_data[len++] = p_racp_val->p_operand[i];
  44. }
  45. }
  46. return len;
  47. }