Lots of updates and refactoring.
This commit is contained in:
@@ -280,6 +280,17 @@ bool ProcessSerialReceive(void);
|
||||
void EnumerateComPorts();
|
||||
unsigned long Hex2Dec(uint8_t *p, int dig);
|
||||
|
||||
// Helpers to convert status codes to text
|
||||
const char *BusyToText(uint8_t val);
|
||||
const char *WarnToText(uint8_t val);
|
||||
const char *PlaybackToText(uint8_t val);
|
||||
const char *FsToText(uint8_t val);
|
||||
const char *ZonePower(uint8_t val);
|
||||
const char *VolumeDB(uint8_t val);
|
||||
const char *ProgramName(uint8_t val);
|
||||
|
||||
void ShowAllStatusInfo();
|
||||
|
||||
bool UserWantsToExitCanSniff = false;
|
||||
|
||||
DWORD progStartTime;
|
||||
@@ -291,8 +302,7 @@ CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
WORD wOldColorAttrs; // Save the current console colors
|
||||
|
||||
short consoleWidth = 105;
|
||||
short consoleHeight = 70;
|
||||
short consoleScrollHeight = 14;
|
||||
short consoleHeight = 80;
|
||||
// 0 99
|
||||
// +---------------------------------------------------------------+
|
||||
// | Program banner information | 0
|
||||
@@ -302,48 +312,197 @@ short consoleScrollHeight = 14;
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// + Down near the bottom is the scroll region + 69
|
||||
// + Down near the bottom is the scroll region + 59
|
||||
// | |
|
||||
// | |
|
||||
// | | 79
|
||||
// +---------------------------------------------------------------+
|
||||
const int scrollTop = 59;
|
||||
const int scrollBot = 69;
|
||||
// +---------------------------------------------------------------+ 80
|
||||
short scrollTop = 59;
|
||||
short scrollBot = 79;
|
||||
short consoleScrollHeight = 20;
|
||||
|
||||
|
||||
void Console_Init();
|
||||
void Console_Cls();
|
||||
bool Console_SetCursorVisibility(bool visible);
|
||||
void Console_SetCursor(short x, short y);
|
||||
void Console_Write(const char *text);
|
||||
void Console_WriteAt(short x, short y, const char *text);
|
||||
void Console_ScrollBottomRegion(short topLine, short bottomLine);
|
||||
bool Console_AdvanceToNextLineIfNotRoomFor(short x, int scroll = -1);
|
||||
|
||||
typedef struct {
|
||||
const char *pMsg;
|
||||
DWORD MsgLen;
|
||||
} Message_T;
|
||||
|
||||
typedef struct {
|
||||
const char Char;
|
||||
const char *pDescription;
|
||||
const char *pCommand;
|
||||
DWORD cmdLen;
|
||||
Message_T TxMsg;
|
||||
} UserCmd_T;
|
||||
|
||||
const UserCmd_T UserCommands[] = {
|
||||
{ 'R', "Ready", "\x11" "000" "\x03", 5 },
|
||||
{ 'P', "Power On", "\x02" "07A1D" "\x03", 7 },
|
||||
{ 'p', "Power Off", "\x02" "07A1E" "\x03", 7 },
|
||||
{ '1', "Zone 1 On", "\x02" "07E7E" "\x03", 7 },
|
||||
{ '!', "Zone 1 Off", "\x02" "07E7F" "\x03", 7 },
|
||||
{ '2', "Zone 2 On", "\x02" "07EBA" "\x03", 7 },
|
||||
{ '@', "Zone 2 Off", "\x02" "07EBB" "\x03", 7 },
|
||||
{ 'V', "Vol 1 Up", "\x02" "07A1A" "\x03", 7 },
|
||||
{ 'v', "Vol 1 Down", "\x02" "07A1B" "\x03", 7 },
|
||||
{ 'M', "Vol 1 Mute", "\x02" "07EA2" "\x03", 7 },
|
||||
{ 'm', "Vol 1 UnMute", "\x02" "07EA3" "\x03", 7 },
|
||||
{ '/', "Show All", "", 0 },
|
||||
{ '?', "Help on runtime commands", "", 0 },
|
||||
{ 'S', "Set RTS", "", 0 },
|
||||
{ 's', "Clear RTS", "", 0 },
|
||||
{ '\x1B', "quit the program", "", 0 },
|
||||
{ 'R', "Ready", {"\x11" "000" "\x03", 5 } },
|
||||
{ '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} },
|
||||
{ '@', "Zone 2 Standby", {"\x02" "07EBB" "\x03", 7} },
|
||||
{ '3', "Zone 3 On", {"\x02" "07AED" "\x03", 7} },
|
||||
{ '#', "Zone 3 Standby", {"\x02" "07AEE" "\x03", 7} },
|
||||
{ 'V', "Vol 1 Up", {"\x02" "07A1A" "\x03", 7} },
|
||||
{ 'v', "Vol 1 Down", {"\x02" "07A1B" "\x03", 7} },
|
||||
{ 'M', "Vol 1 Mute", {"\x02" "07EA2" "\x03", 7} },
|
||||
{ 'm', "Vol 1 UnMute", {"\x02" "07EA3" "\x03", 7} },
|
||||
{ '/', "Show All" },
|
||||
{ '?', "Help on runtime commands" },
|
||||
{ 'S', "Set RTS" },
|
||||
{ 's', "Clear RTS" },
|
||||
{ '\x1B', "Quit App" },
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
//uint8_t type; // 0 to 4, and 0xFF for don't care
|
||||
//uint8_t guard; // 0 to 2, and 0xFF for don't care
|
||||
uint8_t rCmd;
|
||||
uint8_t configOffset; // offset into the Config DT0 - DT155 array, or 0xFF for no action
|
||||
uint8_t numToTransfer; // number of bytes to transfer into the Config array, or 0 for no action
|
||||
bool showAll; // true to call ShowAllStatusInfo after processing
|
||||
void (*fncHelper)(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
const char *TextFormatter; // used primarily for development printf(TextFormatter, value)
|
||||
const char *(*fncValueToText)(uint8_t rDat);
|
||||
} MessageHandler_T;
|
||||
|
||||
void RxSystemReport( uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
void RxWarningReport(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
void RxPlaybackReport(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
void RxFsReport(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
|
||||
void RxPowerStatus( uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
|
||||
void RxMasterVolStatus(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
void RxProgramStatus(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen);
|
||||
|
||||
|
||||
// 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)
|
||||
// fncHelper: optional function to call upon receipt
|
||||
//
|
||||
const MessageHandler_T MessageHandlers[] = {
|
||||
//rCmd cfgOfs num ShowAll function
|
||||
{0x00, 7, 1, 1, RxSystemReport },
|
||||
{0x01, 0, 0, 0, RxWarningReport },
|
||||
{0x10, 31, 1, 1, RxPlaybackReport },
|
||||
{0x11, 32, 1, 1, RxFsReport },
|
||||
{0x12, 33, 1, 1, NULL }, // EX/EX
|
||||
{0x13, 34, 1, 1, NULL }, // Thr / Bypass
|
||||
{0x14, 35, 1, 1, NULL }, // RED dts
|
||||
{0x15, 38, 1, 1, NULL }, // Tuner tuned
|
||||
{0x16, 43, 1, 1, NULL }, // Dts 96/24
|
||||
{0x20, 8, 0, 1, RxPowerStatus, "Zone Power: %s", ZonePower},
|
||||
{0x21, 9, 1, 1, NULL }, // Input Source
|
||||
{0x22, 11, 1, 1, NULL }, // Input Mode
|
||||
{0x23, 12, 1, 1, NULL }, // Mute Status
|
||||
{0x24, 13, 1, 1, NULL }, // Zone 2 Input Source
|
||||
{0x25, 14, 1, 1, NULL }, // Zone 2 Mute
|
||||
{0x26, 15, 2, 1, RxMasterVolStatus },
|
||||
{0x27, 17, 2, 1, NULL }, // Zone 2 Vol
|
||||
{0x28, 19, 2, 1, RxProgramStatus }, // Program
|
||||
{0x29, 25, 1, 1, NULL }, // Tuner Page
|
||||
{0x2A, 26, 1, 1, NULL }, // Tuner Preset Number
|
||||
{0x2B, 23, 1, 1, NULL }, // OSD
|
||||
{0x2C, 24, 1, 1, NULL }, // Sleep Timer
|
||||
{0x2D, 22, 1, 1, NULL }, // EX/ES(Key)
|
||||
{0x2E, 29, 1, 1, NULL }, // Speaker Relay A
|
||||
{0x2F, 30, 1, 1, NULL }, // Speaker Relay B
|
||||
|
||||
{0x36, 39, 1, 1, NULL }, // DC1 Trigger
|
||||
|
||||
{0x3C, 45, 1, 1, NULL }, // DC2 Trigger
|
||||
|
||||
{0x82, 27, 1, 1, NULL }, // Night Mode
|
||||
|
||||
{0xA1, 0, 0, 0, NULL }, // Zone 3 Mute
|
||||
|
||||
};
|
||||
|
||||
// RCMD 00
|
||||
//
|
||||
void RxSystemReport(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen) {
|
||||
(void)rCmd, pMessage, msgLen;
|
||||
//SetData(&avrStatus.config.DT8, pMessage + 5, 2);
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "System Report: %s\n", BusyToText(rDat));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
//ShowAllStatusInfo();
|
||||
}
|
||||
|
||||
// RCMD 01
|
||||
//
|
||||
void RxWarningReport(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen) {
|
||||
(void)rCmd, pMessage, msgLen;
|
||||
//SetData(&avrStatus.config.DT8, pMessage + 5, 2);
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "Warning Report: %s\n", WarnToText(rDat));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
//ShowAllStatusInfo();
|
||||
}
|
||||
|
||||
// RCMD 10
|
||||
void RxPlaybackReport(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen) {
|
||||
(void)rCmd, pMessage, msgLen;
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "Playback Report: %s\n", PlaybackToText(rDat));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
//ShowAllStatusInfo();
|
||||
}
|
||||
|
||||
// RCMD 11
|
||||
void RxFsReport(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen) {
|
||||
(void)rCmd, pMessage, msgLen;
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "Playback Report: %s\n", FsToText(rDat));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
//ShowAllStatusInfo();
|
||||
}
|
||||
|
||||
// RCMD 20
|
||||
void RxPowerStatus(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen) {
|
||||
(void)rCmd, pMessage, msgLen;
|
||||
//SetData(&avrStatus.config.DT8, pMessage + 5, 2);
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "Zone Power: %s\n", ZonePower(rDat));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
//ShowAllStatusInfo();
|
||||
}
|
||||
|
||||
// RCMD 26
|
||||
void RxMasterVolStatus(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen) {
|
||||
(void)rCmd, pMessage, msgLen;
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "Vol: %s\n", VolumeDB(rDat));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
//ShowAllStatusInfo();
|
||||
}
|
||||
|
||||
// RCMD 28
|
||||
void RxProgramStatus(uint8_t rCmd, uint8_t rDat, uint8_t *pMessage, uint32_t msgLen) {
|
||||
(void)rCmd, pMessage, msgLen;
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "Vol: %s\n", ProgramName(rDat));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
//ShowAllStatusInfo();
|
||||
}
|
||||
|
||||
int CS_KeyHit() {
|
||||
int h = _kbhit();
|
||||
@@ -452,8 +611,6 @@ bool SerialSend(const uint8_t *p, DWORD len) {
|
||||
bool ProcessSerialQueue(const uint8_t *p, DWORD len) {
|
||||
bool retVal = false; // assume fail
|
||||
static bool freshData = false;
|
||||
//DWORD now = timeGetTime();
|
||||
//static DWORD lastSendTime = timeGetTime();
|
||||
|
||||
if (p && len) {
|
||||
if (serialQueueCount < SERIALQUEUESIZE) {
|
||||
@@ -524,13 +681,13 @@ void EmitRuntimeHelp() {
|
||||
// The last param will allow resetting the column counter
|
||||
// and pre and post-pending \n
|
||||
//
|
||||
static void PCMessage(const char *msg, int len, uint8_t **src, const char * (fncHelper)(uint32_t val) = NULL) {
|
||||
static void PCMessage(const char *msg, int len, uint8_t **src, const char * (fncHelper)(uint8_t val) = NULL) {
|
||||
char buf[MAXTEXTLEN];
|
||||
const char *p = buf;
|
||||
|
||||
if (fncHelper) {
|
||||
// Get the binary value if we need it
|
||||
uint32_t val = Hex2Dec(*src, len);
|
||||
uint8_t val = (uint8_t)Hex2Dec(*src, len);
|
||||
p = (*fncHelper)(val);
|
||||
*src += len;
|
||||
} else {
|
||||
@@ -550,7 +707,7 @@ static void PCMessage(const char *msg, int len, uint8_t **src, const char * (fnc
|
||||
}
|
||||
|
||||
|
||||
const char * BusyToText(uint32_t val) {
|
||||
const char * BusyToText(uint8_t val) {
|
||||
static char buf[16];
|
||||
if (val == 0) {
|
||||
strcpy_s(buf, sizeof(buf), "OK");
|
||||
@@ -562,19 +719,99 @@ const char * BusyToText(uint32_t val) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char * OnOffText(uint32_t val) {
|
||||
const char * WarnToText(uint8_t val) {
|
||||
static char buf[16];
|
||||
if (val == 0) {
|
||||
strcpy_s(buf, sizeof(buf), "OFF");
|
||||
strcpy_s(buf, sizeof(buf), "OK");
|
||||
} else if (val == 1) {
|
||||
strcpy_s(buf, sizeof(buf), "ON");
|
||||
strcpy_s(buf, sizeof(buf), "BUSY");
|
||||
} else {
|
||||
sprintf_s(buf, sizeof(buf), "0x%02X ?", (unsigned char)val);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char * InputText(uint32_t val) {
|
||||
const char *PlaybackToText(uint8_t val) {
|
||||
static char buf[60];
|
||||
const char *playbackList[] = {
|
||||
/* 0 */ "6Ch Input",
|
||||
/* 1 */ "Analog",
|
||||
/* 2 */ "PCM",
|
||||
/* 3 */ "DD (except 2/0)",
|
||||
/* 4 */ "DD (2/0)",
|
||||
/* 5 */ "DD Karaoke",
|
||||
/* 6 */ "DD EX",
|
||||
/* 7 */ "DTS",
|
||||
/* 8 */ "DTS ES",
|
||||
/* 9 */ "Other Digital",
|
||||
/* A */ "DTS Analog Mute",
|
||||
/* B */ "DTS Discrete",
|
||||
/* C */ "Other than AAC 2/0",
|
||||
/* D */ "AAC 2/0",
|
||||
};
|
||||
if (val < sizeof(playbackList)/sizeof(playbackList[0]))
|
||||
strcpy_s(buf, sizeof(buf), playbackList[val]);
|
||||
else
|
||||
sprintf_s(buf, sizeof(buf), "0x%04X ?", val);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *FsToText(uint8_t val) {
|
||||
static char buf[60];
|
||||
const char *fsList[] = {
|
||||
/* 0 */ "Analog",
|
||||
/* 1 */ "32 kHz",
|
||||
/* 2 */ "44.1 kHz",
|
||||
/* 3 */ "48 kHz",
|
||||
/* 4 */ "64 kHz",
|
||||
/* 5 */ "88.2 kHz",
|
||||
/* 6 */ "96 kHz",
|
||||
/* 7 */ "unknown",
|
||||
/* 8 */ "128.0 kHz unk",
|
||||
/* 9 */ "176.4 kHz unk",
|
||||
/* A */ "192.0 kHz unk",
|
||||
};
|
||||
if (val < sizeof(fsList) / sizeof(fsList[0]))
|
||||
strcpy_s(buf, sizeof(buf), fsList[val]);
|
||||
else
|
||||
sprintf_s(buf, sizeof(buf), "0x%04X ?", val);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char * OnOffText(uint8_t val) {
|
||||
static char buf[16];
|
||||
if (val == 0) {
|
||||
strcpy_s(buf, sizeof(buf), "Off");
|
||||
} else if (val == 1) {
|
||||
strcpy_s(buf, sizeof(buf), "On");
|
||||
} else {
|
||||
sprintf_s(buf, sizeof(buf), "0x%04X ?", val);
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *ZonePower(uint8_t val) {
|
||||
static char buf[60];
|
||||
const char *powerList[8] = {
|
||||
/* 0 */ "All Off (Main, Zone 2, Zone 3)",
|
||||
/* 1 */ "All On (Main, Zone 2, Zone 3)",
|
||||
/* 2 */ "Main On | Zone 2 Off | Zone 3 Off",
|
||||
/* 3 */ "Main Off | Zone 2 On | Zone 3 On ",
|
||||
/* 4 */ "Main On | Zone 2 On | Zone 3 Off",
|
||||
/* 5 */ "Main On | Zone 2 Off | Zone 3 Off",
|
||||
/* 6 */ "Main Off | Zone 2 On | Zone 3 On ",
|
||||
/* 7 */ "Main Off | Zone 2 Off | Zone 3 On ",
|
||||
};
|
||||
if (val < 8)
|
||||
strcpy_s(buf, sizeof(buf), powerList[val]);
|
||||
else
|
||||
sprintf_s(buf, sizeof(buf), "0x%04X ?", val);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char * InputText(uint8_t val) {
|
||||
const char *inputList[13] = {
|
||||
"0:Phono", "1:CD", "2:Tuner", "3:CD-R", "4:MD-Tape", "5:DVD", "6:D-TV",
|
||||
"7:Cable", "8:unk", "9:VCR1", "A:VCR2", "B:unk", "C:V-Aux"
|
||||
@@ -587,33 +824,39 @@ const char * InputText(uint32_t val) {
|
||||
}
|
||||
|
||||
const char *ProgramName(uint8_t val) {
|
||||
static char returnBuf[MAXTEXTLEN] = "";
|
||||
|
||||
returnBuf[0] = '\0';
|
||||
if (val & 0x80) {
|
||||
strcpy_s(returnBuf, MAXTEXTLEN, "STRAIGHT ");
|
||||
}
|
||||
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",
|
||||
"Live Concert (HALL2)",
|
||||
"unk",
|
||||
"Tokyo",
|
||||
"Freiburg",
|
||||
"Freiburg (CHURCH)",
|
||||
"Royaumont",
|
||||
"unk",
|
||||
"Village Gate",
|
||||
"Village Vanguard",
|
||||
"The Bottom Line",
|
||||
"The Bottom Line (JAZZ)",
|
||||
"unk",
|
||||
"The Roxy Theater",
|
||||
"The Roxy Theater (ROCK)",
|
||||
"Warehouse Loft",
|
||||
"Arena",
|
||||
"unk",
|
||||
"Disco",
|
||||
"Party",
|
||||
"Game",
|
||||
"6 / 8CH Stereo",
|
||||
"Pop / Rock",
|
||||
"7 Ch Stereo",
|
||||
"Pop/Rock (Music Video)",
|
||||
"DJ",
|
||||
"unk",
|
||||
"unk",
|
||||
@@ -647,10 +890,11 @@ const char *ProgramName(uint8_t val) {
|
||||
"THX B Music",
|
||||
};
|
||||
if (val < sizeof(nameList)) {
|
||||
return nameList[val];
|
||||
strcat_s(returnBuf, MAXTEXTLEN, nameList[val]);
|
||||
} else {
|
||||
return "huh?";
|
||||
strcpy_s(returnBuf, MAXTEXTLEN, "huh?");
|
||||
}
|
||||
return returnBuf;
|
||||
}
|
||||
|
||||
|
||||
@@ -683,8 +927,9 @@ const char *VolumeDB(uint32_t val) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
void ShowAll(void) {
|
||||
void ShowAllStatusInfo(void) {
|
||||
if (avrStatus.headerValid) {
|
||||
bool priorState = Console_SetCursorVisibility(false);
|
||||
Console_SetCursor(0, 2);
|
||||
char buf[MAXTEXTLEN];
|
||||
sprintf_s(buf, MAXTEXTLEN, "Model ID: %c%c%c%c%c, ver: %c\n", avrStatus.header.type[0], avrStatus.header.type[1],
|
||||
@@ -793,6 +1038,7 @@ void ShowAll(void) {
|
||||
PCMessage("PB/SB Select", 1, &p);
|
||||
}
|
||||
printf("\n");
|
||||
Console_SetCursorVisibility(priorState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -811,7 +1057,7 @@ void ProcessKeyboard(void) {
|
||||
EmitRuntimeHelp();
|
||||
break;
|
||||
case '/':
|
||||
ShowAll();
|
||||
ShowAllStatusInfo();
|
||||
break;
|
||||
case '\x1B':
|
||||
UserWantsToExitCanSniff = true;
|
||||
@@ -831,7 +1077,7 @@ 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].pCommand, UserCommands[i].cmdLen);
|
||||
ProcessSerialQueue((const uint8_t *)UserCommands[i].TxMsg.pMsg, UserCommands[i].TxMsg.MsgLen);
|
||||
cmdFound = true;
|
||||
break;
|
||||
}
|
||||
@@ -913,6 +1159,8 @@ int __cdecl main(int argc, char *argv[]) {
|
||||
if (AttachToSerialPort()) {
|
||||
printf("AVR - a command shell utility for a Yamaha RX-2400 AVR by D.Smart\n");
|
||||
printf("Attached to Serial Port on COM%i at %i baud\n", avrOnPort, avrBaud);
|
||||
Console_WriteAt(0, scrollTop - 1, "----------------------------------------");
|
||||
|
||||
do {
|
||||
ProcessKeyboard();
|
||||
/* bool anyRcvdMsg = */ ProcessSerialReceive();
|
||||
@@ -926,11 +1174,10 @@ int __cdecl main(int argc, char *argv[]) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
void SetData(uint8_t *targ, const uint8_t *string) {
|
||||
void SetData(uint8_t *targ, const uint8_t *string, size_t len = 0) {
|
||||
uint8_t *p = (uint8_t *)string;
|
||||
while (*p) {
|
||||
*targ++ = *p++;
|
||||
}
|
||||
if (len == 0) len = strlen((const char *)string);
|
||||
memcpy(targ, p, len);
|
||||
}
|
||||
|
||||
// Dec2Hex
|
||||
@@ -975,29 +1222,123 @@ bool CheckTheChecksum(uint8_t *szBuffer, uint32_t num) {
|
||||
return (sum == cksum);
|
||||
}
|
||||
|
||||
void ProcessResponse(uint8_t type, uint8_t guard, uint16_t cmd, uint16_t data) {
|
||||
(void)type;
|
||||
(void)guard;
|
||||
// ProcessResponse
|
||||
//
|
||||
// @param[in] szBuffer is the received message
|
||||
// @param[in] len is the null terminated string length of the message
|
||||
//
|
||||
// Typical Message:
|
||||
// '\x02' 'type' 'guard' 'rcmd0' 'rcmd1' 'rdat0' 'rdat1' '\x03'
|
||||
// [0] [1] [2] [3] [4] [5] [6] [7]
|
||||
//
|
||||
void ProcessResponse(uint8_t *szBuffer, uint32_t len) {
|
||||
// These don't have a checksum ...
|
||||
// Example: [02] 4026 66[03]
|
||||
// 4 - controlled by encoder
|
||||
// 0 - guard status 0 = no guard
|
||||
// 26 - master vol
|
||||
// 66 - volume setting (-54.6db)
|
||||
uint8_t type = (uint8_t)Hex2Dec(&szBuffer[1], 1);
|
||||
uint8_t guard = (uint8_t)Hex2Dec(&szBuffer[2], 1);
|
||||
uint8_t rcmd = (uint8_t)Hex2Dec(&szBuffer[3], 2);
|
||||
uint8_t rdat = (uint8_t)Hex2Dec(&szBuffer[5], 2);
|
||||
char buf[MAXTEXTLEN];
|
||||
switch (cmd) {
|
||||
case 0x26:
|
||||
sprintf_s(buf, MAXTEXTLEN, "Vol: %s\n", VolumeDB(data));
|
||||
SetData(&avrStatus.config.DT15, Dec2Hex(data, 2));
|
||||
(void)len; // not used
|
||||
|
||||
bool found = false;
|
||||
for (int i = 0; i < sizeof(MessageHandlers) / sizeof(MessageHandlers[0]); i++) {
|
||||
if (MessageHandlers[i].rCmd == rcmd) {
|
||||
found = true;
|
||||
if (MessageHandlers[i].numToTransfer == 1) {
|
||||
memcpy(&avrStatus.config.DT0 + MessageHandlers[i].configOffset, &szBuffer[6], 1);
|
||||
}
|
||||
if (MessageHandlers[i].numToTransfer == 2) {
|
||||
memcpy(&avrStatus.config.DT0 + MessageHandlers[i].configOffset, &szBuffer[5], 2);
|
||||
}
|
||||
if (MessageHandlers[i].fncHelper) {
|
||||
(*MessageHandlers[i].fncHelper)(rcmd, rdat, szBuffer, len);
|
||||
}
|
||||
if (MessageHandlers[i].showAll) {
|
||||
ShowAllStatusInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
Console_SetCursor(0, -1);
|
||||
if (!found) {
|
||||
sprintf_s(buf, MAXTEXTLEN, "type: %X, guard: %X, cmd: %02X, data: %02X", type, guard, rcmd, rdat);
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
ShowAll();
|
||||
}
|
||||
switch (rcmd) {
|
||||
case 0x20: // Power status
|
||||
// SetData(&avrStatus.config.DT8, Dec2Hex(rdat, 1));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Zone Power: %s\n", ZonePower(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
// break;
|
||||
case 0x23: // Mute
|
||||
// SetData(&avrStatus.config.DT12, Dec2Hex(rdat, 1));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Mute: %s\n", OnOffText(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
// break;
|
||||
case 0x25: // Zone 2 Mute
|
||||
// SetData(&avrStatus.config.DT14, Dec2Hex(rdat, 1));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Zone 2 Mute: %s\n", OnOffText(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
// break;
|
||||
case 0x26: // Master Volume
|
||||
// RxMasterVolStatus(rcmd, rdat, szBuffer, len);
|
||||
// SetData(&avrStatus.config.DT15, Dec2Hex(rdat, 2));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Vol: %s\n", VolumeDB(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
// break;
|
||||
case 0x28: // Program
|
||||
// SetData(&avrStatus.config.DT19, Dec2Hex(rdat, 2));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Prog: %s\n", ProgramName(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
break;
|
||||
case 0x28:
|
||||
sprintf_s(buf, MAXTEXTLEN, "Prog: %s\n", ProgramName(data));
|
||||
SetData(&avrStatus.config.DT19, Dec2Hex(data, 2));
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
ShowAll();
|
||||
case 0x82: // Night Mode
|
||||
// SetData(&avrStatus.config.DT27, Dec2Hex(rdat, 1));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Night Mode: %s\n", OnOffText(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
break;
|
||||
default:
|
||||
sprintf_s(buf, MAXTEXTLEN, "type: %X, guard: %X, cmd: %02X, data: %02X", type, guard, cmd, data);
|
||||
Console_Write(buf);
|
||||
Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
case 0x36: // DC1 Trigger
|
||||
// SetData(&avrStatus.config.DT39, Dec2Hex(rdat, 1));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Trigger Out 1: %s\n", OnOffText(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
break;
|
||||
case 0x3C: // DC2 Trigger
|
||||
// SetData(&avrStatus.config.DT45, Dec2Hex(rdat, 1));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Trigger Out 2: %s\n", OnOffText(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
break;
|
||||
case 0xA1: // Zone 3 Mute
|
||||
// //SetData(&avrStatus.config.DT14, Dec2Hex(rdat, 1));
|
||||
// sprintf_s(buf, MAXTEXTLEN, "Zone 3 Mute: %s\n", OnOffText(rdat));
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
// ShowAllStatusInfo();
|
||||
break;
|
||||
|
||||
default: // Everything not yet handled
|
||||
// sprintf_s(buf, MAXTEXTLEN, "type: %X, guard: %X, cmd: %02X, data: %02X", type, guard, rcmd, rdat);
|
||||
// Console_Write(buf);
|
||||
// Console_ScrollBottomRegion(scrollTop, scrollBot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1013,24 +1354,7 @@ void ProcessResponse(uint8_t type, uint8_t guard, uint16_t cmd, uint16_t data) {
|
||||
void AnalyzeResponse(uint8_t *szBuffer, uint32_t num) {
|
||||
switch (szBuffer[0]) {
|
||||
case 0x02: // STX
|
||||
{
|
||||
// Example: [02] 4026 66[03]
|
||||
// 4 - controlled by encoder
|
||||
// 0 - guard status 0 = no guard
|
||||
// 26 - master vol
|
||||
// 66 - volume setting (-54.6db)
|
||||
uint8_t type, guard;
|
||||
uint16_t rcmd, rdat;
|
||||
|
||||
type = (uint8_t)Hex2Dec(&szBuffer[1], 1);
|
||||
guard = (uint8_t)Hex2Dec(&szBuffer[2], 1);
|
||||
rcmd = (uint16_t)Hex2Dec(&szBuffer[3], 2);
|
||||
rdat = (uint16_t)Hex2Dec(&szBuffer[5], 2);
|
||||
ProcessResponse(type, guard, rcmd, rdat);
|
||||
//ShowType(typ);
|
||||
//ShowGuard(grd);
|
||||
//DecodeStatus(rcmd, rdat);
|
||||
}
|
||||
ProcessResponse(szBuffer, num);
|
||||
break;
|
||||
case 0x11: // DC1
|
||||
break;
|
||||
@@ -1052,7 +1376,7 @@ void AnalyzeResponse(uint8_t *szBuffer, uint32_t num) {
|
||||
} else {
|
||||
printf("***** Received message of unexpected length [%u]\n", num);
|
||||
}
|
||||
ShowAll();
|
||||
ShowAllStatusInfo();
|
||||
} else {
|
||||
printf("Checksum failure on Status Header\n");
|
||||
}
|
||||
@@ -1204,7 +1528,6 @@ void Console_Init() {
|
||||
fprintf(stderr, "Error: Unable to set console window size. Code: %lu\n", GetLastError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// end
|
||||
|
||||
wOldColorAttrs = csbi.wAttributes;
|
||||
@@ -1258,7 +1581,7 @@ void Console_Write(const char *text) {
|
||||
WriteConsole(hStdout, text, (DWORD)strlen(text), &written, nullptr);
|
||||
}
|
||||
|
||||
void Console_WriteAt(short x, short y, char *text) {
|
||||
void Console_WriteAt(short x, short y, const char *text) {
|
||||
Console_SetCursor(x, y);
|
||||
DWORD written;
|
||||
WriteConsole(hStdout, text, (DWORD)strlen(text), &written, nullptr);
|
||||
@@ -1296,3 +1619,27 @@ bool Console_AdvanceToNextLineIfNotRoomFor(short x, int scroll) {
|
||||
}
|
||||
return advanced;
|
||||
}
|
||||
|
||||
// Console_SetCursorVisibility
|
||||
//
|
||||
// Set the state of the cursor and provide the prior state so it
|
||||
// can be restored
|
||||
//
|
||||
// @param[in] bool the desired state, true is visible
|
||||
// @returns the prior state, true is visible
|
||||
//
|
||||
bool Console_SetCursorVisibility(bool visible) {
|
||||
CONSOLE_CURSOR_INFO cursorInfo;
|
||||
bool priorState = true;
|
||||
|
||||
if (!GetConsoleCursorInfo(hStdout, &cursorInfo)) {
|
||||
// printf("***** Error: Unable to get cursor info.\n");
|
||||
return priorState;
|
||||
}
|
||||
priorState = cursorInfo.bVisible;
|
||||
cursorInfo.bVisible = visible; // true = show, false = hide
|
||||
if (!SetConsoleCursorInfo(hStdout, &cursorInfo)) {
|
||||
// std::cerr << "Error: Unable to set cursor info.\n";
|
||||
}
|
||||
return priorState;
|
||||
}
|
||||
Reference in New Issue
Block a user