peer_data.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (c) 2015 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. */
  12. #include "peer_data.h"
  13. #include "peer_manager_types.h"
  14. #include "fds.h"
  15. #include "sdk_common.h"
  16. void peer_data_parts_get(pm_peer_data_const_t const * p_peer_data, fds_record_chunk_t * p_chunks, uint16_t * p_n_chunks)
  17. {
  18. if (p_n_chunks == NULL)
  19. {
  20. }
  21. else if ((p_peer_data == NULL) || (p_chunks == NULL))
  22. {
  23. *p_n_chunks = 0;
  24. }
  25. else
  26. {
  27. p_chunks[0].p_data = p_peer_data->p_all_data;
  28. p_chunks[0].length_words = p_peer_data->length_words;
  29. *p_n_chunks = 1;
  30. }
  31. }
  32. ret_code_t peer_data_deserialize(pm_peer_data_flash_t const * p_in_data, pm_peer_data_t * p_out_data)
  33. {
  34. ret_code_t err_code = NRF_SUCCESS;
  35. if ((p_in_data == NULL) || (p_out_data == NULL))
  36. {
  37. err_code = NRF_ERROR_NULL;
  38. }
  39. else
  40. {
  41. if (p_out_data->length_words < p_in_data->length_words)
  42. {
  43. p_out_data->length_words = p_in_data->length_words;
  44. err_code = NRF_ERROR_NO_MEM;
  45. }
  46. else
  47. {
  48. p_out_data->length_words = p_in_data->length_words;
  49. p_out_data->data_id = p_in_data->data_id;
  50. memcpy(p_out_data->p_all_data, p_in_data->p_all_data, p_in_data->length_words * 4);
  51. }
  52. }
  53. return err_code;
  54. }