/
monitor.c
78 lines (61 loc) · 1.52 KB
/
monitor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "kernel/kernel.h"
#include "kernel/stream.h"
#include "defines.h"
#include "config.h"
#include "ax25.h"
#include "hdlc.h"
BCond mon_ok;
/* External variable in afsk_rx and afsk_tx.
* May pass it as return value from mon_init instead? */
static bool mon_on = false;
static stream_t *out;
static FBQ mon;
static void mon_thread(void);
FBQ* mon_q = &mon;
void mon_init(stream_t* outstr)
{
out = outstr;
bcond_init(&mon_ok, true);
FBQ_INIT(mon, HDLC_DECODER_QUEUE_SIZE);
}
void mon_activate(bool m)
{
/* Start if not on already */
bool tstart = m && !mon_on;
/* Stop if not stopped already */
bool tstop = !m && mon_on;
mon_on = m;
FBQ* mq = (mon_on? &mon : NULL);
hdlc_subscribe_rx(mq, 0);
if (!mon_on || GET_BYTE_PARAM(TXMON_ON))
hdlc_monitor_tx(mq);
if (tstart)
THREAD_START(mon_thread, STACK_MONITOR);
if (tstop) {
hdlc_monitor_tx(NULL);
hdlc_subscribe_rx(NULL, 0);
fbq_signal(&mon);
}
}
void mon_showtext(char* txt)
{
if (mon_on)
putstr(out, txt);
}
static void mon_thread()
{
while (mon_on)
{
/* Wait for frame and then to AFSK decoder/encoder
* is not running.
*/
FBUF frame = fbq_get(&mon);
if (!fbuf_empty(&frame)) {
/* Display it */
ax25_display_frame(out, &frame);
putstr_P(out, PSTR("\r\n"));
}
/* And dispose the frame. Note that also an empty frame should be disposed! */
fbuf_release(&frame);
}
}