get_stat_res.cpp 958 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "get_stat_res.h"
  2. #include <status_codes.h>
  3. #include <iostream>
  4. #include <stdexcept>
  5. #define ID_FORMAT "Sensor id: "
  6. #define MIN_FORMAT "Minimum value: "
  7. #define MAX_FORMAT "Maximum value: "
  8. #define AVG_FORMAT "Average value: "
  9. #define MED_FORMAT "Median value: "
  10. using std::cout;
  11. using std::endl;
  12. using std::runtime_error;
  13. get_stat_res::get_stat_res()
  14. {
  15. }
  16. get_stat_res::~get_stat_res()
  17. {
  18. }
  19. command_type get_stat_res::get_command()
  20. {
  21. return command_type::GET_STAT_CMD;
  22. }
  23. int get_stat_res::perform(response *res)
  24. {
  25. if (res->response_u.get_stat.response != status::VALID)
  26. throw runtime_error(
  27. status_codes::get(res->response_u.get_stat.response));
  28. sensor_stat stat = res->response_u.get_stat.stat;
  29. cout << ID_FORMAT << stat.sensor_id << endl;
  30. cout << MIN_FORMAT << stat.min << endl;
  31. cout << MAX_FORMAT << stat.max << endl;
  32. cout << AVG_FORMAT << stat.avg << endl;
  33. cout << MED_FORMAT << stat.med << endl;
  34. return status::VALID;
  35. }