Support adjusting input levels (twist, gain). Support auto-adjust input levels. Support getting & setting RTC. Send API version. Update to 0.8.9.

cert v0.8.9
Rob Riggs 2018-11-02 20:06:27 -05:00
rodzic 11200f234b
commit c33c97a1ef
3 zmienionych plików z 102 dodań i 10 usunięć

Wyświetl plik

@ -136,6 +136,7 @@ void autoAudioInputLevel()
else if (rx_twist > 9) rx_twist = 9;
INFO("TWIST = %ddB", rx_twist);
mobilinkd::tnc::kiss::settings().rx_twist = rx_twist;
mobilinkd::tnc::kiss::settings().announce_input_settings();
mobilinkd::tnc::kiss::settings().update_crc();
mobilinkd::tnc::kiss::settings().store();
}

Wyświetl plik

@ -10,12 +10,14 @@
#include <ModulatorTask.hpp>
#include <memory>
#include <cstdio>
extern I2C_HandleTypeDef hi2c1;
extern RTC_HandleTypeDef hrtc;
namespace mobilinkd { namespace tnc { namespace kiss {
const char FIRMWARE_VERSION[] = "0.8.8";
const char FIRMWARE_VERSION[] = "0.8.9";
const char HARDWARE_VERSION[] = "Mobilinkd TNC3 2.1.1";
Hardware& settings()
@ -24,6 +26,45 @@ Hardware& settings()
return instance;
}
const uint8_t* get_rtc_datetime()
{
static uint8_t buffer[8]; // YYMMDDWWHHMMSS
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BCD);
HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BCD);
buffer[0] = sDate.Year;
buffer[1] = sDate.Month;
buffer[2] = sDate.Date;
buffer[3] = sDate.WeekDay;
buffer[4] = sTime.Hours;
buffer[5] = sTime.Minutes;
buffer[6] = sTime.Seconds;
buffer[7] = 0;
return buffer;
}
void set_rtc_datetime(const uint8_t* buffer)
{
RTC_TimeTypeDef sTime;
RTC_DateTypeDef sDate;
sDate.Year = buffer[0];
sDate.Month = buffer[1];
sDate.Date = buffer[2];
sDate.WeekDay = buffer[3];
sTime.Hours = buffer[4];
sTime.Minutes = buffer[5];
sTime.Seconds = buffer[6];
HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);
HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);
}
void Hardware::set_txdelay(uint8_t value) {
txdelay = value;
update_crc();
@ -96,13 +137,18 @@ void Hardware::set_alias(const hdlc::IoFrame* frame) {
UNUSED(frame);
}
void Hardware::announce_input_settings()
{
reply16(hardware::GET_INPUT_GAIN, input_gain);
reply8(hardware::GET_INPUT_TWIST, rx_twist);
}
void Hardware::handle_request(hdlc::IoFrame* frame) {
static AFSKTestTone testTone;
auto it = frame->begin();
uint8_t command = *it++;
uint8_t v = *it;
switch (command) {
case hardware::SEND_MARK:
@ -121,6 +167,7 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
#if 1
case hardware::SAVE:
case hardware::SAVE_EEPROM_SETTINGS:
update_crc();
store();
reply8(hardware::OK, hardware::SAVE_EEPROM_SETTINGS);
break;
@ -175,14 +222,16 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
osWaitForever);
break;
case hardware::SET_OUTPUT_GAIN:
DEBUG("SET_OUTPUT_VOLUME");
output_gain = v;
output_gain = *it << 8;
++it;
output_gain += *it;
DEBUG("SET_OUTPUT_VOLUME = %d", output_gain);
audio::setAudioOutputLevel();
update_crc();
[[fallthrough]];
case hardware::GET_OUTPUT_GAIN:
DEBUG("GET_OUTPUT_VOLUME");
reply8(hardware::GET_OUTPUT_GAIN, output_gain);
reply16(hardware::GET_OUTPUT_GAIN, output_gain);
break;
case hardware::STREAM_DCD_VALUE:
@ -209,6 +258,14 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
osWaitForever);
break;
case hardware::ADJUST_INPUT_LEVELS:
DEBUG("ADJUST_INPUT_LEVELS");
osMessagePut(audioInputQueueHandle, audio::AUTO_ADJUST_INPUT_LEVEL,
osWaitForever);
osMessagePut(audioInputQueueHandle, audio::STREAM_AMPLIFIED_INPUT_LEVEL,
osWaitForever);
break;
case hardware::SET_VERBOSITY:
DEBUG("SET_VERBOSITY");
log_level = *it ? Log::Level::debug : Log::Level::warn;
@ -229,13 +286,28 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
reply16(hardware::GET_LOWPASS_FREQ, lowpass_freq);
break;
#endif
case hardware::SET_INPUT_GAIN:
input_gain = *it << 8;
++it;
input_gain += *it;
DEBUG("SET_INPUT_GAIN = %d", input_gain);
update_crc();
osMessagePut(audioInputQueueHandle, audio::UPDATE_SETTINGS,
osWaitForever);
osMessagePut(audioInputQueueHandle, audio::STREAM_AMPLIFIED_INPUT_LEVEL,
osWaitForever);
[[fallthrough]];
case hardware::GET_INPUT_GAIN:
DEBUG("GET_INPUT_GAIN");
reply16(hardware::GET_INPUT_GAIN, input_gain);
break;
case hardware::SET_INPUT_TWIST:
DEBUG("SET_INPUT_TWIST");
rx_twist = *it;
update_crc();
osMessagePut(audioInputQueueHandle, audio::UPDATE_SETTINGS,
osWaitForever);
osMessagePut(audioInputQueueHandle, audio::DEMODULATOR,
osMessagePut(audioInputQueueHandle, audio::STREAM_AMPLIFIED_INPUT_LEVEL,
osWaitForever);
[[fallthrough]];
case hardware::GET_INPUT_TWIST:
@ -346,6 +418,15 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
options & KISS_OPTION_VIN_POWER_ON ? 1 : 0);
break;
case hardware::SET_DATETIME:
DEBUG("SET_DATETIME");
set_rtc_datetime(&*it);
[[fallthrough]];
case hardware::GET_DATETIME:
DEBUG("GET_DATETIME");
reply(hardware::GET_DATETIME, get_rtc_datetime(), 7);
break;
case hardware::GET_CAPABILITIES:
DEBUG("GET_CAPABILITIES");
reply16(hardware::GET_CAPABILITIES,
@ -355,13 +436,13 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
case hardware::GET_ALL_VALUES:
DEBUG("GET_ALL_VALUES");
reply16(hardware::GET_API_VERSION, hardware::KISS_API_VERSION);
osMessagePut(audioInputQueueHandle, audio::POLL_BATTERY_LEVEL,
osWaitForever);
osMessagePut(audioInputQueueHandle, audio::POLL_TWIST_LEVEL,
osWaitForever);
osMessagePut(audioInputQueueHandle, audio::IDLE,
osWaitForever);
reply16(hardware::GET_API_VERSION, hardware::KISS_API_VERSION);
reply(hardware::GET_FIRMWARE_VERSION, (uint8_t*) FIRMWARE_VERSION,
sizeof(FIRMWARE_VERSION) - 1);
reply(hardware::GET_HARDWARE_VERSION, (uint8_t*) HARDWARE_VERSION,
@ -370,8 +451,9 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
sizeof(serial_number_64) - 1);
reply8(hardware::GET_USB_POWER_OFF, options & KISS_OPTION_VIN_POWER_OFF ? 0 : 1);
reply8(hardware::GET_USB_POWER_ON, options & KISS_OPTION_VIN_POWER_ON ? 0 : 1);
reply8(hardware::GET_OUTPUT_GAIN, output_gain);
reply16(hardware::GET_OUTPUT_GAIN, output_gain);
reply8(hardware::GET_OUTPUT_TWIST, tx_twist);
reply16(hardware::GET_INPUT_GAIN, input_gain);
reply8(hardware::GET_INPUT_TWIST, rx_twist);
reply8(hardware::GET_VERBOSITY, log_level == Log::Level::debug);
reply8(hardware::GET_TXDELAY, txdelay);
@ -386,6 +468,9 @@ void Hardware::handle_request(hdlc::IoFrame* frame) {
hardware::CAP_ADJUST_INPUT);
reply16(hardware::GET_MIN_INPUT_GAIN, 0);
reply16(hardware::GET_MAX_INPUT_GAIN, 4);
reply8(hardware::GET_MIN_INPUT_TWIST, -3);
reply8(hardware::GET_MAX_INPUT_TWIST, 9);
reply(hardware::GET_DATETIME, get_rtc_datetime(), 7);
break;
case hardware::EXTENDED_CMD:

Wyświetl plik

@ -120,9 +120,13 @@ constexpr const uint8_t GET_BT_POWER_OFF = 78;
constexpr const uint8_t SET_PTT_CHANNEL = 79; // Which PTT line to use (currently 0 or 1,
constexpr const uint8_t GET_PTT_CHANNEL = 80; // multiplex or simplex)
constexpr const uint8_t GET_MIN_OUTPUT_TWIST = 119; ///< int8_t (may be negative).
constexpr const uint8_t GET_MAX_OUTPUT_TWIST = 120; ///< int8_t (may be negative).
constexpr const uint8_t GET_MIN_INPUT_TWIST = 121; ///< int8_t (may be negative).
constexpr const uint8_t GET_MAX_INPUT_TWIST = 122; ///< int8_t (may be negative).
constexpr const uint8_t GET_API_VERSION = 123; ///< uint16_t (major/minor)
constexpr const uint8_t GET_MIN_INPUT_GAIN = 124; ///< int16_t (may be negative/attenuated).
constexpr const uint8_t GET_MAX_INPUT_GAIN = 125; ///< int16_t (may be negative/attenuated).
constexpr const uint8_t GET_MIN_INPUT_GAIN = 124; ///< int8_t (may be negative/attenuated).
constexpr const uint8_t GET_MAX_INPUT_GAIN = 125; ///< int8_t (may be negative/attenuated).
constexpr const uint8_t GET_CAPABILITIES = 126; ///< Send all capabilities.
constexpr const uint8_t GET_ALL_VALUES = 127; ///< Send all settings & versions.
@ -331,6 +335,8 @@ struct Hardware
void get_alias(uint8_t alias);
void set_alias(const hdlc::IoFrame* frame);
void announce_input_settings();
}; // 812 bytes
extern Hardware& settings();