Continuing move to both OO interface and consolidation of commands into Subsystem, Command rather than all discrete commands.

This commit is contained in:
2026-01-26 13:42:28 -06:00
parent 152e0c2d80
commit 4e0035bea6
5 changed files with 374 additions and 188 deletions

View File

@@ -260,6 +260,8 @@ void EnumerateComPorts();
unsigned long Hex2Dec(uint8_t *p, int dig);
//void ShowAllStatusInfo();
void GetAndSendCustomMessage();
bool UserWantsToExitCanSniff = false;
DWORD progStartTime_ms;
@@ -279,8 +281,8 @@ typedef struct {
//
const UserCmd_T UserCommands[] = {
{ 'R', "Ready", {"\x11" "000" "\x03", 5 } },
{ 'P', "Power On", {"\x02" "07A1D" "\x03", 7} },
{ 'p', "Power Off", {"\x02" "07A1E" "\x03", 7} },
//{ 'P', "Power On", {"\x02" "07A1D" "\x03", 7} },
//{ 'p', "Power Off", {"\x02" "07A1E" "\x03", 7} },
{ '1', "Zone 1 On", {"\x02" "07E7E" "\x03", 7} },
{ '!', "Zone 1 Standby", {"\x02" "07E7F" "\x03", 7} },
{ '2', "Zone 2 On", {"\x02" "07EBA" "\x03", 7} },
@@ -299,6 +301,10 @@ const UserCmd_T UserCommands[] = {
{ 'u', "Zone 2 Name rqst", {"\x02" "22004" "\x03", 7} },
{ 'I', "Zone 2 Vol rqst", {"\x02" "22005" "\x03", 7} },
{ 'i', "Zone 2 Name rqst", {"\x02" "22006" "\x03", 7} },
//{ 'J', "Dual Mono - Main", {"\x02" "07E93" "\x03", 7} },
//{ 'K', "Dual Mono - Sub", {"\x02" "07E94" "\x03", 7} },
//{ 'L', "Dual Mono - All", {"\x02" "07E95" "\x03", 7} },
{ ':', "Custom Message" },
{ '/', "Show All" },
{ '?', "Help on runtime commands" },
{ 'S', "Set RTS" },
@@ -357,11 +363,11 @@ const MessageHandler_T MessageHandlers[] = {
{ 0x00, 7, 1, 1, "System Report: %s", BusyToText },
{ 0x01, 0, 0, 0, "Warning Report: %s", WarnToText },
{ 0x10, 31, 1, 1, "Playback Report: %s", PlaybackToText },
{ 0x11, 32, 1, 1, "Fs Report: %s", FsToText },
{ 0x12, 33, 1, 1, "Ex/Ex: %s", OffMatrixDiscreteText }, // EX/EX
{ 0x13, 34, 1, 1, "Thr Bypass: %s", OffOnText }, // Thr / Bypass
{ 0x14, 35, 1, 1, "RED dts: %s", ReleaseWaitText}, // RED dts
{ 0x15, 38, 1, 1, "Tuner tuned: %s", NotTunedTunedText}, // Tuner tuned
{ 0x11, 32, 1, 1, "Fs Report: %s", FsToText }, --
{ 0x12, 33, 1, 1, "Ex/Ex: %s", OffMatrixDiscreteText }, // EX/EX --
{ 0x13, 34, 1, 1, "Thr Bypass: %s", OffOnText }, // Thr / Bypass --
{ 0x14, 35, 1, 1, "RED dts: %s", ReleaseWaitText}, // RED dts --
{ 0x15, 38, 1, 1, "Tuner tuned: %s", NotTunedTunedText}, // Tuner tuned --
{ 0x16, 43, 1, 1, "DTS 96/24: %s", OffOnText}, // Dts 96/24
{ 0x20, 8, 0, 1, "Zone Power: %s", ZonePower },
{ 0x21, 9, 1, 1, "Input: %s", InputText}, // Input Source
@@ -371,11 +377,11 @@ const MessageHandler_T MessageHandlers[] = {
{ 0x25, 14, 1, 1, "Zone 2 Mute: %s", OffOnText },
{ 0x26, 15, 2, 1, "Volume: %s", VolumeDB },
{ 0x27, 17, 2, 1, "Zone 2 Vol: %s", VolumeDB}, // Zone 2 Vol
{ 0x28, 19, 2, 1, "Program: %s", ProgramName }, // Program
{ 0x29, 25, 1, 1, "Tuner Page: %s", PresetLabelText}, // Tuner Page
{ 0x2A, 26, 1, 1, "Tuner Preset: %s", PresetNumberText}, // Tuner Preset Number
{ 0x2B, 23, 1, 1, "OSD: %s", OSDFullShortOffText}, // OSD
{ 0x2C, 24, 1, 1, "Sleep: %s", SleepTimerText}, // Sleep Timer
{ 0x28, 19, 2, 1, "Program: %s", ProgramName }, // Program --
{ 0x29, 25, 1, 1, "Tuner Page: %s", PresetLabelText}, // Tuner Page --
{ 0x2A, 26, 1, 1, "Tuner Preset: %s", PresetNumberText}, // Tuner Preset Number --
{ 0x2B, 23, 1, 1, "OSD: %s", OSDFullShortOffText}, // OSD --
{ 0x2C, 24, 1, 1, "Sleep: %s", SleepTimerText}, // Sleep Timer --
{ 0x2D, 22, 1, 1, "EX/ES(Key): %s", OffMatrixDiscreteAutoText}, // EX/ES(Key)
{ 0x2E, 29, 1, 1, "SP Relay A: ", OffOnText}, // Speaker Relay A
{ 0x2F, 30, 1, 1, "SP Relay B: ", OffOnText}, // Speaker Relay B
@@ -383,45 +389,45 @@ const MessageHandler_T MessageHandlers[] = {
{ 0x31, 0, 0, 0, "Home Memory:%s", PresetLabelText }, // Preset A, B, ... F
{ 0x32, 0, 0, 0, "Home Vol Preset: %s", PresetLabelText }, // Preset A, B, ... F
{ 0x33, 0, 0, 0, "Home Vol Memory: %s", PresetLabelText }, // Preset A, B, ... F
{ 0x34, 36, 1, 1, "Headphone: %s", OffOnText },
{ 0x35, 37, 1, 1, "FM/AM: %s", FMAMText },
{ 0x36, 39, 1, 1, "DC1 Trigger Out: %s", OffOnText },
{ 0x34, 36, 1, 1, "Headphone: %s", OffOnText }, --
{ 0x35, 37, 1, 1, "FM/AM: %s", FMAMText }, --
{ 0x36, 39, 1, 1, "DC1 Trigger Out: %s", OffOnText }, --
{ 0x37, 0, 0, 0, "Home Zone 2 Vol Preset: %s", PresetLabelText },
{ 0x38, 0, 0, 0, "Home Zone 2 Vol: %s", PresetLabelText },
{ 0x39, 0, 0, 0, "Dual Mono: %s", MainSubAllText },
{ 0x3A, 42, 1, 1, "DC1 Trigger Control: %s", WhichZoneText },
{ 0x3B, 44, 1, 1, "DC2 Trigger Control: %s", WhichZoneText },
{ 0x3C, 45, 1, 1, "DC2 Trigger Out: %s", OffOnText },
{ 0x3A, 42, 1, 1, "DC1 Trigger Control: %s", WhichZoneText }, --
{ 0x3B, 44, 1, 1, "DC2 Trigger Control: %s", WhichZoneText }, --
{ 0x3C, 45, 1, 1, "DC2 Trigger Out: %s", OffOnText }, --
{ 0x3D, 104, 0, 0, "Main Level: %s", Norm10dbDownText },
{ 0x3E, 46, 1, 1, "SP B Set: %s", MainZoneBText },
{ 0x3E, 46, 1, 1, "SP B Set: %s", Zone1Zone2Text },
{ 0x3F, 47, 1, 1, "Zone 2 Speaker: %s", OffOnText },
{ 0x40, 48, 2, 1, "Level Main R: %s", PM10dbText },
{ 0x41, 50, 2, 1, "Level Main L: %s", PM10dbText },
{ 0x42, 52, 2, 1, "Level Center: %s", PM10dbText },
{ 0x43, 54, 2, 1, "Level Rear R: %s", PM10dbText },
{ 0x44, 56, 2, 1, "Level Rear L: %s", PM10dbText },
{ 0x45, 58, 2, 1, "Level Sur Back R: %s", PM10dbText },
{ 0x46, 60, 2, 1, "Level Sur Back L: %s", PM10dbText },
{ 0x47, 62, 2, 1, "Level Front R: %s", PM10dbText },
{ 0x48, 64, 2, 1, "Level Front L: %s", PM10dbText },
{ 0x49, 66, 2, 1, "Level Swfr 1: %s", PM10dbText },
{ 0x40, 48, 2, 1, "Level Main R: %s", PM10dbText }, --
{ 0x41, 50, 2, 1, "Level Main L: %s", PM10dbText }, --
{ 0x42, 52, 2, 1, "Level Center: %s", PM10dbText }, --
{ 0x43, 54, 2, 1, "Level Rear R: %s", PM10dbText }, --
{ 0x44, 56, 2, 1, "Level Rear L: %s", PM10dbText }, --
{ 0x45, 58, 2, 1, "Level Sur Back R: %s", PM10dbText }, --
{ 0x46, 60, 2, 1, "Level Sur Back L: %s", PM10dbText }, --
{ 0x47, 62, 2, 1, "Level Front R: %s", PM10dbText }, --
{ 0x48, 64, 2, 1, "Level Front L: %s", PM10dbText }, --
{ 0x49, 66, 2, 1, "Level Swfr 1: %s", PM10dbText }, --
{ 0x4A, 0, 0, 0, "Level Swfr 2: %s", PM10dbText },
{ 0x50, 0, 0, 0, "Main L/R Bal: %s", BalanceText },
{ 0x51, 74, 2, 1, "LFE Level SP: %s", M20P0dbText },
{ 0x52, 76, 2, 1, "LFE Level HP: %s", M20P0dbText },
{ 0x53, 78, 2, 1, "Audio Delay: %s", ZeroTo160msText },
{ 0x51, 74, 2, 1, "LFE Level SP: %s", M20P0dbText }, --
{ 0x52, 76, 2, 1, "LFE Level HP: %s", M20P0dbText }, --
{ 0x53, 78, 2, 1, "Audio Delay: %s", ZeroTo160msText }, --
{ 0x54, 0, 0, 0, "SP Delay Center: %s", ZeroTo5msText },
{ 0x55, 0, 0, 0, "SP Delay Rear CT: %s", ZeroTo30msText },
{ 0x60, 84, 1, 1, "Input Mode: %s", AutoLastText },
{ 0x61, 85, 1, 1, "Dimmer: %s", M4To0Text },
{ 0x62, 87, 2, 1, "OSD Shift: %s", M5toP5Text },
{ 0x63, 89, 1, 1, "Gray Back: %s", OffAutoText },
{ 0x64, 91, 1, 1, "Dynamic Range SP: %s", MaxStdMinText },
{ 0x65, 92, 1, 1, "Dynamic Range HP: %s", MaxStdMinText },
{ 0x66, 93, 0, 0, "Zone 2 Vol out: %s", VarFixText },
{ 0x60, 84, 1, 1, "Input Mode: %s", AutoLastText }, --
{ 0x61, 85, 1, 1, "Dimmer: %s", M4To0Text }, --
{ 0x62, 87, 2, 1, "OSD Shift: %s", M5toP5Text }, --
{ 0x63, 89, 1, 1, "Gray Back: %s", OffAutoText }, --
{ 0x64, 91, 1, 1, "Dynamic Range SP: %s", MaxStdMinText }, --
{ 0x65, 92, 1, 1, "Dynamic Range HP: %s", MaxStdMinText }, --
{ 0x66, 93, 0, 0, "Zone 2 Vol out: %s", VarFixText }, --
{ 0x67, 0, 0, 0, "Zone 2 Mode: %s", Mode1Mode2Text },
{ 0x68, 95, 1, 1, "Mem Guard: %s", OffOnText },
{ 0x69, 90, 1, 1, "Video Conv: %s", OffOnText },
@@ -432,7 +438,7 @@ const MessageHandler_T MessageHandlers[] = {
{ 0x72, 98, 1, 1, "Rear LR Sp Size: %s", LSNText },
{ 0x73, 99, 1, 1, "Sur Back Size: %s", LLSSNText },
{ 0x74, 100, 1, 1, "Front Sp: %s", YesNoneText },
{ 0x75, 101, 1, 1, "LFE Bass Out: %s", SwfrMainBothText },
{ 0x75, 101, 1, 1, "LFE Bass Out: %s", SwfrMainBothText }, --
{ 0x76, 134, 1, 1, "SW1: %s", LrFrNoneText },
{ 0x78, 102, 1, 1, "6 Ch Center: %s", CenterMainText },
@@ -441,23 +447,23 @@ const MessageHandler_T MessageHandlers[] = {
{ 0x7B, 0, 0, 0, "Multi Ch Select: %s", SixEightText },
{ 0x7E, 135, 1, 1, "SW Crossover", CrossOverText },
{ 0x80, 105, 1, 1, "Test Mode: %s", OffDolbyDspText },
{ 0x80, 105, 1, 1, "Test Mode: %s", OffDolbyDspText }, --
{ 0x81, 0, 0, 0, "Analog Special: %s", OffOn2OnMultiText },
{ 0x82, 27, 1, 1, "Night Mode: %s", OffOnText },
{ 0x82, 27, 1, 1, "Night Mode: %s", OffOnText }, --
{ 0x90, 0, 0, 0, "Multi Ch Level Main R: %s", M10P10dbText },
{ 0x91, 0, 0, 0, "Multi Ch Level Main L: %s", M10P10dbText },
{ 0x92, 0, 0, 0, "Multi Ch Level Center: %s", M10P10dbText },
{ 0x93, 0, 0, 0, "Multi Ch Level Rear R: %s", M10P10dbText },
{ 0x94, 0, 0, 0, "Multi Ch Level Rear L: %s", M10P10dbText },
{ 0x95, 0, 0, 0, "Multi Ch Level Sur B R: %s", M10P10dbText },
{ 0x96, 0, 0, 0, "Multi Ch Level Sur B L: %s", M10P10dbText },
{ 0x97, 0, 0, 0, "Multi Ch Level Front R: %s", M10P10dbText },
{ 0x98, 0, 0, 0, "Multi Ch Level Front L: %s", M10P10dbText },
{ 0x99, 0, 0, 0, "Multi Ch Level Swfr 1: %s", M20P0dbText },
{ 0x9A, 0, 0, 0, "Multi Ch Level Swfr 2: %s", M20P0dbText },
{ 0x90, 0, 0, 0, "Multi Ch Level Main R: %s" , M10P10dbText }, --
{ 0x91, 0, 0, 0, "Multi Ch Level Main L: %s" , M10P10dbText }, --
{ 0x92, 0, 0, 0, "Multi Ch Level Center: %s" , M10P10dbText }, --
{ 0x93, 0, 0, 0, "Multi Ch Level Rear R: %s" , M10P10dbText }, --
{ 0x94, 0, 0, 0, "Multi Ch Level Rear L: %s" , M10P10dbText }, --
{ 0x95, 0, 0, 0, "Multi Ch Level Sur B R: %s", M10P10dbText }, --
{ 0x96, 0, 0, 0, "Multi Ch Level Sur B L: %s", M10P10dbText }, --
{ 0x97, 0, 0, 0, "Multi Ch Level Front R: %s", M10P10dbText }, --
{ 0x98, 0, 0, 0, "Multi Ch Level Front L: %s", M10P10dbText }, --
{ 0x99, 0, 0, 0, "Multi Ch Level Swfr 1: %s" , M20P0dbText }, --
{ 0x9A, 0, 0, 0, "Multi Ch Level Swfr 2: %s" , M20P0dbText },
{ 0xA1, 0, 0, 0, "Zone 3 Mute: %s\n", OffOnText },
{ 0xA1, 0, 0, 0, "Zone 3 Mute: %s\n", OffOnText }, --
};
void MessageHandlerSanityCheck() {
@@ -574,24 +580,23 @@ void EmitBuffer(const char *prefix, const uint8_t *buf, size_t len = 0, bool app
}
}
#if 0
void EchoSerialRecv(const uint8_t *pMsg) {
Console_SetCursor(0, -1);
EmitBuffer("< ", pMsg);
Console_ScrollBottomRegion();
}
#endif
bool SerialSend(const uint8_t *p, uint16_t len) {
bool retVal = false;
Console_SetCursor(0, -1);
EmitBuffer("> ", p, len);
Console_ScrollBottomRegion();
//Console_SetCursor(0, -1);
//EmitBuffer("> ", p, len);
//Console_ScrollBottomRegion();
if (avrPort.Write((const LPVOID)p, len) == len) {
retVal = true;
} else {
Console_SetCursor(0, -1);
Console_Write("***** Failed to send. Port not open?");
Console_ScrollBottomRegion();
Console_WriteAt(0, -1, "***** Failed to send. Port not open?");
}
return retVal;
}
@@ -826,10 +831,10 @@ void ProcessKeyboard(void) {
int c = CS_GetChar();
switch (c) {
case 'P':
avr->Power(AVRInterface::avrPowerOn);
avr->Power(AVRInterface::AVROnOff_E::eOn);
break;
case 'p':
avr->Power(AVRInterface::avrPowerOff);
avr->Power(AVRInterface::AVROnOff_E::eOff);
break;
case 'O':
ProcessSerialQueue((const uint8_t *)"\x02" "21000" "\x03", 7);
@@ -838,6 +843,9 @@ void ProcessKeyboard(void) {
ProcessSerialQueue((const uint8_t *)"\x02" "3sage" "\x03", 7);
ProcessSerialQueue((const uint8_t *)"\x02" "3 WOW" "\x03", 7);
break;
case ':':
GetAndSendCustomMessage();
break;
case '?':
EmitRuntimeHelp();
break;
@@ -863,7 +871,8 @@ void ProcessKeyboard(void) {
default:
for (int i = 0; i < sizeof(UserCommands) / sizeof(UserCmd_T); i++) {
if (UserCommands[i].Char == c) {
ProcessSerialQueue((const uint8_t *)UserCommands[i].TxMsg.pMsg, UserCommands[i].TxMsg.MsgLen);
//ProcessSerialQueue((const uint8_t *)UserCommands[i].TxMsg.pMsg, UserCommands[i].TxMsg.MsgLen);
avr->ProcessSerialQueue((const uint8_t *)UserCommands[i].TxMsg.pMsg, UserCommands[i].TxMsg.MsgLen);
cmdFound = true;
break;
}
@@ -879,6 +888,18 @@ void ProcessKeyboard(void) {
return;
}
void GetAndSendCustomMessage() {
char buf[20];
char msg[30];
Console_ScrollBottomRegion();
Console_ScrollBottomRegion();
Console_WriteAt(0, -2, "Enter Hex string to send: ");
gets_s(buf, sizeof(buf));
Console_ScrollBottomRegion();
sprintf_s(msg, sizeof(msg), "\x02%s\x03", buf);
avr->ProcessSerialQueue(msg, strlen(msg));
}
void GetProgName(char *name) {
char *p = strrchr(name, '\\');
@@ -925,7 +946,7 @@ void InformationUpdate(AVRInterface::AVRMessageType_T type, const char *msg) {
Console_SetCursor(0, 3);
// break; // fall through
case AVRInterface::AVRMessageType_T::mtStream:
Console_AdvanceToNextLineIfNotRoomFor(26); // @TODO hard-coded - ick
Console_AdvanceToNextLineIfNotRoomFor(40); // @TODO hard-coded - ick
Console_Write(msg);
break;
default:
@@ -937,7 +958,7 @@ void InformationUpdate(AVRInterface::AVRMessageType_T type, const char *msg) {
/* m a i n ( ) */
/******************************************************/
// 0 99
// 0 Width
// +---------------------------------------------------------------+
// | Program banner information | 0
// | State machine status information starts on line 2 |
@@ -952,7 +973,7 @@ void InformationUpdate(AVRInterface::AVRMessageType_T type, const char *msg) {
// +---------------------------------------------------------------+ 80
int __cdecl main(int argc, char *argv[]) {
short consoleWidth = 105;
short consoleWidth = 122;
short consoleHeight = 80;
short consoleScrollHeight = 30;
@@ -1001,7 +1022,7 @@ int __cdecl main(int argc, char *argv[]) {
SerialQueue_T anyRcvdMsg = ProcessSerialReceive();
if (anyRcvdMsg.len) {
// Show to the user
EchoSerialRecv(anyRcvdMsg.message);
//EchoSerialRecv(anyRcvdMsg.message);
// Let the AVR interface handle it first
bool showAllFlag = avr->HandleMessage(anyRcvdMsg.message, anyRcvdMsg.len);

View File

@@ -106,6 +106,15 @@ const char *YesNoneText(uint8_t val) {
return buf[val];
}
const char *PRSBText(uint8_t val) {
static const char *buf[] = {
"PR", "SB", "Unk"
};
if (val >= sizeof(buf) / sizeof(buf[0]))
val = sizeof(buf) / sizeof(buf[0]) - 1;
return buf[val];
}
const char *OffMatrixDiscreteText(uint8_t val) {
static const char *buf[] = {
"Off", "Matrix On", "Discrete On", "Unk"
@@ -244,9 +253,9 @@ const char *Norm10dbDownText(uint8_t val) {
return buf[val];
}
const char *MainZoneBText(uint8_t val) {
const char *Zone1Zone2Text(uint8_t val) {
static const char *buf[] = {
"Main", "Zone B", "Unk"
"Zone 1", "Zone 2", "Unk"
};
if (val >= sizeof(buf) / sizeof(buf[0]))
val = sizeof(buf) / sizeof(buf[0]) - 1;
@@ -417,35 +426,35 @@ const char *ProgramName(uint8_t val) {
returnBuf[0] = '\0';
if (val & 0x80) {
strcpy_s(returnBuf, TEXTBUFLEN, "STRAIGHT ");
strcpy_s(returnBuf, TEXTBUFLEN, "St.");
}
val &= 0x7F; // Not accommodating the other variants yet
const char *nameList[] = {
"Hall A (HALL1)",
"Hall A", // (HALL1)
"Hall B",
"Hall C",
"unk",
"Hall C",
"Hall E",
"Live Concert (HALL2)",
"Live Concert", // (HALL2)
"unk",
"Tokyo",
"Freiburg (CHURCH)",
"Church", // Freiburg (CHURCH)
"Royaumont",
"unk",
"Village Gate",
"Village Vanguard",
"The Bottom Line (JAZZ)",
"Vanguard", // Village Vanguard
"Jazz", // The Bottom Line (JAZZ)
"unk",
"The Roxy Theater (ROCK)",
"Warehouse Loft",
"Rock", // The Roxy Theater (ROCK)
"Warehouse", // Warehouse Loft
"Arena",
"unk",
"Disco",
"Party",
"Game",
"7 Ch Stereo",
"Pop/Rock (Music Video)",
"Music Video", // Pop/Rock (Music Video)
"DJ",
"unk",
"unk",
@@ -454,11 +463,11 @@ const char *ProgramName(uint8_t val) {
"unk",
"unk",
"Mono Movie",
"Variety Sports",
"Sports", // Variety Sports
"unk",
"unk",
"Spectacre",
"Sci - Fi",
"Sci-Fi",
"unk",
"unk",
"Adventure",
@@ -473,8 +482,8 @@ const char *ProgramName(uint8_t val) {
"PLII Music",
"Neo: 6 Movie",
"Neo: 6 Music",
"STEREO A 2CH Stereo",
"STEREO B 2CH Direct Stereo"
"Stereo A 2Ch",
"Direct B 2Ch"
"THX A Cinema",
"THX B Music",
};
@@ -512,7 +521,7 @@ const char *VolumeDB(uint8_t val) {
b = -99.5f;
}
float db = m * val + b;
sprintf_s(buf, sizeof(buf), "%+5.1f db", db);
sprintf_s(buf, sizeof(buf), "%+3.1f db", db);
return buf;
}
@@ -526,7 +535,7 @@ const char *PM10dbText(uint8_t val) {
m = 0.5f;
b = -10.0f;
float db = m * (val - 0x14) + b;
sprintf_s(buf, sizeof(buf), "%+5.1f db", db);
sprintf_s(buf, sizeof(buf), "%+3.1f db", db);
}
return buf;
}
@@ -541,7 +550,7 @@ const char *M20P0dbText(uint8_t val) {
m = 0.5f;
b = -20.0f;
float db = m * (val)+b;
sprintf_s(buf, sizeof(buf), "%+5.1f db", db);
sprintf_s(buf, sizeof(buf), "%+3.1f db", db);
}
return buf;
}
@@ -556,7 +565,7 @@ const char *M10P10dbText(uint8_t val) {
m = 0.5f;
b = -10.0f;
float db = m * (val - 0x14) + b;
sprintf_s(buf, sizeof(buf), "%+5.1f db", db);
sprintf_s(buf, sizeof(buf), "%+3.1f db", db);
}
return buf;
}

View File

@@ -46,10 +46,11 @@ const char *M10P10dbText(uint8_t val);
const char *ProgramName(uint8_t val);
const char *OffOnText(uint8_t val);
const char *PRSBText(uint8_t val);
const char *FMAMText(uint8_t val);
const char *PresetLabelText(uint8_t val);
const char *MainSubAllText(uint8_t val);
const char *WhichZoneText(uint8_t val);
const char *Norm10dbDownText(uint8_t val);
const char *MainZoneBText(uint8_t val);
const char *Zone1Zone2Text(uint8_t val);

View File

@@ -7,6 +7,8 @@
#include <memory.h>
#include <string.h>
#include <malloc.h>
#include <ctype.h>
#include "AVRInterface.h"
#include "AVRCommandDecoder.h"
@@ -60,6 +62,11 @@ static const Message_T AVRCommands[] = {
{ eUnMute, "\x02" "07EA3" "\x03", 7 },
};
// This is based on the longest thing from the MessageHandlers text field and the generated text
// "MultiCh Surround" "Surround"
const char *PCMessageFormat = "%18s %-20s";
const uint8_t LengthCheck = 40;
// rCmd: 2-ASCII Hex Bytes converted to uint8_t
// configOffset: offset into avrStatus.config.DTxx
// numToTransfer: number of bytes to transfer from message to config (0 = none)
@@ -117,7 +124,7 @@ static const MessageHandler_T MessageHandlers[] = {
{ 0x3B, 44, 1, 1, "DC2 Trigger Control: %s", WhichZoneText },
{ 0x3C, 45, 1, 1, "DC2 Trigger Out: %s", OffOnText },
{ 0x3D, 104, 0, 0, "Main Level: %s", Norm10dbDownText },
{ 0x3E, 46, 1, 1, "SP B Set: %s", MainZoneBText },
{ 0x3E, 46, 1, 1, "SP B Set: %s", Zone1Zone2Text },
{ 0x3F, 47, 1, 1, "Zone 2 Speaker: %s", OffOnText },
{ 0x40, 48, 2, 1, "Level Main R: %s", PM10dbText },
@@ -210,8 +217,62 @@ bool AVRInterface::IsSanityCheckOK() {
return true;
}
// MessageReport
//
// Generate a text record to provide buffer to the console, translating non-printable
// characters into hex codes enclosed in square brackets.
//
// Consider line-wrapping to align the next line
//
void AVRInterface::MessageReport(const char *prefix, const void *buf, size_t len) {
int i = 0;
const char *p = (const char *)buf;
uint32_t now_ms = lastTick_ms;
char txtBuf[LONGESTTEXT] = "";
char smallBuf[10] = "";
char *pTxtAppend = txtBuf;
if (len == 0) len = strlen(p);
pTxtAppend += sprintf_s(txtBuf, LONGESTTEXT, "%9.3f: [%3d]%s", (float)(now_ms - firstTick_ms) / 1000.0f, (int)strlen(p), prefix);
while (*p && ((unsigned)(p - (const char *)buf) < len)) {
if (isprint(*p)) {
*pTxtAppend++ = *p;
*pTxtAppend = 0; // Keep it null-terminated
i++;
} else if (*p == '\r') {
(*ReportInformation)(mtInfo, txtBuf);
txtBuf[0] = 0; // clear it
} else if (*p == '\n') {
// skip it
} else {
sprintf_s(smallBuf, 10, "[%02X]", (unsigned char)*p);
strcat_s(txtBuf, LONGESTTEXT, smallBuf);
pTxtAppend = txtBuf + strlen(txtBuf);
}
if ((i & 3) == 0) {
if (strlen(txtBuf) > 100) {
(*ReportInformation)(mtInfo, txtBuf);
sprintf_s(txtBuf, LONGESTTEXT, " "); // new line
pTxtAppend = txtBuf + strlen(txtBuf);
} else {
strcat_s(txtBuf, LONGESTTEXT, " ");
pTxtAppend++;
}
i = 0;
}
p++;
}
if (strlen(txtBuf)) {
(*ReportInformation)(mtInfo, txtBuf);
}
}
void AVRInterface::Tick(uint32_t now_ms) {
lastTick_ms = now_ms;
uint32_t elapsed_ms = now_ms - sentAtTime_ms;
char buf[LONGESTTEXT] = "";
if (oldState != state && ReportInformation) {
oldState = state;
@@ -259,7 +320,8 @@ void AVRInterface::Tick(uint32_t now_ms) {
/// @brief Handle a just received message by parsing it
///
/// Given a response string, typically of the form:
/// [11] .... [03]
/// [02] .... [03] // Command Responses from the AVR
/// [11] .... [03] // Commands to
/// [12] .... [03]
/// [14] ............ [03]
///
@@ -270,6 +332,7 @@ void AVRInterface::Tick(uint32_t now_ms) {
bool AVRInterface::HandleMessage(const uint8_t *buffer, uint16_t len) {
bool showAllFlag = false;
MessageReport("<", buffer, len);
switch (state) {
case stAwaitingReadyResponse:
switch (buffer[0]) {
@@ -278,6 +341,7 @@ bool AVRInterface::HandleMessage(const uint8_t *buffer, uint16_t len) {
showAllFlag = ProcessReportResponse(buffer, len);
break;
case 0x11: // DC1 <msg> ETX
// AVR does not send any DC1 messages, these are for commands to the AVR
break;
case 0x12: // DC2 <msg> ETX
if (CheckTheChecksum(buffer, len)) {
@@ -359,9 +423,9 @@ bool AVRInterface::Initialize() {
bool AVRInterface::IsOnline() {
return true;
}
bool AVRInterface::Power(AVRPower_T cmd) {
bool AVRInterface::Power(AVROnOff_E cmd) {
commandResponseReceived = false;
if (cmd == avrPowerOn)
if (cmd == eOn)
ProcessSerialQueue(AVRCommands[ePowerOn].pMsg, AVRCommands[ePowerOn].MsgLen);
else
ProcessSerialQueue(AVRCommands[ePowerOff].pMsg, AVRCommands[ePowerOff].MsgLen);
@@ -369,10 +433,19 @@ bool AVRInterface::Power(AVRPower_T cmd) {
return true;
}
bool AVRInterface::MasterVolumeButton(AVRVolumeButton_T cmd) {
return true;
}
bool AVRInterface::Mute(AVRMute_T cmd) {
bool AVRInterface::VolumeButton(AVRVolume_E cmd) {
switch (cmd) {
case eVolumeUp:
break;
case eVolumeDown:
break;
case eMuteOn:
break;
case eMuteOff:
break;
default:
return false;
}
return true;
}
@@ -388,6 +461,7 @@ bool AVRInterface::ProcessSerialQueue(const void *msg, uint16_t len) {
if (p && len) {
if (serialQueueCount < SERIALQUEUESIZE) {
MessageReport(">", msg, len);
serialQueue[serialQueueCount].messageToSend = (uint8_t *)malloc(len + 1);
if (serialQueue[serialQueueCount].messageToSend) {
memcpy(serialQueue[serialQueueCount].messageToSend, p, len);
@@ -493,6 +567,7 @@ bool AVRInterface::ProcessReportResponse(const uint8_t *szBuffer, uint32_t len)
if (MessageHandlers[i].showAll) {
showAllFlag = true; // ShowAllStatusInfo();
}
break; // no need to scan more
}
}
if (!found) {
@@ -558,14 +633,18 @@ void AVRInterface::PCMessage(const char *msg, int len, uint8_t **src, const char
}
char outBuf[LONGESTTEXT] = "";
sprintf_s(outBuf, LONGESTTEXT, "%17s %-8s",
sprintf_s(outBuf, LONGESTTEXT, PCMessageFormat,
msg,
p
);
(*ReportInformation)(mtStream, outBuf);
}
/// ReportAllStatus
///
/// This emits (via a callback) all the status, in DT0 to DT137 order.
/// You cannot rearrange the sequence to make grouping more logical.
///
void AVRInterface::ReportAllStatus() {
if (avrStatus.headerValid) {
char buf[LONGESTTEXT];
@@ -584,97 +663,97 @@ void AVRInterface::ReportAllStatus() {
PCMessage("Power", 1, &p, OffOnText);
if (avrStatus.configValid) {
PCMessage("Input", 1, &p, InputText);
PCMessage("6 ch", 1, &p);
PCMessage("Inp mode", 1, &p);
PCMessage("6 ch", 1, &p, OffOnText);
PCMessage("Inp mode", 1, &p, InputModeText);
PCMessage("Mute", 1, &p, OffOnText);
PCMessage("Zone 2", 1, &p, InputText);
PCMessage("Mute 2", 1, &p, OffOnText);
PCMessage("Volume", 2, &p, VolumeDB);
PCMessage("Volume 2", 2, &p, VolumeDB);
PCMessage("pgm", 2, &p);
PCMessage("effect", 1, &p, OffOnText);
PCMessage("6.1/es status", 1, &p);
PCMessage("OSD", 1, &p);
PCMessage("sleep", 1, &p);
PCMessage("Tuner Pg", 1, &p);
PCMessage("Tuner #", 1, &p);
PCMessage("Prog", 2, &p, ProgramName);
PCMessage("Effect", 1, &p, OffOnText);
PCMessage("6.1/es status", 1, &p, OffMatrixDiscreteAutoText);
PCMessage("OSD", 1, &p, OSDFullShortOffText);
PCMessage("Sleep", 1, &p, SleepTimerText);
PCMessage("Tuner Pg", 1, &p, PresetLabelText);
PCMessage("Tuner #", 1, &p, PresetNumberText);
PCMessage("Night", 1, &p, OffOnText);
PCMessage("?????", 1, &p);
PCMessage("Spkr A", 1, &p, OffOnText);
PCMessage("Spkr B", 1, &p, OffOnText);
PCMessage("Playback", 1, &p);
PCMessage("Fs", 1, &p);
PCMessage("Ex/Es", 1, &p);
PCMessage("Thr Bypass", 1, &p);
PCMessage("Red DTS", 1, &p);
PCMessage("Headph", 1, &p, OffOnText);
PCMessage("Tuner Band", 1, &p);
PCMessage("Tuner Tuned", 1, &p);
PCMessage("DC1 Control Out", 1, &p);
PCMessage("Playback", 1, &p, PlaybackToText);
PCMessage("Fs", 1, &p, FsToText);
PCMessage("Ex/Es", 1, &p, OffMatrixDiscreteText);
PCMessage("Thr Bypass", 1, &p, OffOnText);
PCMessage("Red DTS", 1, &p, ReleaseWaitText);
PCMessage("Headphone", 1, &p, OffOnText);
PCMessage("Tuner Band", 1, &p, FMAMText);
PCMessage("Tuner Tuned", 1, &p, NotTunedTunedText);
PCMessage("DC1 Control Out", 1, &p, OffOnText);
PCMessage("?????", 2, &p);
PCMessage("DC1 Trig Ctrl", 1, &p);
PCMessage("DTS 96/24", 1, &p, OffOnText);
PCMessage("DC2 Trig Ctrl", 1, &p);
PCMessage("DC2 Trig", 1, &p);
PCMessage("Spkr B Set", 1, &p);
PCMessage("DC2 Trig Ctrl", 1, &p, WhichZoneText);
PCMessage("DC2 Trig Out", 1, &p, OffOnText);
PCMessage("Spkr B Set", 1, &p, Zone1Zone2Text);
PCMessage("Zone 2 SP out", 1, &p, OffOnText);
PCMessage("Main R", 2, &p);
PCMessage("Main L", 2, &p);
PCMessage("Center", 2, &p);
PCMessage("Rear R", 2, &p);
PCMessage("Rear L", 2, &p);
PCMessage("Sur Bk R", 2, &p);
PCMessage("Sur Bk L", 2, &p);
PCMessage("Front R", 2, &p);
PCMessage("Front L", 2, &p);
PCMessage("Sub", 2, &p);
PCMessage("Main R", 2, &p, PM10dbText);
PCMessage("Main L", 2, &p, PM10dbText);
PCMessage("Center", 2, &p, PM10dbText);
PCMessage("Rear R", 2, &p, PM10dbText);
PCMessage("Rear L", 2, &p, PM10dbText);
PCMessage("Sur Bk R", 2, &p, PM10dbText);
PCMessage("Sur Bk L", 2, &p, PM10dbText);
PCMessage("Front R", 2, &p, PM10dbText);
PCMessage("Front L", 2, &p, PM10dbText);
PCMessage("Subwfr 1", 2, &p, PM10dbText);
PCMessage("?????", 6, &p);
PCMessage("LFE SP", 2, &p);
PCMessage("LFE HP", 2, &p);
PCMessage("Audio Delay", 2, &p);
PCMessage("LFE SP", 2, &p, M20P0dbText);
PCMessage("LFE HP", 2, &p, M20P0dbText);
PCMessage("Audio Delay", 2, &p, ZeroTo160msText);
PCMessage("?????", 4, &p);
PCMessage("Inp Mode Set", 1, &p);
PCMessage("Dimmer", 1, &p);
PCMessage("Inp Mode Set", 1, &p, AutoLastText);
PCMessage("Dimmer", 1, &p, M4To0Text);
PCMessage("OSD Msg", 1, &p);
PCMessage("OSD Shift", 2, &p);
PCMessage("Gray Back", 1, &p);
PCMessage("OSD Shift", 2, &p, M5toP5Text);
PCMessage("Gray Back", 1, &p, OffAutoText);
PCMessage("Video Conv", 1, &p, OffOnText);
PCMessage("D Range SP", 1, &p);
PCMessage("D Range HP", 1, &p);
PCMessage("Zone 2 Vol out", 1, &p);
PCMessage("?????", 1, &p);
PCMessage("D Range SP", 1, &p, MaxStdMinText);
PCMessage("D Range HP", 1, &p, MaxStdMinText);
PCMessage("Zone 2 Vol out", 1, &p, VarFixText);
PCMessage("?????", 1, &p); // "Zone 2 Mode: %s", Mode1Mode2Text ???
PCMessage("Memory Guard", 1, &p, OffOnText);
PCMessage("SP set center", 1, &p);
PCMessage("SP set main", 1, &p);
PCMessage("SP set rear L/R", 1, &p);
PCMessage("SP set rear ct", 1, &p);
PCMessage("SP set front", 1, &p);
PCMessage("SP set LFE/Bass", 1, &p);
PCMessage("SP set LFE/Bass", 1, &p, SwfrMainBothText);
PCMessage("6 ch center", 1, &p);
PCMessage("6 ch sub", 1, &p);
PCMessage("Main level", 1, &p);
PCMessage("Test Mode", 1, &p);
PCMessage("Test Mode", 1, &p, OffDolbyDspText);
PCMessage("?????", 1, &p);
PCMessage("Lvl 6 ch main L", 2, &p);
PCMessage("Lvl 6 ch main R", 2, &p);
PCMessage("Lvl 6 ch center", 2, &p);
PCMessage("Lvl 6 ch sl", 2, &p);
PCMessage("Lvl 6 ch sr", 2, &p);
PCMessage("Lvl 6 ch sbl", 2, &p);
PCMessage("Lvl 6 ch sbr", 2, &p);
PCMessage("Lvl 6 ch front l", 2, &p);
PCMessage("Lvl 6 ch front r", 2, &p);
PCMessage("Lvl 6 ch swfr", 2, &p);
PCMessage("Zone 3 Inp", 1, &p);
PCMessage("Zone 3 Mute", 1, &p);
PCMessage("Zone 3 Vol", 2, &p);
PCMessage("Lvl 6 Ch main L", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch main R", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch center", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch sl", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch sr", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch sbl", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch sbr", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch F L", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch F R", 2, &p, M10P10dbText);
PCMessage("Lvl 6 Ch swfr", 2, &p, M20P0dbText );
PCMessage("Zone 3 Inp", 1, &p, PlaybackToText);
PCMessage("Zone 3 Mute", 1, &p, OffOnText);
PCMessage("Zone 3 Vol", 2, &p, VolumeDB);
PCMessage("?????", 1, &p);
PCMessage("MultiCh Select", 1, &p);
PCMessage("MultiCh Surround", 1, &p);
PCMessage("SP Set SW1", 1, &p);
PCMessage("SP Set Crossover", 1, &p);
PCMessage("MultiCh Select", 1, &p, SixEightText);
PCMessage("MultiCh Surround", 1, &p, SurrMainText);
PCMessage("SP Set SW1", 1, &p, LrFrNoneText);
PCMessage("SP Set Crossover", 1, &p, CrossOverText);
PCMessage("Component OSD", 1, &p, OffOnText);
PCMessage("PB/SB Select", 1, &p);
PCMessage("PB/SB Select", 1, &p, PRSBText);
}
}
}

View File

@@ -39,38 +39,102 @@ public:
///
bool IsOnline();
/// @brief Power on and off commands
///
typedef enum {
avrPowerOff,
avrPowerOn,
} AVRPower_T;
eOn = 0,
eOff,
eStandby
} AVROnOff_E;
typedef enum {
eVolumeUp,
eVolumeDown,
eMuteOn,
eMuteOff
} AVRVolume_E;
typedef enum {
eOSDOff,
eOSDShort,
eOSDFull
} AVROSDScreen_E;
typedef enum {
eSleepOff,
eSleep120,
eSleep90,
eSleep60,
eSleep30
} AVRSleep_E;
typedef enum {
eOnMatrix,
eESESOff,
eAuto,
eDiscrete
} AVREX_ES_E;
typedef enum {
eEffectOn,
eStereo
} AVREffect_E;
typedef enum {
eFM,
eAM
} AVRTunerBand_E;
typedef enum {
e1,
e2,
e3,
e4,
e5,
e6, e7, e8
} AVRPresetNum_E;
typedef enum {
eA,
eB,
eC,
eD,
eE,
eF
} AVR_PresetPage_E;
typedef enum {
ePhono,
eCD,
eTuner,
eCDR,
eMD_Tape,
eDVD,
eDTV,
eCable,
eSat,
eVCR1,
eVCR2_DVR,
eVCR3,
eV_Aux,
} AVRInput_E;
typedef enum {
cmdZone1,
cmdZone2,
cmdZone3,
cmdSpeakerSetB,
cmdNightMode,
cmdTrigControl1,
cmdTrigControl2
} AVRSubsystem_E;
/// @brief Send the power command
/// @param cmd
/// @return true
///
bool Power(AVRPower_T cmd);
bool Power(AVROnOff_E cmd);
// MasterVolumeButton
// Issues volume up and down commands to the AVR.
//
typedef enum {
avrVolumeUp,
avrVolumeDown,
} AVRVolumeButton_T;
bool MasterVolumeButton(AVRVolumeButton_T cmd);
// Mute, UnMute
typedef enum {
avrMute,
avrUnMute,
} AVRMute_T;
/// @brief Mute and Unmute
/// @param mute is avrMute or avrUnMute
/// @return true
bool Mute(AVRMute_T mute);
bool VolumeButton(AVRVolume_E cmd);
typedef enum {
mtModelInfo,
@@ -92,6 +156,14 @@ public:
///
void ReportAllStatus();
/// @brief This is public to start, maybe forever because it offers the generic capability
/// @param p the message to send
/// @param len of the message
/// @return true
bool ProcessSerialQueue(const void *p = NULL, uint16_t len = NULL);
private:
uint32_t sentAtTime_ms;
@@ -112,8 +184,9 @@ private:
}
// Each DT is the hex-character from the stream
//
//
//
// This could be simplified to uint8_t DT[138]
//
typedef struct {
uint8_t DT0; // * Baud Rate '@'
uint8_t DT1; // * Receive Buffer 'E'
@@ -292,7 +365,9 @@ private:
SerialQueue_T serialQueue[SERIALQUEUESIZE];
int serialQueueCount = 0;
bool ProcessSerialQueue(const void *p = NULL, uint16_t len = NULL);
uint32_t firstTick_ms; // basically the time when the program started
uint32_t lastTick_ms; // @TODO instead of this, offer a way for the class to get the current time
bool IsSanityCheckOK();
void MessageHandlerSanityCheck();
@@ -305,6 +380,7 @@ private:
void PCMessage(const char *msg, int len, uint8_t **src, const char *(fncHelper)(uint8_t val) = NULL);
bool ProcessReportResponse(const uint8_t *szBuffer, uint32_t len);
void MessageReport(const char *prefix, const void *buf, size_t len = 0);
bool CheckTheChecksum(const uint8_t *szBuffer, uint32_t num);
uint16_t Hex2Dec(const uint8_t *p, int dig);