-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_handler.c
executable file
·158 lines (123 loc) · 2.82 KB
/
cmd_handler.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Little Free Radio - An Open Source Radio for CubeSats
* Copyright (C) 2018 Grant Iraci, Brian Bezanson
* A project of the University at Buffalo Nanosatellite Laboratory
* See LICENSE for details
*/
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "lfr-tcp.h"
#include "cmd_handler.h"
#include "cmd_parser.h"
void cmd_nop() {
log_info("NOP\n");
reply(CMD_NOP, 0, NULL);
}
void cmd_reset() {
log_info("RESET!\n");
}
void cmd_set_txpwr(uint16_t pwr) {
log_info("SET_TXPWR: 0x%04X\n", pwr);
tx_gate_bias = pwr;
reply(CMD_SET_TXPWR, 0, NULL);
}
void cmd_get_txpwr() {
uint8_t resp[] = {(uint8_t)(tx_gate_bias >> 8),
(uint8_t)(tx_gate_bias & 0xFF)};
reply(CMD_READ_TXPWR, sizeof(resp), resp);
}
void cmd_tx_data(int len, uint8_t *data) {
int err = kiss_send_async(len, data);
if (err) {
// Halt and catch fire
reply_error((uint8_t) -err);
} else {
reply(CMD_TXDATA, 0, NULL);
}
}
void cmd_set_freq(uint32_t freq) {
log_info("SET_FREQ: %d Hz\n", freq);
int err = 0;
if (err) {
// Halt and catch fire
reply_error((uint8_t) -err);
} else {
reply(CMD_SET_FREQ, 0, NULL);
}
}
void cmd_get_cfg() {
int err = -127; // ENOTIMPL
log_info("GET_CFG: Not implemented!\n");
if (err) {
reply_error((uint8_t) -err);
} else {
reply(CMD_GET_CFG, 0, NULL);
}
}
void cmd_set_cfg(int len, uint8_t *data) {
int err = 0;
if (len == 0) {
err = -ECMDINVAL;
} else {
log_info("CFG_SET: ver %d\n", data[0]);
}
if (err) {
reply_error((uint8_t) -err);
} else {
reply(CMD_SET_CFG, 0, NULL);
}
}
void cmd_cfg_default() {
int err = 0;
log_info("CFG_DEFAULT\n");
if (err) {
reply_error((uint8_t) -err);
} else {
reply(CMD_CFG_DEFAULT, 0, NULL);
}
}
void cmd_save_cfg() {
int err = 0;
log_info("SAVE_CFG\n");
if (err) {
reply_error((uint8_t) -err);
} else {
reply(CMD_CFG_DEFAULT, 0, NULL);
}
}
void cmd_get_queue_depth() {
int err = 0;
uint16_t depth = 0;
uint8_t data[] = {depth >> 8, depth & 0xFF};
log_info("GET_QUEUE_DEPTH\n");
if (err) {
reply_error((uint8_t) -err);
} else {
reply(CMD_GET_QUEUE_DEPTH, sizeof(data), data);
}
}
void cmd_abort_tx() {
int err = 0;
log_info("ABORT_TX\n");
if (err) {
reply_error((uint8_t) -err);
} else {
reply(CMD_TX_ABORT, 0, NULL);
}
}
void cmd_tx_psr() {
int err = 0;
log_info("TX_PSR\n");
if (err) {
reply_error((uint8_t) -err);
} else {
reply(CMD_TX_PSR, 0, NULL);
}
}
void cmd_err(int err) {
reply_error((uint8_t) err);
}
int reply_putc(uint8_t c) {
uart_putc(c);
return 0;
}