From adad03c7dfc826973e692d39dc870303b7ca31db Mon Sep 17 00:00:00 2001 From: David Date: Sat, 7 Feb 2026 14:38:35 -0600 Subject: [PATCH] Reduce the size of the AVRDriver code. Colorize the changed parameter. Warning reduction across all files. --- AVR Working Controller/AVR.cpp | 303 +++-- AVR Working Controller/AVR.vcxproj | 2 + AVR Working Controller/AVR.vcxproj.filters | 6 + AVR Working Controller/AVR.vcxproj.user | 2 +- AVR Working Controller/AVRCommandDecoder.cpp | 16 +- AVR Working Controller/AVRInterface.cpp | 1104 +++++------------ AVR Working Controller/AVRInterface.h | 528 +------- AVR Working Controller/ConsoleHandler.cpp | 42 +- AVR Working Controller/ConsoleHandler.h | 5 + .../SerialPort/SerialPort.cpp | 4 +- 10 files changed, 583 insertions(+), 1429 deletions(-) diff --git a/AVR Working Controller/AVR.cpp b/AVR Working Controller/AVR.cpp index fce84fd..f7977a5 100644 --- a/AVR Working Controller/AVR.cpp +++ b/AVR Working Controller/AVR.cpp @@ -15,13 +15,12 @@ //#include "AVRCommandDecoder.h" #include "ConsoleHandler.h" -enum -{ +enum { COM_NO_PORT = -1, COM_MIN_PORT = 1, COM_MAX_PORT = 99 }; -CSerialPort avrPort; +CSerialPort rs232Port; int avrOnPort = COM_NO_PORT; // Serial Port 1, 2, ... taking note that some USB adapters can be up toward channel 11, 12, ... unsigned avrBaud = 9600; @@ -30,6 +29,7 @@ const uint32_t retryInterval = 1000; // ms AVRInterface *avr; +#if 0 // Each DT is the hex-character from the stream // // @@ -198,7 +198,7 @@ typedef struct { //AVR_StatusHeader_T avrStatusHeader; //AVR_Configuration_T avrConfigData; AVR_Status_T avrStatus; - +#endif typedef enum { EXIT_OK = 0, @@ -224,7 +224,7 @@ int DetachSerialPort(); // @param[in] len is the count of bytes in the message // @returns true if the serial interface accepted it. // -bool SerialSend(const uint8_t *p, uint16_t len); +bool SerialSend(const uint8_t *message, uint32_t len); // Just big enough to hold an OSD message which is a 1 message command, 4 messages with text #define SERIALQUEUESIZE 5 @@ -237,7 +237,7 @@ static SerialQueue_T serialQueue[SERIALQUEUESIZE]; static int serialQueueCount = 0; -// ProcessSerialQueue +// SendMessageToSerial // // If there are parameters passed, insert a message into the queue. // Process the queue (with zero or more messages) to send @@ -246,7 +246,7 @@ static int serialQueueCount = 0; // @param[in] len is the count of bytes in the message // @returns false if the queue (which is a fixed size) is full. // -//bool ProcessSerialQueue(const uint8_t *p = NULL, uint16_t len = 0); +//bool SendMessageToSerial(const uint8_t *p = NULL, uint16_t len = 0); // ProcessSerialReceive @@ -256,7 +256,7 @@ static int serialQueueCount = 0; // @returns true if a message was processed. // SerialQueue_T ProcessSerialReceive(void); -void HandleMessage(uint8_t *szBuffer, uint32_t num); +//void HandleMessage(uint8_t *szBuffer, uint32_t num); void EnumerateComPorts(); unsigned long Hex2Dec(uint8_t *p, int dig); @@ -268,6 +268,7 @@ void GetAndSendOSDMessage(); bool SendExtendedMessage(char *buf); void EmitRuntimeHelp(); +DWORD AppTime(); bool UserExitRequested = false; bool SystemExitRequested = false; @@ -313,6 +314,7 @@ BOOL WINAPI ControlIntercept(DWORD CtrlType) { void ProcessWindowsMessage(void) { MSG msgx; bool msgReturn; + msgReturn = PeekMessage(&msgx, NULL, WM_QUIT, WM_QUIT, PM_NOREMOVE); if (msgReturn == true && msgx.message == WM_QUIT) { SystemExitRequested = true; @@ -320,12 +322,10 @@ void ProcessWindowsMessage(void) { } -bool SerialSend(const uint8_t *p, uint16_t len) { +bool SerialSend(const uint8_t *message, uint32_t len) { bool retVal = false; - //Console_SetCursor(0, -1); - //EmitBuffer("> ", p, len); - //Console_ScrollBottomRegion(); - if (avrPort.Write((const LPVOID)p, len) == len) { + + if (rs232Port.Write((const LPVOID)message, len) == len) { retVal = true; } else { Console_WriteAt(0, -1, "***** Failed to send. Port not open?"); @@ -337,6 +337,7 @@ bool SerialSend(const uint8_t *p, uint16_t len) { void EmitSpinner() { static int x = 0; const char arrow[] = "|/-\\|/-\\"; + printf("%c\b", arrow[x++]); if (x == 8) x = 0; } @@ -407,10 +408,10 @@ void ProcessKeyboard(void) { int c = CS_GetChar(); switch (c) { case 'P': - avr->AVRCommand(AVRInterface::subMain, AVRInterface::fncPower, AVRInterface::eOn); + avr->AVRCommand(AVRSubsystem_T::subMain, AVRFunction_T::fncPower, AVRArg_T::eOn); break; case 'p': - avr->AVRCommand(AVRInterface::subMain, AVRInterface::fncPower, AVRInterface::eOff); + avr->AVRCommand(AVRSubsystem_T::subMain, AVRFunction_T::fncPower, AVRArg_T::eOff); break; case 'O': GetAndSendOSDMessage(); @@ -426,19 +427,18 @@ void ProcessKeyboard(void) { break; case '/': avr->ReportAllStatus(); - //ShowAllStatusInfo(); break; case '\x1B': UserExitRequested = true; break; case 'S': - avrPort.Set_RTS_State(TRUE); + rs232Port.Set_RTS_State(TRUE); Console_SetCursor(0, -1); printf("RTS set ON"); Console_ScrollBottomRegion(); break; case 's': - avrPort.Set_RTS_State(FALSE); + rs232Port.Set_RTS_State(FALSE); Console_SetCursor(0, -1); printf("RTS set OFF"); Console_ScrollBottomRegion(); @@ -446,8 +446,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); - avr->ProcessSerialQueue((const uint8_t *)UserCommands[i].TxMsg.pMsg, UserCommands[i].TxMsg.MsgLen); + //SendMessageToSerial((const uint8_t *)UserCommands[i].TxMsg.pMsg, UserCommands[i].TxMsg.MsgLen); + avr->SendMessageToSerial(UserCommands[i].TxMsg.pMsg, UserCommands[i].TxMsg.MsgLen); cmdFound = true; break; } @@ -499,19 +499,58 @@ void EmitRuntimeHelp() { Console_AdvanceToNextLineIfNotRoomFor((short)strlen(buf), 1); Console_Write(buf); } - if (avrPort.IsOpen()) { + if (rs232Port.IsOpen()) { Console_ScrollBottomRegion(); Console_SetCursor(0, -1); - printf(" Com Status: RTS: %-3s ", avrPort.Get_RTS_State() ? "ON" : "OFF"); - printf("DTR: %-3s ", avrPort.Get_DTR_State() ? "ON" : "OFF"); - printf("CTS: %-3s ", avrPort.Get_CTS_State() ? "ON" : "OFF"); - printf("DSR: %-3s ", avrPort.Get_DSR_State() ? "ON" : "OFF"); - printf("RI: %-3s", avrPort.Get_RI_State() ? "ON" : "OFF"); + printf(" Com Status: RTS: %-3s ", rs232Port.Get_RTS_State() ? "ON" : "OFF"); + printf("DTR: %-3s ", rs232Port.Get_DTR_State() ? "ON" : "OFF"); + printf("CTS: %-3s ", rs232Port.Get_CTS_State() ? "ON" : "OFF"); + printf("DSR: %-3s ", rs232Port.Get_DSR_State() ? "ON" : "OFF"); + printf("RI: %-3s", rs232Port.Get_RI_State() ? "ON" : "OFF"); Console_ScrollBottomRegion(); Console_SetCursor(0, -1); } } +void EmitBuffer(const char *prefix, const uint8_t *buf, size_t len = 0, bool appendReturn = false) { + int i = 0; + const char *p = (const char *)buf; + char txtBuf[MAXTEXTLEN] = ""; + + if (len == 0) len = strlen((const char *)buf); + sprintf_s(txtBuf, MAXTEXTLEN, "%7.3f: [%3d]%s", (float)(AppTime())/1000.0, (int)strlen(p), prefix); + Console_Write(txtBuf); + while (*p && ((unsigned)(p - (const char *)buf) < len)) { + if (isprint((char)*p)) { + putchar(*p); + i++; + } else if (*p == '\r') { + putchar('\n'); + Console_ScrollBottomRegion(); + } else if (*p == '\n') { + // skip it + } else { + printf("[%02X]", (unsigned char)*p); + } + if ((i & 3) == 0) { + if (Console_AdvanceToNextLineIfNotRoomFor(12, 1)) { + //Console_ScrollBottomRegion(); + printf(" "); // sized to get past the timestamp, length, and prefix + i = 0; + } else { + printf(" "); + } + } + p++; + } + if (appendReturn) { + Console_ScrollBottomRegion(); // putch('\r'); + } else { + //putch('\n'); + //Console_ScrollBottomRegion(); + } +} + void HexUppercase(char *p) { const char *hex = "0123456789ABCDEF"; while (*p) { @@ -561,7 +600,7 @@ void GetAndSendCustomMessage() { } else { Console_ScrollBottomRegion(); sprintf_s(msg, sizeof(msg), "\x02%s\x03", buf); - avr->ProcessSerialQueue(msg, (uint16_t)strlen(msg)); + avr->SendMessageToSerial(msg, (uint16_t)strlen(msg)); } } @@ -579,7 +618,7 @@ bool SendExtendedMessage(char * buf) { } while (*p && (p < msg + 70)); // 70 < 75 to generously reserve space for SUM0,SUM1,ETX,\0 sprintf_s(p, 75 - strlen(msg), "%02X\x03", checksum); Console_ScrollBottomRegion(); - avr->ProcessSerialQueue(msg, (uint16_t)strlen(msg)); + avr->SendMessageToSerial(msg, (uint16_t)strlen(msg)); return true; } return false; @@ -612,32 +651,78 @@ void GetProgName(char *name) { } -void InformationUpdate(AVRInterface::AVRMessageType_T type, const char *msg) { +bool InformationUpdate(AVRMessageType_T type, const void *message, uint32_t attrib) { + const char *msg = (const char *)message; char buf[MAXTEXTLEN] = ""; + if (verboseMode) { switch (type) { - case AVRInterface::AVRMessageType_T::mtStatus: - sprintf_s(buf, MAXTEXTLEN, "AVR Status: %-60s", msg); + case mtState: + sprintf_s(buf, MAXTEXTLEN, "AVR Status: %-60s", avr->GetStateLabel(attrib)); + Console_SetColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); Console_WriteAt(0, 1, buf); + Console_RestoreColor(); break; - case AVRInterface::AVRMessageType_T::mtInfo: + case mtInfo: Console_WriteAt(0, -1, msg); Console_ScrollBottomRegion(); break; - case AVRInterface::AVRMessageType_T::mtModelInfo: + case mtModelInfo: Console_WriteAt(0, 2, msg); break; - case AVRInterface::AVRMessageType_T::mtStreamStart: + case mtStreamStart: Console_SetCursor(0, 3); // break; // fall through - case AVRInterface::AVRMessageType_T::mtStream: + case mtStream: Console_AdvanceToNextLineIfNotRoomFor(40); // @TODO hard-coded - ick + if (attrib) { + Console_SetColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); + } Console_Write(msg); + if (attrib) { + Console_RestoreColor(); + } + break; + case mtXmtdMsg: + Console_SetCursor(0, -1); + EmitBuffer(">", (const uint8_t *)msg, attrib, true); + break; + case mtRcvdMsg: + Console_SetCursor(0, -1); + EmitBuffer("<", (const uint8_t *)msg, attrib, true); + break; + case mtExtendedResp: + Console_SetCursor(0, -1); + EmitBuffer("[", (const uint8_t *)msg, attrib, true); + break; + case mtStatusMsg: + Console_SetCursor(0, -1); + EmitBuffer("}", (const uint8_t *)msg, attrib, true); + break; + case mtOperationResp: + // This is just the echo of the command + // so there is nothing to report that wouldn't be a duplicate + //Console_SetCursor(0, -1); + //EmitBuffer("{", (const uint8_t *)msg, attrib, true); + break; + case mtParamUpdated: + message = "x"; + break; + case mtErrNotFound: + sprintf_s(buf, MAXTEXTLEN, "AVRCommand(%02X,%02X,%02X) -- not found", (attrib >> 16), (attrib >> 8) & 0xFF, attrib & 0xFF); + Console_WriteAt(0, -1, buf); + break; + case mtErrRxLength: + break; + case mtErrMalloc: + break; + case mtFailed: break; default: break; } } + return true; } void EmitCommandLineHelp() { @@ -668,7 +753,7 @@ void EmitCommandLineHelp() { printf("\n"); printf("Options:\n"); printf("\n"); - printf(" -SerialPort=X[,yyyy] Set to Com port X to baud rate yyyy.\n"); + printf(" -SerialPort=X[,yyyy] Set to Serial Port X to baud rate yyyy.\n"); printf(" Defaults baud is %d\n", avrBaud); printf(" NOTE: At least for the RX-V2400, 9600,8,N,1 is required.\n"); printf(" NOTE: At least for the RX-V2400, the host must assert RTS.\n"); @@ -779,7 +864,7 @@ int __cdecl main(int argc, char *argv[]) { short consoleWidth = 122; short consoleHeight = 80; short consoleScrollHeight = 30; - short consoleLeft = 15; + short consoleLeft = 50; short consoleTop = 15; int CommandToExecute[4] = { -1, -1, -1, -1 }; float db; @@ -790,8 +875,7 @@ int __cdecl main(int argc, char *argv[]) { GetProgName(argv[0]); UserCommandsSanityCheck(); // If the table is bad, we exit here - avr = new AVRInterface(SerialSend); - avr->RegisterInformationCallback(InformationUpdate); + avr = new AVRInterface(InformationUpdate, SerialSend); ReadIniFile(); @@ -822,10 +906,10 @@ int __cdecl main(int argc, char *argv[]) { // switch (parseCount) { case 1: - CommandToExecute[1] = AVRInterface::AVRFunction_E::fncFunctionCount; + CommandToExecute[1] = AVRFunction_T::fncFunctionCount; // break; // fall thru on purpose case 2: - CommandToExecute[2] = AVRInterface::AVRArg_T::eARGCount; + CommandToExecute[2] = AVRArg_T::eARGCount; // break; // fall thru on purpose default: // nothing to do @@ -833,32 +917,32 @@ int __cdecl main(int argc, char *argv[]) { } bool saveVerbose = verboseMode; verboseMode = true; - avr->ExportInformation((AVRInterface::AVRSubsystem_T)CommandToExecute[0], - (AVRInterface::AVRFunction_E)CommandToExecute[1], - (AVRInterface::AVRArg_T)CommandToExecute[2]); + avr->ExportInformation((AVRSubsystem_T)CommandToExecute[0], + (AVRFunction_T)CommandToExecute[1], + (AVRArg_T)CommandToExecute[2]); verboseMode = saveVerbose; exit(EXIT_OK); } else if (0 == strcmp(argv[i], "-Power=On")) { - CommandToExecute[0] = AVRInterface::subMain; - CommandToExecute[1] = AVRInterface::fncPower; - CommandToExecute[2] = AVRInterface::eOn; + CommandToExecute[0] = subMain; + CommandToExecute[1] = fncPower; + CommandToExecute[2] = eOn; } else if (0 == strcmp(argv[i], "-Power=Off")) { - CommandToExecute[0] = AVRInterface::subMain; - CommandToExecute[1] = AVRInterface::fncPower; - CommandToExecute[2] = AVRInterface::eOff; + CommandToExecute[0] = subMain; + CommandToExecute[1] = fncPower; + CommandToExecute[2] = eOff; } else if (0 == strcmp(argv[i], "-Mute=On")) { - CommandToExecute[0] = AVRInterface::subMain; - CommandToExecute[1] = AVRInterface::fncMute; - CommandToExecute[2] = AVRInterface::eOn; + CommandToExecute[0] = subMain; + CommandToExecute[1] = fncMute; + CommandToExecute[2] = eOn; } else if (0 == strcmp(argv[i], "-Mute=Off")) { - CommandToExecute[0] = AVRInterface::subMain; - CommandToExecute[1] = AVRInterface::fncMute; - CommandToExecute[2] = AVRInterface::eOff; + CommandToExecute[0] = subMain; + CommandToExecute[1] = fncMute; + CommandToExecute[2] = eOff; } else if (1 == sscanf_s(argv[i], "-Zone1Volume=%4f", &db)) { if (db >= -80.0f && db <= +16.5f) { - CommandToExecute[0] = AVRInterface::sysCommand; - CommandToExecute[1] = AVRInterface::fncSetValue; - CommandToExecute[2] = AVRInterface::eMasterVol; + CommandToExecute[0] = sysCommand; + CommandToExecute[1] = fncSetValue; + CommandToExecute[2] = eMasterVol; CommandToExecute[3] = avr->VolumeDBtoAPIValue(db); } else { printf("***** Volume %+4.1f not in the range '-80.0 <= value <= 16.5' *****\n", db); @@ -866,9 +950,9 @@ int __cdecl main(int argc, char *argv[]) { } } else if (1 == sscanf_s(argv[i], "-Zone2Volume=%4f", &db)) { if (db >= -80.0f && db <= +16.5f) { - CommandToExecute[0] = AVRInterface::sysCommand; - CommandToExecute[1] = AVRInterface::fncSetValue; - CommandToExecute[2] = AVRInterface::eZone2Vol; + CommandToExecute[0] = sysCommand; + CommandToExecute[1] = fncSetValue; + CommandToExecute[2] = eZone2Vol; CommandToExecute[3] = avr->VolumeDBtoAPIValue(db); } else { printf("***** Volume %+4.1f not in the range '-80.0 <= value <= 16.5' *****\n", db); @@ -876,9 +960,9 @@ int __cdecl main(int argc, char *argv[]) { } } else if (1 == sscanf_s(argv[i], "-Zone3Volume=%4f", &db)) { if (db >= -80.0f && db <= +16.5f) { - CommandToExecute[0] = AVRInterface::sysCommand; - CommandToExecute[1] = AVRInterface::fncSetValue; - CommandToExecute[2] = AVRInterface::eZone3Vol; + CommandToExecute[0] = sysCommand; + CommandToExecute[1] = fncSetValue; + CommandToExecute[2] = eZone3Vol; CommandToExecute[3] = avr->VolumeDBtoAPIValue(db); } else { printf("***** Volume %+4.1f not in the range '-80.0 <= value <= 16.5' *****\n", db); @@ -900,7 +984,7 @@ int __cdecl main(int argc, char *argv[]) { DWORD refTime = AppTime(); DWORD nowTime = AppTime(); DWORD elapsedTime = nowTime - refTime; - AVRInterface::AVRState_T state = AVRInterface::stPoweringUp; + AVRInterface::AVRState_T state = AVRInterface::stMaxStates; do { state = avr->Tick(nowTime); Sleep(10); // @TODO how long to wait should not be based on lucky timing @@ -916,9 +1000,9 @@ int __cdecl main(int argc, char *argv[]) { if (pExtendedMessage) { SendExtendedMessage(pExtendedMessage); } else { - avr->AVRCommand((AVRInterface::AVRSubsystem_T)CommandToExecute[0], - (AVRInterface::AVRFunction_E)CommandToExecute[1], - (AVRInterface::AVRArg_T)CommandToExecute[2], + avr->AVRCommand((AVRSubsystem_T)CommandToExecute[0], + (AVRFunction_T)CommandToExecute[1], + (AVRArg_T)CommandToExecute[2], (uint8_t)CommandToExecute[3]); } refTime = nowTime = AppTime(); @@ -952,14 +1036,15 @@ int __cdecl main(int argc, char *argv[]) { ProcessKeyboard(); SerialQueue_T anyRcvdMsg = ProcessSerialReceive(); if (anyRcvdMsg.len) { - bool showAllFlag = avr->HandleMessage(anyRcvdMsg.message, anyRcvdMsg.len); + uint8_t offsetChanged = avr->HandleMessage(anyRcvdMsg.message, anyRcvdMsg.len); - if (showAllFlag) { + if (offsetChanged) { bool priorState = Console_SetCursorVisibility(false); - avr->ReportAllStatus(); + avr->ReportAllStatus(offsetChanged); Console_SetCursorVisibility(priorState); } } + Sleep(10); ProcessWindowsMessage(); } while (!UserExitRequested && !SystemExitRequested); DetachSerialPort(); @@ -1024,57 +1109,6 @@ bool CheckTheChecksum(uint8_t *szBuffer, uint32_t num) { } -// HandleMessage -// -// Given a response string, typically of the form: -// [11] .... [03] -// [12] .... [03] -// ... etc -// -// -void HandleMessage(uint8_t *szBuffer, uint32_t num) { - switch (szBuffer[0]) { - case 0x02: // STX - //ProcessReportResponse(szBuffer, num); - break; - case 0x11: // DC1 - break; - case 0x12: // DC2 - if (CheckTheChecksum(szBuffer, num)) { - if (num == 21) { - memcpy(&avrStatus.header, &szBuffer[1], sizeof(AVR_StatusHeader_T)); - num = Hex2Dec(&avrStatus.header.length[0], 2); - memcpy(&avrStatus.config.DT0, &szBuffer[9], num); // Copy bits of the config - avrStatus.headerValid = true; - } else if (num == 150) { - memcpy(&avrStatus.header, &szBuffer[1], sizeof(AVR_StatusHeader_T)); - num = Hex2Dec(&avrStatus.header.length[0], 2); - memcpy(&avrStatus.config.DT0, &szBuffer[9], num); // Copy the config - - //memcpy(&avrStatus.header, &szBuffer[1], sizeof(AVR_StatusHeader_T) + sizeof(AVR_Configuration_T)); - avrStatus.headerValid = true; - avrStatus.configValid = true; - } else { - printf("***** Received message of unexpected length [%u]\n", num); - } - } else { - Console_WriteAt(0, -1, "Checksum failure on Status Header"); - } - //PrintConfiguration(szBuffer); - break; - case 0x14: // DC4 Extended Response - //DecodeExtended(szBuffer); - // Decode Extended response - break; - case '0': - //rcmd = Hex2Dec(&szBuffer[0], 2); - //DecodeString(rcmd, &szBuffer[2]); - break; - default: - //printf("[%d] %s\n", i, szBuffer); - break; - } -} // ProcessSerialReceive // @@ -1089,7 +1123,8 @@ SerialQueue_T ProcessSerialReceive() { static uint8_t *p = messageBuf[bufInUse]; // used to fill the partialRx as data comes in SerialQueue_T retInfo = { NULL, 0 }; - uint32_t num = avrPort.Read(partialRx, MAXTEXTLEN); + #include + uint32_t num = rs232Port.Read(partialRx, MAXTEXTLEN); if (num) { for (uint32_t i = 0; i < num; i++) { *p = partialRx[i]; @@ -1102,10 +1137,12 @@ SerialQueue_T ProcessSerialReceive() { bufInUse = (++bufInUse & 1); p = messageBuf[bufInUse]; // Reset the buffer for the next message, which might be in partialRx *p = '\0'; + } else { + *p = '\0'; // keep it null terminated } } if (messageBuf[0]) { - //EmitBuffer("~", messageBuf, 0, true); // Show them the partial receipt if anything is there + //EmitBuffer("~", (const uint8_t *)messageBuf, 0, true); // Show them the partial receipt if anything is there } } return retInfo; @@ -1114,7 +1151,7 @@ SerialQueue_T ProcessSerialReceive() { void EnumerateComPorts() { - printf("Com Port Scan:\n"); + printf("Serial Port Scan:\n"); int foundPorts = 0; for (int pNum = COM_MIN_PORT; pNum < COM_MAX_PORT; pNum++) { char cBuf[20]; // generously sized @@ -1135,18 +1172,18 @@ void EnumerateComPorts() { CloseHandle(port); } if (portFound) { - printf(" Com Port %d found.\n", pNum); + printf(" Serial Port %d found.\n", pNum); } } if (foundPorts == 0) { - printf(" No Com Ports found, perhaps you need to plug in an adapter?\n"); + printf(" No Serial Ports found, perhaps you need to plug in an adapter?\n"); } } int DetachSerialPort() { - if (avrPort.IsOpen()) { - avrPort.Close(); + if (rs232Port.IsOpen()) { + rs232Port.Close(); } return true; } @@ -1158,11 +1195,11 @@ int AttachToSerialPort() { sprintf_s(buf, sizeof(buf), "\\\\.\\COM%d", avrOnPort); uint32_t Access = GENERIC_WRITE | GENERIC_READ; - if (avrPort.Open(buf, avrBaud, 8, NOPARITY, ONESTOPBIT, Access)) { + if (rs232Port.Open(buf, avrBaud, 8, NOPARITY, ONESTOPBIT, Access)) { success = true; - avrPort.Set_RTS_State(false); + rs232Port.Set_RTS_State(false); Sleep(50); - avrPort.Set_RTS_State(true); + rs232Port.Set_RTS_State(true); Sleep(50); } } diff --git a/AVR Working Controller/AVR.vcxproj b/AVR Working Controller/AVR.vcxproj index 8a72ada..7bc64bb 100644 --- a/AVR Working Controller/AVR.vcxproj +++ b/AVR Working Controller/AVR.vcxproj @@ -129,12 +129,14 @@ + + diff --git a/AVR Working Controller/AVR.vcxproj.filters b/AVR Working Controller/AVR.vcxproj.filters index 8c750f6..ce18cf7 100644 --- a/AVR Working Controller/AVR.vcxproj.filters +++ b/AVR Working Controller/AVR.vcxproj.filters @@ -30,6 +30,9 @@ Source Files + + Source Files + @@ -44,5 +47,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/AVR Working Controller/AVR.vcxproj.user b/AVR Working Controller/AVR.vcxproj.user index 18ec96e..022778a 100644 --- a/AVR Working Controller/AVR.vcxproj.user +++ b/AVR Working Controller/AVR.vcxproj.user @@ -1,7 +1,7 @@  - -SerialPort=2 -Command=0,1,4 + -SerialPort=2 WindowsLocalDebugger \ No newline at end of file diff --git a/AVR Working Controller/AVRCommandDecoder.cpp b/AVR Working Controller/AVRCommandDecoder.cpp index 834c9e2..5580f68 100644 --- a/AVR Working Controller/AVRCommandDecoder.cpp +++ b/AVR Working Controller/AVRCommandDecoder.cpp @@ -392,14 +392,14 @@ const char *Mode1Mode2Text(uint8_t val) { 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 ", + /* 0 */ "All Off", + /* 1 */ "All On", + /* 2 */ "Zone 1 On | 2,3 Off", + /* 3 */ "Zone 1 Off | 2,3 On", + /* 4 */ "Zone 1,2 On | 3 Off", + /* 5 */ "Zone 1 On | 2,3 Off", + /* 6 */ "Zone 1 Off | 2,3 On", + /* 7 */ "Zone 1,2 Off | 3 On", }; if (val < 8) strcpy_s(buf, sizeof(buf), powerList[val]); diff --git a/AVR Working Controller/AVRInterface.cpp b/AVR Working Controller/AVRInterface.cpp index b5c975a..a97c10a 100644 --- a/AVR Working Controller/AVRInterface.cpp +++ b/AVR Working Controller/AVRInterface.cpp @@ -12,10 +12,6 @@ #define LONGESTTEXT 150 -using AVRSubsys = AVRInterface::AVRSubsystem_T; -using AVRFunc = AVRInterface::AVRFunction_E; -using AVRArg = AVRInterface::AVRArg_T; - typedef enum { eReady, ePowerOn, @@ -33,28 +29,17 @@ typedef struct { } Message_T; 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 const char *TextFormatter; // used primarily for development printf(TextFormatter, value) const char *(*fncValueToText)(uint8_t rDat); -} MessageHandler_T; +} MessageTextHandler_T; -static const char * StateText[] = { - "Powering Up", - "Awaiting Ready Response", - "Initializing", - "Retry Initializing", - "Ready", - "Awaiting Response", - "Unknown State" -}; -// This is based on the longest thing from the MessageHandlers text field and the generated text +// This is based on the longest thing from the MessageHandlerText text field and the generated text // "MultiCh Surround" "Surround" const char *PCMessageFormat = "%18s %-20s"; const uint8_t LengthCheck = 40; @@ -65,11 +50,11 @@ const uint8_t LengthCheck = 40; // show all status // fncHelper: optional function to call upon receipt // -static const MessageHandler_T MessageHandlers[] = { +static const MessageTextHandler_T MessageHandlerText[] = { // // Configuration Map for Response Messages // - // +--------------------------- rCmd + // +---------------------------- rCmd // | +----------------------- DT Block Offset // | | +-------------------- Number of Bytes to transfer into the DT Block // | | | +----------------- Force a 'show all' status screen update @@ -180,19 +165,58 @@ static const MessageHandler_T MessageHandlers[] = { { 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", OffOnText }, +}; + +const char *StateMachineTextLabel[] = { + "Powering Up", + "Awaiting Ready Response", + "Initializing", + "Retry Initializing", + "Ready", + "Awaiting Response", + "Failed to contact", + "Unknown State", }; +// static instance definition +AVRInterface *AVRInterface::s_instance = nullptr; -AVRInterface::AVRInterface(bool (*SendMessage)(const uint8_t *buffer, uint16_t len)) { - SendMethod = SendMessage; +// Trampoline: assigned into AVRDriver::NotifyHost so the driver calls into +// AVRInterface::ProcessReportResponse(instance, ...). This avoids changing +// the existing NotifyCallBack signature which has no context pointer. +bool AVRInterface::NotifyTrampoline(AVRMessageType_T type, const void *message, uint32_t attrib) { + if (AVRInterface::s_instance) { + return AVRInterface::s_instance->ProcessReportResponse(type, message, attrib); + } + return false; +} + +AVRInterface::AVRInterface( + NotifyCallBack notifyCB, /// 100) { - if (ReportInformation) { // Guard it - (*ReportInformation)(mtInfo, txtBuf); + if (AppNotify) { // Guard it + (*AppNotify)(mtInfo, txtBuf, (uint32_t)strlen(txtBuf)); } sprintf_s(txtBuf, LONGESTTEXT, " "); // new line pTxtAppend = txtBuf + strlen(txtBuf); @@ -250,277 +274,25 @@ void AVRInterface::MessageReport(const char *prefix, const void *buf, size_t len p++; } if (strlen(txtBuf)) { - if (ReportInformation) { // Guard it - (*ReportInformation)(mtInfo, txtBuf); + if (AppNotify) { // Guard it + (*AppNotify)(mtInfo, txtBuf, (uint32_t)strlen(txtBuf)); } } } -AVRInterface::AVRState_T AVRInterface::Tick(uint32_t now_ms) { - if (!bFirstTickInitialized) { - bFirstTickInitialized = true; - firstTick_ms = now_ms; - } - lastTick_ms = now_ms; - uint32_t elapsed_ms = now_ms - sentAtTime_ms; - char buf[LONGESTTEXT] = ""; +//bool AVRInterface::HostSendPassthru(const uint8_t * message, uint32_t len) { +// return (*HostSendCB)(message, len); +//} - if (oldState != state && ReportInformation) { - (*ReportInformation)(mtStatus, StateText[state]); +const char *AVRInterface::GetStateLabel(uint32_t st) { + if (st >= stMaxStates) { + st = stMaxStates; } - oldState = state; - switch (state) { - default: - case AVRState_T::stPoweringUp: - readyResponsReceived = false; - AVRCommand(sysCommand, fncReady, eOn); - (*ReportInformation)(mtInfo, "Send Ready"); - sentAtTime_ms = now_ms; - readyTries++; - state = stAwaitingReadyResponse; - break; - case stAwaitingReadyResponse: - if (readyResponsReceived) { - state = stReady; - } else if (elapsed_ms > RETRY_INTERVAL_ms) { - if (readyTries > MAXTRIES) { - // fail - state = stFailed; - } else { - state = stPoweringUp; - } - } - break; - case AVRState_T::stInitializing: - break; - case AVRState_T::stRetryInitializing: - break; - case AVRState_T::stAwaitingResponse: - if (commandResponseReceived) { - state = stReady; - } else if (elapsed_ms > RETRY_INTERVAL_ms) { - ProcessSerialQueue(); - state = stAwaitingResponse; - } - break; - case AVRState_T::stReady: - ProcessSerialQueue(); - break; - } - return state; -} - -/// @brief Handle a just received message by parsing it -/// -/// Given a response string, typically of the form: -/// [02] .... [03] // Command Responses from the AVR -/// [11] .... [03] // Commands to -/// [12] .... [03] -/// [14] ............ [03] -/// -/// @param buffer contains the message -/// @param len of the message -/// @return true, if data was accepted and the overall status changed, so might be shown -/// -bool AVRInterface::HandleMessage(const uint8_t *buffer, uint16_t len) { - bool showAllFlag = false; - - MessageReport("<", buffer, len); - switch (state) { - case stAwaitingReadyResponse: - switch (buffer[0]) { - case 0x02: // STX ETX - commandResponseReceived = true; - showAllFlag = ProcessReportResponse(buffer, len); - break; - case 0x11: // DC1 ETX - // AVR does not send any DC1 messages, these are for commands to the AVR - break; - case 0x12: // DC2 ETX - if (CheckTheChecksum(buffer, len)) { - if (len == 21) { // Short message when power is off - memcpy(&avrStatus.header, &buffer[1], sizeof(AVR_StatusHeader_T)); - len = Hex2Dec(&avrStatus.header.length[0], 2); - memcpy(&avrStatus.config.DT0, &buffer[9], len); // Copy bits of the config - avrStatus.headerValid = true; - showAllFlag = true; - } else if (len == 150) { // Long message when power is on - memcpy(&avrStatus.header, &buffer[1], sizeof(AVR_StatusHeader_T)); - len = Hex2Dec(&avrStatus.header.length[0], 2); - memcpy(&avrStatus.config.DT0, &buffer[9], len); // Copy the config - avrStatus.headerValid = true; - avrStatus.configValid = true; - showAllFlag = true; - } else { - printf("***** Received message of unexpected length [%u]\n", len); - } - readyResponsReceived = true; - } - break; - case 0x14: // DC4 ETX - // DecodeExtendedResponse(buffer, len); // once I figure out what is in here... - break; - default: - break; - } - break; - case stAwaitingResponse: - // @TODO Process the message here... - commandResponseReceived = true; - break; - case stReady: - switch (buffer[0]) { - case 0x02: // STX ETX - commandResponseReceived = true; - showAllFlag = ProcessReportResponse(buffer, len); - break; - case 0x11: // DC1 ETX - break; - case 0x12: // DC2 ETX - if (CheckTheChecksum(buffer, len)) { - if (len == 21) { // Short message when power is off - memcpy(&avrStatus.header, &buffer[1], sizeof(AVR_StatusHeader_T)); - len = Hex2Dec(&avrStatus.header.length[0], 2); - memcpy(&avrStatus.config.DT0, &buffer[9], len); // Copy bits of the config - avrStatus.headerValid = true; - showAllFlag = true; - } else if (len == 150) { // Long message when power is on - memcpy(&avrStatus.header, &buffer[1], sizeof(AVR_StatusHeader_T)); - len = Hex2Dec(&avrStatus.header.length[0], 2); - memcpy(&avrStatus.config.DT0, &buffer[9], len); // Copy the config - avrStatus.headerValid = true; - avrStatus.configValid = true; - showAllFlag = true; - } else { - printf("***** Received message of unexpected length [%u]\n", len); - } - readyResponsReceived = true; - } - break; - case 0x14: // DC4 ETX - // DecodeExtendedResponse(buffer, len); // once I figure out what is in here... - break; - default: - break; - } - break; - } - return showAllFlag; -} - -bool AVRInterface::Initialize() { - state = AVRState_T::stPoweringUp; - return true; -} - - -bool AVRInterface::RegisterInformationCallback(void(*StatusChangeCallback)(AVRMessageType_T type, const char *msg)) { - ReportInformation = StatusChangeCallback; - return true; -} - - -bool AVRInterface::AVRSendOSDMessage(const char *pMsg) { - const char valid[] = " !#%&()*+,-.0123456789:<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz"; - char buf[17] = { 0 }; - if (strlen(pMsg) <= 16) { - for (size_t i = 0; i < 16; i++) { - if (*pMsg == '\0') { - buf[i] = ' '; - } else if (strchr(valid, *pMsg)) { - buf[i] = *pMsg++; - } else { - return false; // Invalid character - } - } - ProcessSerialQueue("\x02" "21000" "\x03", 7); // Start the OSD message - char msg[8]; - for (int i = 0; i < 16; i += 4) { - strcpy_s(msg, sizeof(msg), "\x02"); // Each chunk - strcat_s(msg, sizeof(msg), "3"); - strncat_s(msg, sizeof(msg), &buf[i], 4); - strcat_s(msg, sizeof(msg), "\x03"); - ProcessSerialQueue(msg, 7); - } - return true; - } else { - return false; - } -} - -bool AVRInterface::ProcessSerialQueue(const void *msg, uint16_t len) { - const char *p = (const char *)msg; - bool retVal = false; // assume fail - static bool freshData = false; - - 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); - *(serialQueue[serialQueueCount].messageToSend + len) = '\0'; - serialQueue[serialQueueCount].len = len; - serialQueueCount++; - retVal = true; - freshData = true; - } - } - } - if (serialQueueCount) { - if ((*SendMethod)((const uint8_t *)serialQueue[0].messageToSend, serialQueue[0].len)) { - --serialQueueCount; - free(serialQueue[0].messageToSend); - serialQueue[0].messageToSend = NULL; - for (int i = 0; i < serialQueueCount; i++) { - serialQueue[i] = serialQueue[i + 1]; - } - retVal = true; - } - state = stAwaitingResponse; - } - return retVal; -} - -void AVRInterface::FreeMemory() { - for (int i = 0; i < serialQueueCount; i++) { - if (serialQueue[0].messageToSend) - free(serialQueue[0].messageToSend); - } -} - - -bool AVRInterface::CheckTheChecksum(const uint8_t *szBuffer, uint32_t num) { - uint8_t sum = 0; - for (uint16_t i = 1; i < num - 3; i++) { - sum += szBuffer[i]; - } - uint8_t cksum = (uint8_t)Hex2Dec(&szBuffer[num - 3], 2); - return (sum == cksum); -} - -// Hex2Dec -// -// All responses are pretty much Hex-ASCII, so -// we sometimes want to convert it to decimal -// This takes a buffer and converts the specified -// number of characters. -// -uint16_t AVRInterface::Hex2Dec(const uint8_t *p, int dig) { - uint16_t x = 0; - while (dig--) { - if (*p >= '0' && *p <= '9') - x = x * 16 + *p - '0'; - else if (*p >= 'a' && *p <= 'f') - x = x * 16 + 0x0a + *p - 'a'; - else if (*p >= 'A' && *p <= 'F') - x = x * 16 + 0x0a + *p - 'A'; - p++; - } - return x; + return StateMachineTextLabel[st]; } +#if 1 // ProcessReportResponse // // @param[in] szBuffer is the received message @@ -530,73 +302,136 @@ uint16_t AVRInterface::Hex2Dec(const uint8_t *p, int dig) { // '\x02' 'type' 'guard' 'rcmd0' 'rcmd1' 'rdat0' 'rdat1' '\x03' // [0] [1] [2] [3] [4] [5] [6] [7] // -bool AVRInterface::ProcessReportResponse(const 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); +bool AVRInterface::ProcessReportResponse(AVRMessageType_T mtype, const void *szBuffer, uint32_t param) { + const uint8_t *p = (const uint8_t *)szBuffer; char buf[LONGESTTEXT]; - (void)len; // not used + (void)param; // not used bool showAllFlag = false; - 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].TextFormatter && MessageHandlers[i].fncValueToText) { - if (ReportInformation) { // Guard it - sprintf_s(buf, LONGESTTEXT, MessageHandlers[i].TextFormatter, MessageHandlers[i].fncValueToText(rdat)); - (*ReportInformation)(mtInfo, buf); + switch (mtype) { + case mtModelInfo: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtState: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtInfo: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtStreamStart: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtStream: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtRcvdMsg: + if (p) { + // 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(p + 1, 1); + uint8_t guard = (uint8_t)Hex2Dec(p + 2, 1); + uint8_t rcmd = (uint8_t)Hex2Dec(p + 3, 2); + uint8_t rdat = (uint8_t)Hex2Dec(p + 5, 2); + bool found = false; + + for (int i = 0; i < sizeof(MessageHandlerText) / sizeof(MessageHandlerText[0]); i++) { + if (MessageHandlerText[i].rCmd == rcmd) { + found = true; + //if (MessageHandlerText[i].numToTransfer == 1) { + // //memcpy(&avrStatus.config.DT0 + MessageHandlerText[i].configOffset, p + 6, 1); + //} + //if (MessageHandlerText[i].numToTransfer == 2) { + // //memcpy(&avrStatus.config.DT0 + MessageHandlerText[i].configOffset, p + 5, 2); + //} + if (MessageHandlerText[i].TextFormatter && MessageHandlerText[i].fncValueToText) { + if (AppNotify) { // Guard it + sprintf_s(buf, LONGESTTEXT, MessageHandlerText[i].TextFormatter, MessageHandlerText[i].fncValueToText(rdat)); + (*AppNotify)(mtInfo, buf, (uint32_t)strlen(buf)); + } + } + if (MessageHandlerText[i].showAll) { + showAllFlag = true; // ShowAllStatusInfo(); + } + break; // no need to scan more } } - if (MessageHandlers[i].showAll) { - showAllFlag = true; // ShowAllStatusInfo(); + if (!found && AppNotify) { + sprintf_s(buf, LONGESTTEXT, "***** type: %X, guard: %X, cmd: %02X, data: %02X", type, guard, rcmd, rdat); + (*AppNotify)(mtInfo, buf, (uint32_t)strlen(buf)); } - break; // no need to scan more + } else { + (*AppNotify)(mtype, szBuffer, param); } - } - if (!found && ReportInformation) { - sprintf_s(buf, LONGESTTEXT, "***** type: %X, guard: %X, cmd: %02X, data: %02X", type, guard, rcmd, rdat); - (*ReportInformation)(mtInfo, buf); - } + case mtXmtdMsg: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtStatusMsg: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtOperationResp: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtParamUpdated: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtExtendedResp: + (*AppNotify)(mtype, szBuffer, param); + break; + case mtErrNotFound: + // forward formatted error to application callback + if (AppNotify) { + sprintf_s(buf, LONGESTTEXT, "AVRCommand(%d,%d,%d) is invalid.", (param >> 16) & 0xFF, (param >> 8) & 0xFF, param & 0xFF); + (*AppNotify)(mtype, buf, (uint32_t)strlen(buf)); + } + break; + case mtErrRxLength: + if (AppNotify) { + sprintf_s(buf, LONGESTTEXT, "Receive Message Length (%d) is invalid.", param); + (*AppNotify)(mtype, buf, (uint32_t)strlen(buf)); + } + break; + case mtErrMalloc: + if (AppNotify) { + sprintf_s(buf, LONGESTTEXT, "Malloc (%d) Failed.", param); + (*AppNotify)(mtype, buf, (uint32_t)strlen(buf)); + } + break; + case mtFailed: + if (AppNotify) { + (*AppNotify)(mtype, szBuffer, (uint32_t)strlen((const char *)szBuffer)); + } + }; return showAllFlag; } +#endif void AVRInterface::MessageHandlerSanityCheck() { uint8_t usedCommands[256] = { 0 }; uint8_t blockOffset[256] = { 0 }; bool fail = false; - // Ensure that the MessageHandlers table is correct - for (int i = 0; i < sizeof(MessageHandlers) / sizeof(MessageHandlers[0]); i++) { - usedCommands[MessageHandlers[i].rCmd]++; - if (usedCommands[MessageHandlers[i].rCmd] > 1) { - printf("***** MessageHandler entry %d has duplicate rCmd of 0x%02X\n", i, MessageHandlers[i].rCmd); + // Ensure that the MessageHandlerText table is correct + for (int i = 0; i < sizeof(MessageHandlerText) / sizeof(MessageHandlerText[0]); i++) { + usedCommands[MessageHandlerText[i].rCmd]++; + if (usedCommands[MessageHandlerText[i].rCmd] > 1) { + printf("***** MessageHandler entry %d has duplicate rCmd of 0x%02X\n", i, MessageHandlerText[i].rCmd); fail = true; } - blockOffset[MessageHandlers[i].configOffset]++; - if (MessageHandlers[i].configOffset != 0 && blockOffset[MessageHandlers[i].configOffset] > 1) { - printf("***** MessageHandler entry %d has duplicate configOffset of %d\n", i, MessageHandlers[i].configOffset); + blockOffset[MessageHandlerText[i].configOffset]++; + if (MessageHandlerText[i].configOffset != 0 && blockOffset[MessageHandlerText[i].configOffset] > 1) { + printf("***** MessageHandler entry %d has duplicate configOffset of %d\n", i, MessageHandlerText[i].configOffset); fail = true; } - if (MessageHandlers[i].numToTransfer > 2) { - printf("***** MessageHandler entry %d has invalid numToTransfer of %d\n", i, MessageHandlers[i].numToTransfer); + if (MessageHandlerText[i].numToTransfer > 2) { + printf("***** MessageHandler entry %d has invalid numToTransfer of %d\n", i, MessageHandlerText[i].numToTransfer); } - if (MessageHandlers[i].configOffset + MessageHandlers[i].numToTransfer > sizeof(AVR_Configuration_T)) { - printf("***** MessageHandler entry %d has invalid configOffset of %d\n", i, MessageHandlers[i].configOffset); + if (MessageHandlerText[i].configOffset + MessageHandlerText[i].numToTransfer > sizeof(AVR_Configuration_T)) { + printf("***** MessageHandler entry %d has invalid configOffset of %d\n", i, MessageHandlerText[i].configOffset); } } if (fail) { @@ -610,8 +445,10 @@ void AVRInterface::MessageHandlerSanityCheck() { // Various responses need to be formatted and shown on screen // The last param will allow resetting the column counter // and pre and post-pending \n +// +// @returns how far we moved in the buffer // -void AVRInterface::PCMessage(const char *msg, int len, uint8_t **src, const char *(fncHelper)(uint8_t val)) { +uint8_t AVRInterface::PCMessage(const char *msg, uint8_t len, uint8_t **src, const char *(fncHelper)(uint8_t val), bool highlight) { char buf[LONGESTTEXT] = ""; const char *p = buf; @@ -632,325 +469,15 @@ void AVRInterface::PCMessage(const char *msg, int len, uint8_t **src, const char msg, p ); - if (ReportInformation) { // Guard it - (*ReportInformation)(mtStream, outBuf); + if (AppNotify) { // Guard it + (*AppNotify)(mtStream, outBuf, highlight); } + return len; } -typedef const struct { - AVRInterface::AVRSubsystem_T subsystem; - AVRInterface::AVRFunction_E function; - AVRInterface::AVRArg_T arg; - const char *Message; - uint16_t MessageLen; - // Helper? -} MessageTable_T; -MessageTable_T MessageTable[] = { - // System Commands - { AVRSubsys::sysCommand, AVRFunc::fncReady, AVRInterface::eOn, "\x11" "000" "\x03", 5 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportEnable, AVRInterface::eOn, "\x02" "20000" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportEnable, AVRInterface::eOff, "\x02" "20001" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e0ms, "\x02" "20100" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e50ms, "\x02" "20101" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e100ms, "\x02" "20102" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e150ms, "\x02" "20103" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e200ms, "\x02" "20104" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e250ms, "\x02" "20105" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e300ms, "\x02" "20106" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e350ms, "\x02" "20107" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncReportDelay, AVRInterface::e400ms, "\x02" "20108" "\x03", 7 }, - - { AVRSubsys::sysCommand, AVRFunc::fncRequest, AVRInterface::eTuningFreq, "\x02" "22000" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncRequest, AVRInterface::eMainVolDB, "\x02" "22001" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncRequest, AVRInterface::eZone2VolDB, "\x02" "22002" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncRequest, AVRInterface::eInputName, "\x02" "22003" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncRequest, AVRInterface::eZone2InputName, "\x02" "22004" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncRequest, AVRInterface::eZoneXVolDB, "\x02" "22005" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncRequest, AVRInterface::eZoneXInputName, "\x02" "22006" "\x03", 7 }, - - // System Commands with variable data - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eMasterVol, "\x02" "230xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eZone2Vol, "\x02" "231xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eMainLRBal, "\x02" "232xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eMainLevel, "\x02" "233xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eZone3Vol, "\x02" "234xx" "\x03", 7 }, - - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eMainLevelR, "\x02" "240xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eMainLevelL, "\x02" "241xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eCenterLevel, "\x02" "242xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eRearR, "\x02" "243xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eRearL, "\x02" "244xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eFrontR, "\x02" "245xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eFrontL, "\x02" "246xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eSurBackR, "\x02" "247xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eSurBackL, "\x02" "248xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eSwfr1, "\x02" "249xx" "\x03", 7 }, - { AVRSubsys::sysCommand, AVRFunc::fncSetValue, AVRInterface::eSwfr2, "\x02" "24Axx" "\x03", 7 }, - - // Operation Commands - { AVRSubsys::subMain, AVRFunc::fncPower, AVRInterface::eOn, "\x02" "07A1D" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncPower, AVRInterface::eOff, "\x02" "07A1E" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncVolume, AVRInterface::eUp, "\x02" "07A1A" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncVolume, AVRInterface::eDown, "\x02" "07A1B" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncMute, AVRInterface::eOn, "\x02" "07EA2" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncMute, AVRInterface::eOff, "\x02" "07EA3" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncOSD, AVRInterface::eOSDOff, "\x02" "07EB0" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncOSD, AVRInterface::eOSDShort, "\x02" "07EB1" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncOSD, AVRInterface::eOSDFull, "\x02" "07EB2" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncNightModeOnOff, AVRInterface::eOn, "\x02" "07E9B" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncNightModeOnOff, AVRInterface::eOff, "\x02" "07E9C" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSleep, AVRInterface::eSleepOff, "\x02" "07EB3" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSleep, AVRInterface::eSleep120, "\x02" "07EB4" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSleep, AVRInterface::eSleep90, "\x02" "07EB5" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSleep, AVRInterface::eSleep60, "\x02" "07EB6" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSleep, AVRInterface::eSleep30, "\x02" "07EB7" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSpeakerAOnOff, AVRInterface::eOn, "\x02" "07EAB" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSpeakerAOnOff, AVRInterface::eOff, "\x02" "07EAC" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSpeakerBOnOff, AVRInterface::eOn, "\x02" "07EAD" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSpeakerBOnOff, AVRInterface::eOff, "\x02" "07EAE" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDC1TrigControl, AVRInterface::eZone1, "\x02" "07E32" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDC1TrigControl, AVRInterface::eZone2, "\x02" "07E33" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDC1TrigControl, AVRInterface::eZone3, "\x02" "07E31" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDualMono, AVRInterface::eDualMain, "\x02" "07E93" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDualMono, AVRInterface::eDualSub, "\x02" "07E94" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDualMono, AVRInterface::eDualAll, "\x02" "07E95" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDC1TrigControl, AVRInterface::eZone1, "\x02" "07E96" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDC1TrigControl, AVRInterface::eZone2, "\x02" "07E97" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDC1TrigControl, AVRInterface::eZone3, "\x02" "07E9F" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncDC1TrigControl, AVRInterface::eZoneOR, "\x02" "07E98" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSpeakerBZone, AVRInterface::eZone1, "\x02" "07E28" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncSpeakerBZone, AVRInterface::eZone2, "\x02" "07E29" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncZone2SpeakerOnOff, AVRInterface::eOn, "\x02" "07E99" "\x03", 7 }, - { AVRSubsys::subMain, AVRFunc::fncZone2SpeakerOnOff, AVRInterface::eOff, "\x02" "07E9A" "\x03", 7 }, - - { AVRSubsys::subRadio, AVRFunc::fncRadioBand, AVRInterface::eFM, "\x02" "07EBC" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioBand, AVRInterface::eAM, "\x02" "07EBD" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioTune, AVRInterface::eUp, "\x02" "07EBE" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioTune, AVRInterface::eDown, "\x02" "07EBF" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetPage, AVRInterface::eA, "\x02" "07AE0" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetPage, AVRInterface::eB, "\x02" "07AE1" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetPage, AVRInterface::eC, "\x02" "07AE2" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetPage, AVRInterface::eD, "\x02" "07AE3" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetPage, AVRInterface::eE, "\x02" "07AE4" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e1, "\x02" "07AE5" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e2, "\x02" "07AE6" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e3, "\x02" "07AE7" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e4, "\x02" "07AE8" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e5, "\x02" "07AE9" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e6, "\x02" "07AEA" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e7, "\x02" "07AEB" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetNumber, AVRInterface::e8, "\x02" "07AEC" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetMemory, AVRInterface::eA, "\x02" "07E2B" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetMemory, AVRInterface::eB, "\x02" "07E2C" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetMemory, AVRInterface::eC, "\x02" "07E2D" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetMemory, AVRInterface::eD, "\x02" "07E2E" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetMemory, AVRInterface::eE, "\x02" "07E2F" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetMemory, AVRInterface::eF, "\x02" "07E20" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetRecall, AVRInterface::eA, "\x02" "07E35" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetRecall, AVRInterface::eB, "\x02" "07E36" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetRecall, AVRInterface::eC, "\x02" "07E37" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetRecall, AVRInterface::eD, "\x02" "07E38" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetRecall, AVRInterface::eE, "\x02" "07E39" "\x03", 7 }, - { AVRSubsys::subRadio, AVRFunc::fncRadioPresetRecall, AVRInterface::eF, "\x02" "07E3A" "\x03", 7 }, - - { AVRSubsys::subAudio, AVRFunc::fnc6ChInput, AVRInterface::eOn, "\x02" "07EA4" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fnc6ChInput, AVRInterface::eOff, "\x02" "07EA5" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncInputMode, AVRInterface::eInpAuto, "\x02" "07EA6" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncInputMode, AVRInterface::eDD_RF, "\x02" "07EA7" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncInputMode, AVRInterface::eDTS, "\x02" "07EA8" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncInputMode, AVRInterface::eDigital, "\x02" "07EA9" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncInputMode, AVRInterface::eAnalog, "\x02" "07EAA" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncInputMode, AVRInterface::eAAC, "\x02" "07E3B" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncEx_EsOnOff, AVRInterface::eOnMatrix, "\x02" "07EB8" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncEx_EsOnOff, AVRInterface::eESESOff, "\x02" "07EB9" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncEx_EsOnOff, AVRInterface::eAuto, "\x02" "07E7C" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncEx_EsOnOff, AVRInterface::eDiscrete, "\x02" "07E7D" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncEffect, AVRInterface::eEffectOn, "\x02" "07E27" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncEffect, AVRInterface::eStereo, "\x02" "07EE0" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Hall_A, "\x02" "07EE1" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Hall_B, "\x02" "07EE2" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Hall_C, "\x02" "07EE3" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Hall_USA, "\x02" "07EE4" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Hall_E, "\x02" "07EE5" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Live_Concert, "\x02" "07EE6" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Tokyo, "\x02" "07EE7" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Freiburg, "\x02" "07EE8" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Royaumont, "\x02" "07EE9" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Village_Gate, "\x02" "07EEA" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Village_Vanguard, "\x02" "07EEB" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::The_Bottom_Line, "\x02" "07EEC" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::The_Roxy_Theater, "\x02" "07EED" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Warehouse_Loft, "\x02" "07EEE" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Arena, "\x02" "07EEF" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Disco, "\x02" "07EF0" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Party, "\x02" "07EF1" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Game, "\x02" "07EF2" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Stereo_6_8Ch, "\x02" "07EFF" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Pop_Rock, "\x02" "07EF3" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::DJ, "\x02" "07EF4" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Opera, "\x02" "07EF5" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Pavillion, "\x02" "07EF6" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Mono_Movie, "\x02" "07EF7" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Variety_Sports, "\x02" "07EF8" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Spectacre, "\x02" "07EF9" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Sci_Fi, "\x02" "07EFA" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Adventure, "\x02" "07EFB" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::General, "\x02" "07EFC" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Normal, "\x02" "07EFD" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Enhanced, "\x02" "07EFE" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::PLII_Movie, "\x02" "07E67" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::PLII_Music, "\x02" "07E68" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Neo_6_Movie, "\x02" "07E69" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Neo_6_Music, "\x02" "07E6A" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Direct_2Ch, "\x02" "07EC1" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::Stereo_2Ch, "\x02" "07EC0" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::THX_Ultra_PL, "\x02" "07EC2" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::THX_Music, "\x02" "07EC3" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::THX_Ultra_PL2, "\x02" "07EC7" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncDSPSoundScape, AVRInterface::THX_Ultra_NEO6, "\x02" "07EC8" "\x03", 7 }, - - { AVRSubsys::subAudio, AVRFunc::fncVolumeMemory, AVRInterface::eA, "\x02" "07E6B" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeMemory, AVRInterface::eB, "\x02" "07E6C" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeMemory, AVRInterface::eC, "\x02" "07E6D" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeMemory, AVRInterface::eD, "\x02" "07E6E" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeMemory, AVRInterface::eE, "\x02" "07E6F" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeMemory, AVRInterface::eF, "\x02" "07E60" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeRecall, AVRInterface::eA, "\x02" "07E75" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeRecall, AVRInterface::eB, "\x02" "07E76" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeRecall, AVRInterface::eC, "\x02" "07E77" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeRecall, AVRInterface::eD, "\x02" "07E78" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeRecall, AVRInterface::eE, "\x02" "07E79" "\x03", 7 }, - { AVRSubsys::subAudio, AVRFunc::fncVolumeRecall, AVRInterface::eF, "\x02" "07E7A" "\x03", 7 }, - - { AVRSubsys::subZone1, AVRFunc::fncPower, AVRInterface::eOn, "\x02" "07E7E" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncPower, AVRInterface::eOff, "\x02" "07E7F" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::ePhono, "\x02" "07A14" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eCD, "\x02" "07A15" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eTuner, "\x02" "07A16" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eCDR, "\x02" "07A19" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eMD_Tape, "\x02" "07AC9" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eDVD, "\x02" "07AC1" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eDTV, "\x02" "07A54" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eCable, "\x02" "07AC0" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eSat, "\x02" "07ACA" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eVCR1, "\x02" "07A0F" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eVCR2_DVR, "\x02" "07A13" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eVCR3, "\x02" "07AC8" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncInput, AVRInterface::eV_Aux, "\x02" "07A55" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncDC1OnOff, AVRInterface::eOn, "\x02" "07E73" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncDC1OnOff, AVRInterface::eOff, "\x02" "07E74" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncDC2OnOff, AVRInterface::eOn, "\x02" "07E3E" "\x03", 7 }, - { AVRSubsys::subZone1, AVRFunc::fncDC2OnOff, AVRInterface::eOff, "\x02" "07E3F" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolume, AVRInterface::eUp, "\x02" "07ADA" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolume, AVRInterface::eDown, "\x02" "07ADB" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncMute, AVRInterface::eOn, "\x02" "07EA0" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncMute, AVRInterface::eOff, "\x02" "07EA1" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::ePhono, "\x02" "07AD0" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eCD, "\x02" "07AD1" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eTuner, "\x02" "07AD2" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eCDR, "\x02" "07AD4" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eMD_Tape, "\x02" "07ACF" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eDVD, "\x02" "07ACD" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eDTV, "\x02" "07AD9" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eCable, "\x02" "07ACC" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eSat, "\x02" "07ACB" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eVCR1, "\x02" "07AD6" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eVCR2_DVR, "\x02" "07AD7" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eVCR3, "\x02" "07ACE" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncInput, AVRInterface::eV_Aux, "\x02" "07AD8" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncPower, AVRInterface::eOn, "\x02" "07EBA" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncPower, AVRInterface::eOff, "\x02" "07EBB" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeMemory, AVRInterface::eA, "\x02" "07E87" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeMemory, AVRInterface::eB, "\x02" "07E88" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeMemory, AVRInterface::eC, "\x02" "07E89" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeMemory, AVRInterface::eD, "\x02" "07E8A" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeMemory, AVRInterface::eE, "\x02" "07E8B" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeMemory, AVRInterface::eF, "\x02" "07E8C" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeRecall, AVRInterface::eA, "\x02" "07E8D" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeRecall, AVRInterface::eB, "\x02" "07E8E" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeRecall, AVRInterface::eC, "\x02" "07E8F" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeRecall, AVRInterface::eD, "\x02" "07E90" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeRecall, AVRInterface::eE, "\x02" "07E91" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncVolumeRecall, AVRInterface::eF, "\x02" "07E92" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncDC1OnOff, AVRInterface::eOn, "\x02" "07E71" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncDC1OnOff, AVRInterface::eOff, "\x02" "07E72" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncDC2OnOff, AVRInterface::eOn, "\x02" "07E3C" "\x03", 7 }, - { AVRSubsys::subZone2, AVRFunc::fncDC2OnOff, AVRInterface::eOff, "\x02" "07E3D" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncPower, AVRInterface::eOn, "\x02" "07AED" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncPower, AVRInterface::eStandby, "\x02" "07AEE" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncMute, AVRInterface::eOn, "\x02" "07E26" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncMute, AVRInterface::eOff, "\x02" "07E66" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolume, AVRInterface::eUp, "\x02" "07AFD" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolume, AVRInterface::eDown, "\x02" "07AFE" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::ePhono, "\x02" "07AF1" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eCD, "\x02" "07AF2" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eTuner, "\x02" "07AF3" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eCDR, "\x02" "07AF5" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eMD_Tape, "\x02" "07AF4" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eDVD, "\x02" "07AFC" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eDTV, "\x02" "07AF6" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eCable, "\x02" "07AF7" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eSat, "\x02" "07AF8" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eVCR1, "\x02" "07AF9" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eVCR2_DVR, "\x02" "07AFA" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eVCR3, "\x02" "07AFB" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncInput, AVRInterface::eV_Aux, "\x02" "07AF0" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeMemory, AVRInterface::eA, "\x02" "07E20" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeMemory, AVRInterface::eB, "\x02" "07E21" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeMemory, AVRInterface::eC, "\x02" "07E22" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeMemory, AVRInterface::eD, "\x02" "07E23" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeMemory, AVRInterface::eE, "\x02" "07E24" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeMemory, AVRInterface::eF, "\x02" "07E25" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeRecall, AVRInterface::eA, "\x02" "07E60" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeRecall, AVRInterface::eB, "\x02" "07E61" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeRecall, AVRInterface::eC, "\x02" "07E62" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeRecall, AVRInterface::eD, "\x02" "07E63" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeRecall, AVRInterface::eE, "\x02" "07E64" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncVolumeRecall, AVRInterface::eF, "\x02" "07E65" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncDC1OnOff, AVRInterface::eOn, "\x02" "07E83" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncDC1OnOff, AVRInterface::eOff, "\x02" "07E84" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncDC2OnOff, AVRInterface::eOn, "\x02" "07E85" "\x03", 7 }, - { AVRSubsys::subZone3, AVRFunc::fncDC2OnOff, AVRInterface::eOff, "\x02" "07E86" "\x03", 7 }, -}; - -bool AVRInterface::AVRCommand(AVRInterface::AVRSubsystem_T subsystem, - AVRInterface::AVRFunction_E function, - AVRArg_T arg, uint8_t variableData) { - bool found = false; - for (int i = 0; i < sizeof(MessageTable) / sizeof(MessageTable_T); i++) { - if (MessageTable[i].subsystem == subsystem && MessageTable[i].function == function and MessageTable[i].arg == arg) { - found = true; - const char *p = strchr(MessageTable[i].Message, 'x'); - if (p) { - char hexBuf[3] = ""; - char *bigBuf = (char *)malloc(MessageTable[i].MessageLen + 1); - if (bigBuf) { - sprintf_s(hexBuf, 3, "%0X", variableData); - memcpy(bigBuf, MessageTable[i].Message, MessageTable[i].MessageLen); - p = strchr(bigBuf, 'x'); - memcpy((void *)p, hexBuf, 2); - ProcessSerialQueue(bigBuf, MessageTable[i].MessageLen); - free(bigBuf); - } else { - (*ReportInformation)(mtInfo, "***** Memory allocation failed!"); - } - } else { - ProcessSerialQueue(MessageTable[i].Message, MessageTable[i].MessageLen); - } - break; - } - } - if (!found) { - char buf[LONGESTTEXT] = ""; - sprintf_s(buf, LONGESTTEXT, "AVRCommand(%d,%d,%d) is invalid.", subsystem, function, arg); - (*ReportInformation)(mtInfo, buf); - } - return true; -} - -void AVRInterface::ExportInformation(AVRInterface::AVRSubsystem_T subsystem, - AVRInterface::AVRFunction_E function, +void AVRInterface::ExportInformation(AVRSubsystem_T subsystem, + AVRFunction_T function, AVRArg_T arg) { char buf[LONGESTTEXT] = ""; typedef struct { @@ -1149,43 +676,44 @@ void AVRInterface::ExportInformation(AVRInterface::AVRSubsystem_T subsystem, { e0ms, "0 ms" }, }; - ReportInformation(mtInfo, ""); - ReportInformation(mtInfo, "AVR Command Line Control uses 3 numeric parameters:"); - ReportInformation(mtInfo, " 1) Subsystem Identifier for the subsystem control"); - ReportInformation(mtInfo, " 2) Function Identifier valid for the subsystem"); - ReportInformation(mtInfo, " 3) Value Identifier valid for the subsystem and function"); - ReportInformation(mtInfo, ""); - ReportInformation(mtInfo, " NOTE: Most commands are unavailable when the system is off."); - ReportInformation(mtInfo, " "); - ReportInformation(mtInfo, ""); + (*NotifyHost)(mtInfo, "", 0); + (*NotifyHost)(mtInfo, "AVR Command Line Control uses 3 numeric parameters:", 0); + (*NotifyHost)(mtInfo, " 1) Subsystem Identifier for the subsystem control", 0); + (*NotifyHost)(mtInfo, " 2) Function Identifier valid for the subsystem", 0); + (*NotifyHost)(mtInfo, " 3) Value Identifier valid for the subsystem and function", 0); + (*NotifyHost)(mtInfo, "", 0); + (*NotifyHost)(mtInfo, " NOTE: Most commands are unavailable when the system is off.", 0); + (*NotifyHost)(mtInfo, " ", 0); + (*NotifyHost)(mtInfo, "", 0); sprintf_s(buf, LONGESTTEXT, "%8d: %-21s | %3d: %-28s | %3d: %-22s | %-13s", 1, "Subsystem Identifier", 2, "Function Identifier", 3, "Value Identifier", "Stream" ); - ReportInformation(mtInfo, buf); + (*NotifyHost)(mtInfo, buf, (uint32_t)strlen(buf)); sprintf_s(buf, LONGESTTEXT, " %2s: %-21s | %3s: %-28s | %3s: %22s | %13s", "##", "#####################", "##", "############################", "##", "######################", "#############" ); - ReportInformation(mtInfo, buf); + (*NotifyHost)(mtInfo, buf, (uint32_t)strlen(buf)); AVRSubsystem_T refSub = subsystemCount; - AVRFunction_E refFnc = fncFunctionCount; + AVRFunction_T refFnc = fncFunctionCount; const char *pSubsystemText = NULL, *pFunctionText = NULL, *pValueText = NULL; - for (int i = 0; i < sizeof(MessageTable) / sizeof(MessageTable_T); i++) { - + uint16_t count = GetMessageTableSize(); + for (uint16_t i = 0; i < count; i++) { + MessageTable_T *p = GetMessageTableRecord(i); // Subsystem scan or filter // - if (subsystem != subsystemCount && subsystem != MessageTable[i].subsystem) { + if (subsystem != subsystemCount && subsystem != p->subsystem) { continue; } - if (function != fncFunctionCount && function != MessageTable[i].function) { + if (function != fncFunctionCount && function != p->function) { continue; } - if (arg != eARGCount && arg != MessageTable[i].arg) { + if (arg != eARGCount && arg != p->arg) { continue; } - if (refSub != MessageTable[i].subsystem) { - refSub = MessageTable[i].subsystem; + if (refSub != p->subsystem) { + refSub = p->subsystem; for (int j = 0; j < sizeof(subsysList) / sizeof(ValuePurpose_T); j++) { if (subsysList[j].value == refSub) { pSubsystemText = subsysList[j].helpText; @@ -1200,8 +728,8 @@ void AVRInterface::ExportInformation(AVRInterface::AVRSubsystem_T subsystem, // // function choices // - if (refFnc != MessageTable[i].function) { - refFnc = MessageTable[i].function; + if (refFnc != p->function) { + refFnc = p->function; for (int j = 0; j < sizeof(funcList) / sizeof(ValuePurpose_T); j++) { if (funcList[j].value == refFnc) { pFunctionText = funcList[j].helpText; @@ -1217,7 +745,7 @@ void AVRInterface::ExportInformation(AVRInterface::AVRSubsystem_T subsystem, // argument choices // for (int j = 0; j < sizeof(valueList) / sizeof(ValuePurpose_T); j++) { - if (valueList[j].value == MessageTable[i].arg) { + if (valueList[j].value == p->arg) { pValueText = valueList[j].helpText; break; } else { @@ -1227,10 +755,10 @@ void AVRInterface::ExportInformation(AVRInterface::AVRSubsystem_T subsystem, sprintf_s(buf, LONGESTTEXT, "%8d: %-21s | %3d: %-28s | %3d: %-22s | %s", refSub, pSubsystemText, refFnc, pFunctionText, - MessageTable[i].arg, pValueText, - MessageToText(MessageTable[i].Message, MessageTable[i].MessageLen) + p->arg, pValueText, + MessageToText(p->Message, p->MessageLen) ); - ReportInformation(mtInfo, buf); + (*NotifyHost)(mtInfo, buf, (uint32_t)strlen(buf)); } }; @@ -1271,115 +799,119 @@ uint8_t AVRInterface::VolumeDBtoAPIValue(float db) { /// 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 && ReportInformation) { +/// @param[in] offsetChanged indicates what index into the big buffer changed +/// +void AVRInterface::ReportAllStatus(uint8_t offsetChanged) { + const AVRDriver::AVR_Status_T * avStat = GetAVRStatusData(); + if (avStat->headerValid && AppNotify) { char buf[LONGESTTEXT]; - sprintf_s(buf, LONGESTTEXT, "Model ID: %c%c%c%c%c, ver: %c\n", avrStatus.header.type[0], avrStatus.header.type[1], - avrStatus.header.type[2], avrStatus.header.type[3], avrStatus.header.type[4], - avrStatus.header.version); - (*ReportInformation)(mtModelInfo, buf); + sprintf_s(buf, LONGESTTEXT, "Model ID: %c%c%c%c%c, ver: %c\n", avStat->header.type[0], avStat->header.type[1], + avStat->header.type[2], avStat->header.type[3], avStat->header.type[4], + avStat->header.version); + (*AppNotify)(mtModelInfo, buf, (uint32_t)strlen(buf)); - uint8_t *p = (uint8_t *)&avrStatus.config; - (*ReportInformation)(mtStreamStart, "---- AVR Status Report ----\n"); - PCMessage("Baud Rate", 1, &p); - PCMessage("Rx Buffer", 2, &p); - PCMessage("Cmd Timeout", 3, &p); - PCMessage("Handshake", 1, &p); - PCMessage("Busy", 1, &p, BusyToText); - PCMessage("Power", 1, &p, OffOnText); - if (avrStatus.configValid) { - PCMessage("Zone 1 Input", 1, &p, InputText); - PCMessage("6 ch", 1, &p, OffOnText); - PCMessage("Inp mode", 1, &p, InputModeText); - PCMessage("Mute", 1, &p, OffOnText); - PCMessage("Zone 2 Input", 1, &p, InputText); - PCMessage("Zone 2 Mute", 1, &p, OffOnText); - PCMessage("Volume", 2, &p, VolumeDB); - PCMessage("Zone 2 Volume", 2, &p, VolumeDB); - 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, 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, 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, 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, M20P0dbText); - PCMessage("LFE HP", 2, &p, M20P0dbText); - PCMessage("Audio Delay", 2, &p, ZeroTo160msText); - PCMessage("?????", 4, &p); - PCMessage("Inp Mode Set", 1, &p, AutoLastText); - PCMessage("Dimmer", 1, &p, M4To0Text); - PCMessage("OSD Msg", 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, 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, SwfrMainBothText); - PCMessage("6 ch center", 1, &p); - PCMessage("6 ch sub", 1, &p); - PCMessage("Main level", 1, &p); - PCMessage("Test Mode", 1, &p, OffDolbyDspText); - PCMessage("?????", 1, &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 Input", 1, &p, PlaybackToText); - PCMessage("Zone 3 Mute", 1, &p, OffOnText); - PCMessage("Zone 3 Volume", 2, &p, VolumeDB); - PCMessage("?????", 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, PRSBText); + uint8_t *p = (uint8_t *)&avStat->config; + (*AppNotify)(mtStreamStart, "---- AVR Status Report ----\n", 0); + int offset = 0; + offset += PCMessage("Baud Rate", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Rx Buffer", 2, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Cmd Timeout", 3, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Handshake", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Busy", 1, &p, BusyToText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Power", 1, &p, ZonePower, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + if (avStat->configValid) { + offset += PCMessage("Zone 1 Input", 1, &p, InputText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("6 ch", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Inp mode", 1, &p, InputModeText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Mute", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 2 Input", 1, &p, InputText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 2 Mute", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Volume", 2, &p, VolumeDB, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 2 Volume", 2, &p, VolumeDB, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Prog", 2, &p, ProgramName, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Effect", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("6.1/es status", 1, &p, OffMatrixDiscreteAutoText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("OSD", 1, &p, OSDFullShortOffText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Sleep", 1, &p, SleepTimerText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Tuner Pg", 1, &p, PresetLabelText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Tuner #", 1, &p, PresetNumberText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Night", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("?????", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Spkr A", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Spkr B", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Playback", 1, &p, PlaybackToText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Fs", 1, &p, FsToText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Ex/Es", 1, &p, OffMatrixDiscreteText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Thr Bypass", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Red DTS", 1, &p, ReleaseWaitText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Headphone", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Tuner Band", 1, &p, FMAMText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Tuner Tuned", 1, &p, NotTunedTunedText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("DC1 Control Out", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("?????", 2, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("DC1 Trig Ctrl", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("DTS 96/24", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("DC2 Trig Ctrl", 1, &p, WhichZoneText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("DC2 Trig Out", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Spkr B Set", 1, &p, Zone1Zone2Text, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 2 SP out", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Main R", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Main L", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Center", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Rear R", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Rear L", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Sur Bk R", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Sur Bk L", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Front R", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Front L", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Subwfr 1", 2, &p, PM10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("?????", 6, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("LFE SP", 2, &p, M20P0dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("LFE HP", 2, &p, M20P0dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Audio Delay", 2, &p, ZeroTo160msText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("?????", 4, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Inp Mode Set", 1, &p, AutoLastText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Dimmer", 1, &p, M4To0Text, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("OSD Msg", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("OSD Shift", 2, &p, M5toP5Text, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Gray Back", 1, &p, OffAutoText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Video Conv", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("D Range SP", 1, &p, MaxStdMinText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("D Range HP", 1, &p, MaxStdMinText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 2 Vol out", 1, &p, VarFixText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("?????", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); // "Zone 2 Mode: %s", Mode1Mode2Text ??? + offset += PCMessage("Memory Guard", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP set center", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP set main", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP set rear L/R", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP set rear ct", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP set front", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP set LFE/Bass", 1, &p, SwfrMainBothText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("6 ch center", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("6 ch sub", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Main level", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Test Mode", 1, &p, OffDolbyDspText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("?????", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch main L", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch main R", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch center", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch sl", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch sr", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch sbl", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch sbr", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch F L", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch F R", 2, &p, M10P10dbText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Lvl 6 Ch swfr", 2, &p, M20P0dbText , (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 3 Input", 1, &p, PlaybackToText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 3 Mute", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Zone 3 Volume", 2, &p, VolumeDB, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("?????", 1, &p, NULL, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("MultiCh Select", 1, &p, SixEightText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("MultiCh Surround", 1, &p, SurrMainText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP Set SW1", 1, &p, LrFrNoneText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("SP Set Crossover", 1, &p, CrossOverText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("Component OSD", 1, &p, OffOnText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); + offset += PCMessage("PB/SB Select", 1, &p, PRSBText, (offsetChanged == 0xFF || offsetChanged == offset) ? true : false); } } } diff --git a/AVR Working Controller/AVRInterface.h b/AVR Working Controller/AVRInterface.h index c238f67..5468f57 100644 --- a/AVR Working Controller/AVRInterface.h +++ b/AVR Working Controller/AVRInterface.h @@ -1,42 +1,19 @@ #pragma once #include +#include "AVRDriver.h" -class AVRInterface { +class AVRInterface : public AVRDriver { public: /// @brief /// @param SendMessage is the function this AVRInterface calls to send a message to the device /// - AVRInterface(bool (*SendMessage)(const uint8_t *buffer, uint16_t len)); + AVRInterface( + NotifyCallBack notifyCB, ///?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]_abcdefghijklmnopqrstuvwxyz" - /// @return true if the message was accepted for sending, false if it is too long or has invalid characters. - /// - bool AVRSendOSDMessage(const char *msg); + void ReportAllStatus(uint8_t offsetChanged = 0); /// ExportInformation /// @@ -321,8 +40,8 @@ public: /// @param[in] function : Power, Speaker, Volume, etc. /// @param[in] arg: on/off, etc. /// - void ExportInformation(AVRInterface::AVRSubsystem_T subsystem = subsystemCount, - AVRInterface::AVRFunction_E function = fncFunctionCount, + void ExportInformation(AVRSubsystem_T subsystem = subsystemCount, + AVRFunction_T function = fncFunctionCount, AVRArg_T arg = eARGCount); /// VolumeDBtoAPIValue @@ -333,219 +52,38 @@ public: /// uint8_t VolumeDBtoAPIValue(float db); + /// @brief permits snooping on what the driver intends to send to the AVR via RS-232 + /// + /// @param message + /// @param len + /// @return true + //bool HostSendPassthru(const uint8_t * message, uint32_t len); + + + const char *GetStateLabel(uint32_t st); private: - uint32_t sentAtTime_ms; + // Instance pointer used by the C-style NotifyCallBack trampoline. + // There is only one AVRInterface instance expected in this design. + static AVRInterface *s_instance; - AVRState_T state = stPoweringUp; - AVRState_T oldState = stMaxStates; - - AVRState_T GetState() { - return state; - } - - // 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' - uint8_t DT2; // * Receive Buffer '0' - uint8_t DT3; // * '1' - uint8_t DT4; // * Command Timeout '9' - uint8_t DT5; // * '0' - uint8_t DT6; // * '0' - uint8_t DT7; // * System '0':Ok, '1':Busy - uint8_t DT8; // * Power 0:Off, 1:On - uint8_t DT9; // Input 0: Phono, 1:CD, 2:Tuner, 3:CD-R, 4:MD-Tape, 5:DVD, 6:D-TV, 7:Cbl, 9:VCR1, A:VCR2 - uint8_t DT10; // 6ch input 0:Off, 1:On - uint8_t DT11; // Input Mode 0:AUTO, 2:DTS, 4:Analog, 5:Analog Only - uint8_t DT12; // Audio Mute 0:Off, 1:On - uint8_t DT13; // Zone2 Input 0: PHONO / 1: CD / 2: TUNER / 3: CD-R / 4: MD-TAPE / 5: DVD / 6: D-TV-LD / 7: CBL-SAT / 9: VCR1 / A: VCR2-DVR / C: V-AUX - uint8_t DT14; // Zone2 Mute 0: OFF / 1: ON - uint8_t DT15; // Master Volume Upper 4 bit - uint8_t DT16; // Master Volume Lower 4 bit - uint8_t DT17; // Zone2 Volume Upper 4 bit - uint8_t DT18; // Zone2 Volume Lower 4 bit - uint8_t DT19; // Program Upper 4 bit - uint8_t DT20; // Program Lower 4 bit - uint8_t DT21; // Effect 0: OFF / 1: ON - uint8_t DT22; // 6.1/ES key status 0: OFF / 1: MATRIX ON / 2: DISCRETE ON / 3: AUTO - uint8_t DT23; // OSD* 0: FULL / 1: SHORT / 2: OFF - uint8_t DT24; // Sleep 0: 120 / 2: 90 / 3: 60 / 4: 30 / 5: OFF - uint8_t DT25; // Tuner Page 0: Page A / 1: Page B / 2: Page C / 3: Page D / 4: PageE - uint8_t DT26; // Tuner No. 0: No.1 / 1: No.2 / 2: No.3 / 3: No.4 / 4: No.5 / 5: No.6 / 6: No.7 / 7: No.8 - uint8_t DT27; // Night mode 0: OFF / 1: ON - uint8_t DT28; // Care - uint8_t DT29; // Speaker relay A 0: OFF / 1: ON - uint8_t DT30; // Speaker relay B 0: OFF / 1: ON - uint8_t DT31; // Playback 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 ES Discrete - uint8_t DT32; // Fs 0: Analog / 1: 32kHz / 2: 44.1kHz / 3: 48kiHz / 4: 64kHz / 5: 88.2kHz / 6: 96kHz / 7: Unknown B: DTS 96/24 - uint8_t DT33; // EX/ES playback 0: OFF / 1: MATRIX ON / 2: DISCRETE ON - uint8_t DT34; // Thr / Bypass 0: Normal / 1: Bypass - uint8_t DT35; // RED dts 0: Release / 1: Wait - uint8_t DT36; // Head Phone 0: OFF / 1: ON - uint8_t DT37; // TUNER BAND 0: FM / 1: AM - uint8_t DT38; // TUNER TUNED 0: NOT TUNED / 1: TUNED - uint8_t DT39; // DC1 Control Out 0: LOW / 1: HIGH - - uint8_t DT40; // Don’t care - uint8_t DT41; // Don't Care - uint8_t DT42; // 0-2 DC1 TRG Ctrl. 0: Zone1 / 1: Zone2 / 2: Zone1&2 - uint8_t DT43; // 0/1 dts 96/24 0: OFF / 1: ON - uint8_t DT44; // 0-2 DC2 TRG Ctrl. 0: Zone1 / 1: Zone2 / 2: Zone1&2 - uint8_t DT45; // 0/1 DC2 Trigger 0: LOW / 1: HIGH - uint8_t DT46; // SP B set 0: Zone1 / 1: Zone2 - uint8_t DT47; // Zone 2 SP out 0: OFF / 1: ON - uint8_t DT48; // MAIN R Upper 4bit - uint8_t DT49; // Lower 4bit - uint8_t DT50; // MAIN L Upper 4bit - uint8_t DT51; // Lower 4bit - uint8_t DT52; // CENTER Upper 4bit - uint8_t DT53; // Lower 4bit - uint8_t DT54; // REAR R Upper 4bit - uint8_t DT55; // Lower 4bit - uint8_t DT56; // REAR L Upper 4bit - uint8_t DT57; // Lower 4bit - uint8_t DT58; // SUR BACK Upper 4bit - uint8_t DT59; // R Lower 4bit - uint8_t DT60; // SUR BACK Upper 4bit - uint8_t DT61; // L Lower 4bit - uint8_t DT62; // FRONT R Upper 4bit - uint8_t DT63; // Lower 4bit - uint8_t DT64; // FRONT L Upper 4bit - uint8_t DT65; // Lower 4bit - uint8_t DT66; // SWFR 1 Upper 4bit - uint8_t DT67; // Lower 4bit - uint8_t DT68; // Don't Care - uint8_t DT69; // Don't Care - uint8_t DT70; // Don't Care - uint8_t DT71; // Don't Care - uint8_t DT72; // Don't Care - uint8_t DT73; // Don't Care - uint8_t DT74; // LFE Lvl. SP Upper 4bit - uint8_t DT75; // Lower 4bit - uint8_t DT76; // LFE Lvl. HP Upper 4bit - uint8_t DT77; // Lower 4bit - uint8_t DT78; // Audio Delay Upper 4bit - uint8_t DT79; // Lower 4bit - - uint8_t DT80; // Don't Care - uint8_t DT81; // Don't Care - uint8_t DT82; // Don't Care - uint8_t DT83; // Don't Care - uint8_t DT84; // Input mode set 0: AUTO / 1: LAST - uint8_t DT85; // Dimmer 0: -4 / 1: -3 / 2: -2 / 3: -1 / 4: 0 - uint8_t DT86; // OSD Message - uint8_t DT87; // OSD shift Upper 4bit - uint8_t DT88; // Lower 4bit - uint8_t DT89; // Glay back 0: OFF / 1: AUTO - uint8_t DT90; // Video conversion 0: OFF / 1: ON - uint8_t DT91; // D. Range SP 0: MAX / 1: STD / 2: MIN - uint8_t DT92; // HP 0: MAX / 1: STD / 2: MIN - uint8_t DT93; // Zone 2 vol. Out - uint8_t DT94; // Don't Care - uint8_t DT95; // Memory guard 0: OFF / 1: ON - uint8_t DT96; // SP set Center 0: Large / 1: Small / 2: None - uint8_t DT97; // Main 0: Large / 1: Small - uint8_t DT98; // Rear L/R 0: Large / 1: Small / 2: None - uint8_t DT99; // Rear CT 0: Large / 1: Small / 2: None - uint8_t DT100; // Front 0: Yes / 1: None - uint8_t DT101; // LFE/BASS 0: SWFR / 1: Main / 2: Both - uint8_t DT102; // 6CH Center 0: Center / 1: Main - uint8_t DT103; // SWFR 0: SWFR / 1: Main - uint8_t DT104; // Main level 0: Normal / 1: -10dB - uint8_t DT105; // Test mode 0: OFF / 1: Dolby / 2: DTS - uint8_t DT106; // Don't Care - uint8_t DT107; // LVL 6CH MAIN L Upper 4bit - uint8_t DT108; // Lower 4bit - uint8_t DT109; // MAIN R Upper 4bit - uint8_t DT110; // Lower 4bit - uint8_t DT111; // CENTER Upper 4bit - uint8_t DT112; // Lower 4bit - uint8_t DT113; // SL Upper 4bit - uint8_t DT114; // Lower 4bit - uint8_t DT115; // SR Upper 4bit - uint8_t DT116; // Lower 4bit - uint8_t DT117; // SBL Upper 4bit - uint8_t DT118; // Lower 4bit - uint8_t DT119; // SBR Upper 4bit - uint8_t DT120; // Lower 4bit - uint8_t DT121; // FRONT L Upper 4bit - uint8_t DT122; // Lower 4bit - uint8_t DT123; // FRONT R Upper 4bit - uint8_t DT124; // Lower 4bit - uint8_t DT125; // SWFR Upper 4bit - uint8_t DT126; // Lower 4bit - uint8_t DT127; // 0 - C Z3 Input - uint8_t DT128; // 0/1 Z3 Mute - uint8_t DT129; // 0 - F Z3 Volume Upper 4bit - - uint8_t DT130; // 0 - F Lower 4bit - uint8_t DT131; // Don't Care - uint8_t DT132; // MULTI_CH SELECT 00:6CH / 01:8CH TUNER / 02: 8CH CD / 04: 8CH CD-R / 05: 8CH DVD / 06: DTV / 07: 8CH CBL/SAT / 09: 8CH VCR1 / 0A: VCR2/DVR / 0C: VAUX - uint8_t DT133; // MULTI_CH SURROUND to 00: Surround / 01: Main - uint8_t DT134; // SP SET SW1 00: L-R / 01: F-R / 02: NONE - uint8_t DT135; // SP SET CROSSOVER 00: 40Hz / 01: 60Hz / 02: 80Hz / 03: 90Hz / 04: 100Hz / 05: 110Hz / 06: 120Hz / 07: 160Hz / 08: 200Hz - uint8_t DT136; // COMPONENT OSD 00: OFF / 01: ON - uint8_t DT137; // PB/SB SELECT 00: PR / 01: SB - - uint8_t DT138[100]; // From here on is just buffer in case it sends more data - } AVR_Configuration_T; - - typedef struct { - uint8_t type[5]; // Model ID - uint8_t version; // A-Z - uint8_t length[2]; // 1 - 255 - } AVR_StatusHeader_T; - - typedef struct { - bool headerValid; - bool configValid; - AVR_StatusHeader_T header; - AVR_Configuration_T config; - - } AVR_Status_T; - - //AVR_StatusHeader_T avrStatusHeader; - //AVR_Configuration_T avrConfigData; - AVR_Status_T avrStatus; - bool commandResponseReceived; // a response to the last command was received - bool readyResponsReceived; // the special system ready response was received - int readyTries; - #define RETRY_INTERVAL_ms 500 - #define MAXTRIES 5 - - #define SERIALQUEUESIZE 5 - typedef struct { - uint8_t *messageToSend; - uint16_t len; - } SerialQueue_T; - - SerialQueue_T serialQueue[SERIALQUEUESIZE]; - int serialQueueCount = 0; - - bool bFirstTickInitialized; - 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 + // The application supplied notify callback -- invoked by this interface + // after the driver's notifications are processed by AVRInterface. + NotifyCallBack AppNotify; + // Trampoline used to set the AVRDriver::NotifyHost to a function + // that dispatches into the instance method ProcessReportResponse. + static bool NotifyTrampoline(AVRMessageType_T type, const void *message, uint32_t attrib); bool IsSanityCheckOK(); void MessageHandlerSanityCheck(); - // host provided method to send to the AVR - bool (*SendMethod)(const uint8_t *buffer, uint16_t bufferSize); // host provided method to update the user with a text message - void(*ReportInformation)(AVRMessageType_T type, const char * message); + //void(*ReportInformation)(AVRMessageType_T type, const char * message); - 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); + uint8_t PCMessage(const char *msg, uint8_t len, uint8_t **src, const char *(fncHelper)(uint8_t val) = NULL, bool highlight = false); + bool ProcessReportResponse(AVRMessageType_T type, const void * message, uint32_t attrib); void MessageReport(const char *prefix, const void *buf, size_t len = 0); const char *MessageToText(const char *msg, size_t len); - bool CheckTheChecksum(const uint8_t *szBuffer, uint32_t num); - uint16_t Hex2Dec(const uint8_t *p, int dig); - - void FreeMemory(); }; diff --git a/AVR Working Controller/ConsoleHandler.cpp b/AVR Working Controller/ConsoleHandler.cpp index 3f6615b..f26564f 100644 --- a/AVR Working Controller/ConsoleHandler.cpp +++ b/AVR Working Controller/ConsoleHandler.cpp @@ -1,4 +1,30 @@ +// Something for later +// +// #include +// #include +// +// void enable_ansi_escape_sequences(void) { +// HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); +// DWORD mode = 0; +// +// if (!GetConsoleMode(hOut, &mode)) { +// return; // handle error if needed +// } +// +// mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; +// +// SetConsoleMode(hOut, mode); +// } +// +// int main() { +// enable_ansi_escape_sequences(); +// +// printf("\x1b[32mGreen text\x1b[0m\n"); +// printf("\x1b[31mRed text\x1b[0m\n"); +// +// return 0; +// } #include "stdafx.h" #include @@ -17,6 +43,14 @@ static short consoleHeight = 0; static short scrollBot = 0; // set at init: consoleHeight - 1 static short scrollTop = 0; // set at init: consoleHeight - consoleScrollHeight - 1 +void Console_SetColor(WORD color) { + SetConsoleTextAttribute(hStdout, color); +} +void Console_RestoreColor() { + SetConsoleTextAttribute(hStdout, wOldColorAttrs); +} + + void Console_Init(short Left, short Top, short Width, short Height, short bottomScrollHeight) { hStdin = GetStdHandle(STD_INPUT_HANDLE); hStdout = GetStdHandle(STD_OUTPUT_HANDLE); @@ -24,6 +58,8 @@ void Console_Init(short Left, short Top, short Width, short Height, short bottom fprintf(stderr, "Error: Unable to get console buffer info. Code: %lu\n", GetLastError()); exit(1); } + wOldColorAttrs = csbi.wAttributes; + consoleWidth = Width; consoleHeight = Height; @@ -31,7 +67,7 @@ void Console_Init(short Left, short Top, short Width, short Height, short bottom scrollTop = consoleHeight - bottomScrollHeight - 1; // Desired size (width x height) - COORD newSize; + COORD newSize = { 0, 0 }; newSize.X = consoleWidth; // columns newSize.Y = consoleHeight; // rows @@ -42,7 +78,7 @@ void Console_Init(short Left, short Top, short Width, short Height, short bottom } // Step 3: Set final window size to match buffer - SMALL_RECT newWindow; + SMALL_RECT newWindow = { 0 }; newWindow.Left = 0; newWindow.Top = 0; newWindow.Right = newSize.X - 1; @@ -56,8 +92,6 @@ void Console_Init(short Left, short Top, short Width, short Height, short bottom Console_SetWindowPosition(Left, Top); - wOldColorAttrs = csbi.wAttributes; - //SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_INTENSITY); } void Console_Close() { diff --git a/AVR Working Controller/ConsoleHandler.h b/AVR Working Controller/ConsoleHandler.h index 808906a..09c97dd 100644 --- a/AVR Working Controller/ConsoleHandler.h +++ b/AVR Working Controller/ConsoleHandler.h @@ -6,6 +6,11 @@ void Console_Cls(); void Console_SetWindowPosition(int x, int y); bool Console_SetCursorVisibility(bool visible); void Console_SetCursor(short x, short y); +// +// FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_BLUE, FOREGROUND_INTENSITY +// BACKGROUND_RED, BACKGROUND_GREEN, BACKGROUND_BLUE, BACKGROUND_INTENSITY +void Console_SetColor(WORD color); +void Console_RestoreColor(); void Console_Write(const char *text); void Console_WriteAt(short x, short y, const char *text); void Console_ScrollBottomRegion(); diff --git a/AVR Working Controller/SerialPort/SerialPort.cpp b/AVR Working Controller/SerialPort/SerialPort.cpp index c968efd..e3bd909 100644 --- a/AVR Working Controller/SerialPort/SerialPort.cpp +++ b/AVR Working Controller/SerialPort/SerialPort.cpp @@ -37,7 +37,7 @@ bool CSerialPort::Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE Close(); m_PortHandle = CreateFile(PortName, DesiredAccess, 0, NULL, OPEN_EXISTING, 0, 0); if (m_PortHandle != INVALID_HANDLE_VALUE) { - DCB dcb; + DCB dcb = { 0 }; CString s; dcb.DCBlength = sizeof(dcb); GetCommState(m_PortHandle, &dcb); @@ -66,7 +66,7 @@ bool CSerialPort::Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE SetCommState(m_PortHandle, &dcb); - COMMTIMEOUTS touts; + COMMTIMEOUTS touts = { 0 };; touts.ReadIntervalTimeout = UINT32_MAX; // This, plus the zero timeouts causes immediate return touts.ReadTotalTimeoutMultiplier = 0; touts.ReadTotalTimeoutConstant = 0;