Aruna
aruna::sis::watcher Namespace Reference

Functions

err_t start ()
 start SIS report watcher thread More...
 
void * watch (void *)
 Watch SIS reports task. More...
 
void set_level (type_t type, level_t new_level)
 set level of alert on SIS level. More...
 

Variables

static const comm::port_t port = 2
 

Function Documentation

◆ set_level()

void aruna::sis::watcher::set_level ( type_t  type,
level_t  new_level 
)

set level of alert on SIS level.

Definition at line 74 of file watcher.cpp.

74  {
75  level[(uint8_t) type] = new_level;
76 }
sis::level_t level[(uint8_t) sis::type_t::MAX]
Definition: watcher.cpp:16

◆ start()

err_t aruna::sis::watcher::start ( )

start SIS report watcher thread

Returns
comm error

start SIS report watcher thread

start reporter to report all SIS activiry to the watcher over comm channels

Using LINK_HARDWARE to define hardware

Return values
err_t
  • HARDWARE_ERROR if the hardware fails.
  • OK great success!

start SIS report watcher thread

start reporter to report all SIS activiry to the watcher over comm channels

Returns
status_t, returns current status of the modulke
  • RUNNING if it is running,
  • STOPPED is it us currenty stopped.

Definition at line 19 of file watcher.cpp.

19  {
21 // TODO error check
22  log_channel = new log::channel_t("SIS watcher");
23  for (auto &i : level) {
24  i = level_t::WARNING;
25  }
26  pthread_create(&watcher_thread, NULL, watch, NULL);
27  return comm_channel->register_err;
28 }
sis::level_t level[(uint8_t) sis::type_t::MAX]
Definition: watcher.cpp:16
void * watch(void *)
Watch SIS reports task.
Definition: watcher.cpp:30
comm::channel_t * comm_channel
Definition: watcher.cpp:13
log::channel_t * log_channel
Definition: watcher.cpp:14
endpoint type of a comm channel
Definition: commTypes.h:150
static const comm::port_t port
Definition: reporter.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ watch()

void * aruna::sis::watcher::watch ( void *  )

Watch SIS reports task.

Definition at line 30 of file watcher.cpp.

30  {
32  sis::status_t *status_buffer;
33  sis::type_t received_type;
34  while (1) {
35  comm_channel->receive(&tp);
36  if (tp.from_port != sis::reporter::port) {
38  log_channel->warning("Port: %i sending us packages, dropping:", tp.from_port);
39  log_channel->dump(log::level_t::WARNING, tp.data_received, tp.data_lenght);
40  continue;
41  }
42  received_type = (sis::type_t) tp.data_received[0];
43 
44 // TODO this feels off, is there any better way of handling this?
45  switch (received_type) {
46  case type_t::WATER:
47  status_buffer = reinterpret_cast<status_t *>(new sensor::water_status_t());
48  break;
49  case type_t::UNKNOWN:
50  case type_t::MAX:
51  default:
52  received_type = type_t::UNKNOWN;
53  case sis::type_t::DEFAULT:
54  status_buffer = new sis::status_t(received_type);
55  break;
56  }
57 
58  status_buffer->decode(tp.data_received);
59  if ((uint8_t) level[(uint8_t) received_type] <= (uint8_t) status_buffer->level) {
60 // TODO error on critical and warning on warning.
61 // TODO better log containing type and level.
62 // TODO water type specific handler
63  log_channel->error(status_buffer->description);
64 // TODO log NOTIFY after >WARNING
65  } else {
66 // TODO log in verbose
67  }
68  delete status_buffer;
70  }
71  return nullptr;
72 }
type_t
Type of status.
Definition: sisTypes.h:26
uint8_t data_lenght
size of the data
Definition: commTypes.h:70
port_t from_port
channel who is sending the data.
Definition: commTypes.h:44
bool receive(transmitpackage_t *tpp)
handeler to handle incomming connections
Definition: commTypes.h:171
sis::level_t level[(uint8_t) sis::type_t::MAX]
Definition: watcher.cpp:16
comm::channel_t * comm_channel
Definition: watcher.cpp:13
char description[32]
Definition: sisTypes.h:40
log::channel_t * log_channel
Definition: watcher.cpp:14
int warning(const char *format,...)
log warning message
Definition: log.cpp:77
int error(const char *format,...)
log error message
Definition: log.cpp:90
status that is to be reported to the watcher
Definition: sisTypes.h:36
virtual void decode(uint8_t *to_decode)
Definition: sisTypes.h:56
static const comm::port_t port
Definition: reporter.h:15
uint8_t * data_received
pointer to where incoming data must be stored.
Definition: commTypes.h:65
int dump(level_t level, uint8_t *bin, size_t size)
dump array of bin data
Definition: log.cpp:135
transmit ready package.
Definition: commTypes.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ port

const comm::port_t aruna::sis::watcher::port = 2
static

Definition at line 16 of file watcher.h.