read_all_res.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "read_all_res.h"
  2. #include "rpcdb.h"
  3. #include <status_codes.h>
  4. #include <iostream>
  5. #include <stdexcept>
  6. #include <vector>
  7. #define SEPARATOR " "
  8. #define SENSOR_INFO "Sensor id: "
  9. #define READ_VALUES_MESSAGE "Data: "
  10. using std::cout;
  11. using std::endl;
  12. using std::runtime_error;
  13. using std::vector;
  14. read_all_res::read_all_res()
  15. {
  16. }
  17. read_all_res::~read_all_res()
  18. {
  19. }
  20. command_type read_all_res::get_command()
  21. {
  22. return command_type::READ_ALL_CMD;
  23. }
  24. int read_all_res::perform(response *res)
  25. {
  26. if (res->response_u.read_all.response != status::VALID)
  27. throw runtime_error(
  28. status_codes::get(res->response_u.read_all.response));
  29. sensor_data *src = res->response_u.read_all.data.data_val;
  30. size_t size = res->response_u.read_all.data.data_len;
  31. for (int i = 0; i < size; i++) {
  32. float *val_src = src[i].values.values_val;
  33. size_t val_size = src[i].values.values_len;
  34. vector<float> values(val_src, val_src + val_size);
  35. cout << SENSOR_INFO << src[i].sensor_id << endl;
  36. cout << READ_VALUES_MESSAGE;
  37. for (auto j : values)
  38. cout << j << SEPARATOR;
  39. cout << endl;
  40. }
  41. return status::VALID;
  42. }