diff --git a/AVR Working Controller/AVR.cpp b/AVR Working Controller/AVR.cpp index 72b9bb9..fce84fd 100644 --- a/AVR Working Controller/AVR.cpp +++ b/AVR Working Controller/AVR.cpp @@ -210,6 +210,8 @@ typedef enum { constexpr auto MAXTEXTLEN = 512; char progname[MAXTEXTLEN]; +char ininame[MAXTEXTLEN] = ""; + int AttachToSerialPort(); int DetachSerialPort(); @@ -261,7 +263,9 @@ unsigned long Hex2Dec(uint8_t *p, int dig); //void ShowAllStatusInfo(); void GetAndSendCustomMessage(); +void GetAndSendExtendedMessage(); void GetAndSendOSDMessage(); +bool SendExtendedMessage(char *buf); void EmitRuntimeHelp(); @@ -383,7 +387,8 @@ const UserCmd_T UserCommands[] = { //{ 'J', "Dual Mono - Main", {"\x02" "07E93" "\x03", 7} }, //{ 'K', "Dual Mono - Sub", {"\x02" "07E94" "\x03", 7} }, //{ 'L', "Dual Mono - All", {"\x02" "07E95" "\x03", 7} }, - { ':', "Custom Message" }, + { ':', "Send Command Message" }, + { '=', "Send Extended Message" }, { '/', "Show All" }, { '?', "Help on runtime commands" }, { 'S', "Set RTS" }, @@ -413,6 +418,9 @@ void ProcessKeyboard(void) { case ':': GetAndSendCustomMessage(); break; + case '=': + GetAndSendExtendedMessage(); + break; case '?': EmitRuntimeHelp(); break; @@ -557,6 +565,35 @@ void GetAndSendCustomMessage() { } } +bool SendExtendedMessage(char * buf) { + HexUppercase(buf); // Gets nulled if there are non-Hex + if (strlen(buf)) { + char msg[75]; // Hope it is large enough + const char * prefix = "\x14" "20"; + unsigned len = (unsigned)strlen(buf); + sprintf_s(msg, 70, "%s%02X%s", prefix, len, buf); + char *p = &msg[1]; + uint8_t checksum = 0; + do { + checksum += *p++; + } 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)); + return true; + } + return false; +} + +void GetAndSendExtendedMessage() { + char buf[60]; + Console_ScrollBottomRegion(); + Console_ScrollBottomRegion(); + Console_WriteAt(0, -2, "Enter DT0...DTX Hex string to send: "); + gets_s(buf, sizeof(buf) - 1); + SendExtendedMessage(buf); +} + void GetProgName(char *name) { char *p = strrchr(name, '\\'); @@ -570,6 +607,8 @@ void GetProgName(char *name) { if (p && 0 == stricmp(p, ".exe")) { *p = '\0'; } + strcpy_s(ininame, MAXTEXTLEN, progname); + strcat_s(ininame, MAXTEXTLEN, ".ini"); } @@ -602,35 +641,88 @@ void InformationUpdate(AVRInterface::AVRMessageType_T type, const char *msg) { } void EmitCommandLineHelp() { - printf("%s [Options] by Smartware Computing\n", progname); + const char * by = "by Smartware Computing"; + printf("%s [Options] %80s\n", progname, by); printf("\n"); - printf(" This program can control a Yamaha AVR RX-2400 receiver via the RS-232 port.\n"); - printf(" It may work for other similar models, and the API docs used to build this\n"); - printf(" showed commands not in the RX-2400, but they were implemented herein.\n"); + printf(" This program can control a Yamaha AVR RX-V2400 receiver via the RS-232 port.\n"); + printf(" It may work for other similar models.\n"); printf("\n"); - printf(" Options:\n"); - printf(" -SerialPort=X[,yyyy] Set to Com port X to baud rate yyyy.\n"); - printf(" Defaults baud is %d\n", avrBaud); - printf(" -Command=S,F,O[,V] Execute a command and exit (based on the numeric values):\n"); - printf(" S - Subsystem,\n"); - printf(" F - Function,\n"); - printf(" O - Operation,\n"); - printf(" V - Value used by only certain command.\n"); - printf(" Use the -ExportInfo command to see the Command List.\n"); - printf(" NOTE: Program will auto-exit after performing the command,\n"); - printf(" or after 5 seconds without obvious success.\n"); - printf(" -Verbose Shows progress during -Command operation.\n"); - printf(" NOTE: It is always verbose in interactive mode.\n"); - printf(" -ExportInfo Export AVR Control Parameters and exit.\n"); + printf(" This software, and/or material is the property of Smartware Computing. All use,\n"); + printf(" disclosure, and/or reproduction not specifically authorized by Smartware\n"); + printf(" Computing is prohibited. This program has no warranty or declaration of fitness\n"); + printf(" for your use, and no claim that it will function as intended. While the author is\n"); + printf(" using this regularly with an RX-V2400 receiver, it was developed using the full\n"); + printf(" capability expressed in the Yamaha RS232C Standard document, even though not all\n"); + printf(" features have been tested and NOT ALL AVRs support all commands.\n"); printf("\n"); - printf(" Example: avr -SerialPort=2 -Command=0,0,0 (Turn Main Power On)\n"); + printf(" There is no claim that it cannot damage your AVR, and you are accepting the risk!\n"); + printf("\n"); + printf(" Reference Documents:\n"); + printf(" + Yamaha RX-V2400 RS232C Standard - with decoding of most parameters.\n"); + printf(" + Yamaha RX-V2400 RS232C Extended - raw hex streams are supported.\n"); + printf("\n"); + printf(" This program is copyright (c) 2025 by Smartware Computing, all rights reserved.\n"); + printf("\n"); + printf(" Author David Smart, Smartware Computing\n"); + + printf("\n"); + printf("Options:\n"); + printf("\n"); + printf(" -SerialPort=X[,yyyy] Set to Com 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"); + printf("\n"); + printf(" -Command=S,F,O[,V] Execute command and exit (based on the numeric values):\n"); + printf(" S - Subsystem,\n"); + printf(" F - Function,\n"); + printf(" O - Operation,\n"); + printf(" V - Value used by only certain commands. This value is\n"); + printf(" entered as a decimal value (like the S,F, and O).\n"); + printf(" Use the -ExportInfo command to see the Command List.\n"); + printf(" NOTE: Program will auto-exit after performing the command,\n"); + printf(" or after about 5 seconds without obvious success.\n"); + printf("\n"); + printf(" -Extended=xxxxxxxx... Send Extended Command defined by ASCII hex sequence of DT0...DTx.\n"); + printf(" The length and checksum will be computed in the overall message.\n"); + printf(" [DC4][SW][KIND][L0][L1][DT0][DT1]...[DTx][SUM0][SUM1][ETX]\n"); + printf("\n"); + printf(" -Verbose Shows progress during -Command operation.\n"); + printf(" NOTE: %s is always verbose in interactive mode.\n", progname); + printf("\n"); + printf(" -ExportInfo[=S[,F[,O]]] Export AVR Control Parameters and exit, optionally \n"); + printf(" filtered to a subsystem, function, and operation.\n"); + printf(" NOTE: The unfiltered list is quite long.\n"); + printf("\n"); + printf("Handy Commands: Here's a few commands, made 'simpler' to access.\n"); + printf("\n"); + printf(" -Power=On|Off Control Main Power - On or Off\n"); + printf(" -Zone1Volume=+xx.y Set the zone 1 volume db level in the range -80.0 to +16.5.\n"); + printf(" -Zone2Volume=+xx.y Set the zone 2 volume db level in the range -80.0 to +16.5.\n"); + printf(" -Zone3Volume=+xx.y Set the zone 2 volume db level in the range -80.0 to +16.5.\n"); + printf(" CAUTION: Take care that you don't blow your speakers/ears!\n"); + printf(" -Mute=On|Off Mute on or Mute off\n"); + printf("\n"); + printf("ini File:\n"); + printf("\n"); + printf(" %s.ini, if it exists in the same folder as the program, will be read before any command\n", progname); + printf(" line parameters are processed. Supported items: \n"); + printf(" + Either form of the SerialPort command.\n"); + printf(" + Anything else is silently ignored.\n"); + printf("\n"); + printf("Examples:\n"); + printf("\n"); + printf(" > avr -ExportInfo=1,0 (See the options for Main Power)\n"); + printf(" > avr -SerialPort=2 -Command=1,0,0 (Turn Main Power On)\n"); + printf("\n"); + printf("Exit Codes:\n"); + printf("\n"); + printf(" 0 = Normal exit\n"); + printf(" 1 = Illegal Option or unrecognized command\n"); + printf(" 2 = Program Internal Error - Data table failed santity check.\n"); + printf(" 3 = External Quit (e.g. Windows command to close).\n"); + printf(" 4 = Something very abnormal happened to cause exit.\n"); printf("\n"); - printf(" Exit Codes:\n"); - printf(" 0 = Normal exit\n"); - printf(" 1 = Illegal Option or unrecognized command\n"); - printf(" 2 = Program Internal Error - Table data failed santity check.\n"); - printf(" 3 = External Quit (e.g. Windows command to close).\n"); - printf(" 4 = Something very abnormal happened to cause exit.\n"); if (avrOnPort == COM_NO_PORT) { EnumerateComPorts(); } @@ -647,6 +739,24 @@ DWORD AppTime() { return timeGetTime() - startTime; } +void ReadIniFile() { + char buf[MAXTEXTLEN] = ""; + FILE *fp = fopen(ininame, "r"); + int param1, param2; + + if (fp) { + while (!feof(fp)) { + fgets(buf, sizeof(buf) - 1, fp); + if (1 == sscanf_s(buf, "-SerialPort=%d", ¶m1)) { + avrOnPort = param1; + } else if (2 == sscanf_s(buf, "-SerialPort=%d,%d", ¶m1, ¶m2)) { + avrOnPort = param1; + avrBaud = param2; + } + } + } +} + /******************************************************/ /* m a i n ( ) */ /******************************************************/ @@ -672,6 +782,9 @@ int __cdecl main(int argc, char *argv[]) { short consoleLeft = 15; short consoleTop = 15; int CommandToExecute[4] = { -1, -1, -1, -1 }; + float db; + int parseCount = 0; + char *pExtendedMessage = NULL; // MessageHandlerSanityCheck(); // If the table is bad, we exit here GetProgName(argv[0]); @@ -680,6 +793,8 @@ int __cdecl main(int argc, char *argv[]) { avr = new AVRInterface(SerialSend); avr->RegisterInformationCallback(InformationUpdate); + ReadIniFile(); + for (int i = 1; i < argc; i++) { int param1, param2; if (1 == sscanf_s(argv[i], "-SerialPort=%d", ¶m1)) { @@ -691,6 +806,8 @@ int __cdecl main(int argc, char *argv[]) { // After the port is open, execute this and exit } else if (4 == sscanf_s(argv[i], "-Command=%d,%d,%d,%d", &CommandToExecute[0], &CommandToExecute[1], &CommandToExecute[2], &CommandToExecute[3])) { // After the port is open, execute this and exit + } else if (0 == strncmp(argv[i], "-Extended=", 10)) { + pExtendedMessage = argv[i] + 10; } else if (0 == strcmp(argv[i], "-Verbose")) { verboseMode = true; } else if (0 == strcmp(argv[i], "-ExportInfo")) { @@ -699,6 +816,74 @@ int __cdecl main(int argc, char *argv[]) { avr->ExportInformation(); verboseMode = saveVerbose; exit(EXIT_OK); + } else if (1 <= (parseCount = sscanf_s(argv[i], "-ExportInfo=%d,%d,%d", &CommandToExecute[0], &CommandToExecute[1], &CommandToExecute[2]))) { + // + // // If they didn't provide all three, set the others to default (wildcard) + // + switch (parseCount) { + case 1: + CommandToExecute[1] = AVRInterface::AVRFunction_E::fncFunctionCount; + // break; // fall thru on purpose + case 2: + CommandToExecute[2] = AVRInterface::AVRArg_T::eARGCount; + // break; // fall thru on purpose + default: + // nothing to do + break; + } + bool saveVerbose = verboseMode; + verboseMode = true; + avr->ExportInformation((AVRInterface::AVRSubsystem_T)CommandToExecute[0], + (AVRInterface::AVRFunction_E)CommandToExecute[1], + (AVRInterface::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; + } else if (0 == strcmp(argv[i], "-Power=Off")) { + CommandToExecute[0] = AVRInterface::subMain; + CommandToExecute[1] = AVRInterface::fncPower; + CommandToExecute[2] = AVRInterface::eOff; + } else if (0 == strcmp(argv[i], "-Mute=On")) { + CommandToExecute[0] = AVRInterface::subMain; + CommandToExecute[1] = AVRInterface::fncMute; + CommandToExecute[2] = AVRInterface::eOn; + } else if (0 == strcmp(argv[i], "-Mute=Off")) { + CommandToExecute[0] = AVRInterface::subMain; + CommandToExecute[1] = AVRInterface::fncMute; + CommandToExecute[2] = AVRInterface::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[3] = avr->VolumeDBtoAPIValue(db); + } else { + printf("***** Volume %+4.1f not in the range '-80.0 <= value <= 16.5' *****\n", db); + exit(EXIT_IllegalOption); + } + } 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[3] = avr->VolumeDBtoAPIValue(db); + } else { + printf("***** Volume %+4.1f not in the range '-80.0 <= value <= 16.5' *****\n", db); + exit(EXIT_IllegalOption); + } + } 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[3] = avr->VolumeDBtoAPIValue(db); + } else { + printf("***** Volume %+4.1f not in the range '-80.0 <= value <= 16.5' *****\n", db); + exit(EXIT_IllegalOption); + } } else { printf("***** Unrecognized command '%s' *****\n", argv[i]); EmitCommandLineHelp(); @@ -711,7 +896,7 @@ int __cdecl main(int argc, char *argv[]) { } if (AttachToSerialPort()) { - if (CommandToExecute[0] != -1 && CommandToExecute[1] != -1 && CommandToExecute[2] != -1) { + if (pExtendedMessage || (CommandToExecute[0] != -1 && CommandToExecute[1] != -1 && CommandToExecute[2] != -1)) { DWORD refTime = AppTime(); DWORD nowTime = AppTime(); DWORD elapsedTime = nowTime - refTime; @@ -726,11 +911,16 @@ int __cdecl main(int argc, char *argv[]) { nowTime = AppTime(); elapsedTime = nowTime - refTime; } while ((elapsedTime < 5000) && (state != AVRInterface::stReady)); - + if (elapsedTime < 5000) { - avr->AVRCommand((AVRInterface::AVRSubsystem_T)CommandToExecute[0], - (AVRInterface::AVRFunction_E)CommandToExecute[1], - (AVRInterface::AVRArg_T)CommandToExecute[2]); + if (pExtendedMessage) { + SendExtendedMessage(pExtendedMessage); + } else { + avr->AVRCommand((AVRInterface::AVRSubsystem_T)CommandToExecute[0], + (AVRInterface::AVRFunction_E)CommandToExecute[1], + (AVRInterface::AVRArg_T)CommandToExecute[2], + (uint8_t)CommandToExecute[3]); + } refTime = nowTime = AppTime(); do { Sleep(10); // @TODO how long to wait should not be based on lucky timing @@ -741,8 +931,6 @@ int __cdecl main(int argc, char *argv[]) { } state = avr->Tick(nowTime); } while (((nowTime - refTime) < 5000) && (state != AVRInterface::stReady)); - } else { - // printf("%u\n", elapsedTime); } DetachSerialPort(); exit(EXIT_OK); @@ -755,7 +943,7 @@ int __cdecl main(int argc, char *argv[]) { printf("WARN: Cannot install Console Control Handler\n"); } - printf("AVR - a command shell utility for a Yamaha RX-2400 AVR by D.Smart "); + printf("AVR - a command shell utility for a Yamaha RX-V2400 AVR by D.Smart "); printf("[COM%i at %i baud]", avrOnPort, avrBaud); Console_WriteAt(0, consoleHeight - consoleScrollHeight -1, "----------------------------------------"); diff --git a/AVR Working Controller/AVR.vcxproj b/AVR Working Controller/AVR.vcxproj index bf2740a..8a72ada 100644 --- a/AVR Working Controller/AVR.vcxproj +++ b/AVR Working Controller/AVR.vcxproj @@ -50,7 +50,7 @@ false v143 true - Unicode + MultiByte @@ -112,12 +112,14 @@ - Level3 + Level4 true true true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + MultiThreaded + Size Console diff --git a/AVR Working Controller/AVRCommandDecoder.cpp b/AVR Working Controller/AVRCommandDecoder.cpp index bdb332a..834c9e2 100644 --- a/AVR Working Controller/AVRCommandDecoder.cpp +++ b/AVR Working Controller/AVRCommandDecoder.cpp @@ -523,7 +523,7 @@ const char *VolumeDB(uint8_t val) { b = -99.5f; //} float db = m * val + b; - sprintf_s(buf, sizeof(buf), "%+3.1f db", db); + sprintf_s(buf, sizeof(buf), "%+4.1f db", db); return buf; } @@ -537,7 +537,7 @@ const char *PM10dbText(uint8_t val) { m = 0.5f; b = -10.0f; float db = m * (val - 0x14) + b; - sprintf_s(buf, sizeof(buf), "%+3.1f db", db); + sprintf_s(buf, sizeof(buf), "%+4.1f db", db); } return buf; } @@ -552,7 +552,7 @@ const char *M20P0dbText(uint8_t val) { m = 0.5f; b = -20.0f; float db = m * (val)+b; - sprintf_s(buf, sizeof(buf), "%+3.1f db", db); + sprintf_s(buf, sizeof(buf), "%+4.1f db", db); } return buf; } @@ -567,7 +567,7 @@ const char *M10P10dbText(uint8_t val) { m = 0.5f; b = -10.0f; float db = m * (val - 0x14) + b; - sprintf_s(buf, sizeof(buf), "%+3.1f db", db); + sprintf_s(buf, sizeof(buf), "%+4.1f db", db); } return buf; } @@ -644,7 +644,7 @@ const char *ZeroTo30msText(uint8_t val) { m = 0.5f; b = 0; float delay = m * (val + b); - sprintf_s(buf, sizeof(buf), "%+3.1f ms", delay); + sprintf_s(buf, sizeof(buf), "%+4.1f ms", delay); } return buf; } diff --git a/AVR Working Controller/AVRInterface.cpp b/AVR Working Controller/AVRInterface.cpp index 57f32f2..b5c975a 100644 --- a/AVR Working Controller/AVRInterface.cpp +++ b/AVR Working Controller/AVRInterface.cpp @@ -1,9 +1,7 @@ // +// The AVR Interface object and interaction methods // -// -#ifdef _DEBUG #include -#endif #include #include #include @@ -480,6 +478,7 @@ bool AVRInterface::ProcessSerialQueue(const void *msg, uint16_t len) { } retVal = true; } + state = stAwaitingResponse; } return retVal; } @@ -950,7 +949,9 @@ bool AVRInterface::AVRCommand(AVRInterface::AVRSubsystem_T subsystem, return true; } -void AVRInterface::ExportInformation() { +void AVRInterface::ExportInformation(AVRInterface::AVRSubsystem_T subsystem, + AVRInterface::AVRFunction_E function, + AVRArg_T arg) { char buf[LONGESTTEXT] = ""; typedef struct { uint16_t value; @@ -1127,6 +1128,12 @@ void AVRInterface::ExportInformation() { { eZoneXVolDB, "Zone X Volume" }, { eZoneXInputName, "Zone X Input Name" }, + { eMasterVol, "Master Volume" }, + { eZone2Vol, "Zone 2 Volume" }, + { eMainLRBal, "Left-Right Balance" }, + { eMainLevel, "Main Level" }, + { eZone3Vol, "Zone 3 Volume" }, + { eMainLevelR, "Main Level R" }, { eMainLevelL, "Main Level L" }, { eCenterLevel, "Center Level" }, @@ -1160,10 +1167,23 @@ void AVRInterface::ExportInformation() { ); ReportInformation(mtInfo, buf); - AVRSubsystem_T refSub = subSubsystemCount; + AVRSubsystem_T refSub = subsystemCount; AVRFunction_E refFnc = fncFunctionCount; const char *pSubsystemText = NULL, *pFunctionText = NULL, *pValueText = NULL; for (int i = 0; i < sizeof(MessageTable) / sizeof(MessageTable_T); i++) { + + // Subsystem scan or filter + // + if (subsystem != subsystemCount && subsystem != MessageTable[i].subsystem) { + continue; + } + if (function != fncFunctionCount && function != MessageTable[i].function) { + continue; + } + if (arg != eARGCount && arg != MessageTable[i].arg) { + continue; + } + if (refSub != MessageTable[i].subsystem) { refSub = MessageTable[i].subsystem; for (int j = 0; j < sizeof(subsysList) / sizeof(ValuePurpose_T); j++) { @@ -1177,6 +1197,9 @@ void AVRInterface::ExportInformation() { } else { pSubsystemText = ""; } + // + // function choices + // if (refFnc != MessageTable[i].function) { refFnc = MessageTable[i].function; for (int j = 0; j < sizeof(funcList) / sizeof(ValuePurpose_T); j++) { @@ -1190,7 +1213,9 @@ void AVRInterface::ExportInformation() { } else { pFunctionText = ""; } - // @TODO Probably all the enum values must be merged into one big enum list for this to work. + // + // argument choices + // for (int j = 0; j < sizeof(valueList) / sizeof(ValuePurpose_T); j++) { if (valueList[j].value == MessageTable[i].arg) { pValueText = valueList[j].helpText; @@ -1224,6 +1249,23 @@ const char *AVRInterface::MessageToText(const char *p, size_t len) { return privateBuffer; } + +// +// Single Linear according to the on-screen display of Volume +// db = 0.5 x - 99.5 +// therefore: +// db + 99.5 = 0.5 x +// 0.5 x == db + 99.5 +// x = 2 * (db + 99.5) +// +uint8_t AVRInterface::VolumeDBtoAPIValue(float db) { + if (db >= -80.0f && db <= +16.5f) { + return (uint8_t)(2 * (db + 99.5)); + } else { + return (0); // mute + } +} + /// ReportAllStatus /// /// This emits (via a callback) all the status, in DT0 to DT137 order. @@ -1246,14 +1288,14 @@ void AVRInterface::ReportAllStatus() { PCMessage("Busy", 1, &p, BusyToText); PCMessage("Power", 1, &p, OffOnText); if (avrStatus.configValid) { - PCMessage("Input", 1, &p, InputText); + 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", 1, &p, InputText); - PCMessage("Mute 2", 1, &p, OffOnText); + PCMessage("Zone 2 Input", 1, &p, InputText); + PCMessage("Zone 2 Mute", 1, &p, OffOnText); PCMessage("Volume", 2, &p, VolumeDB); - PCMessage("Volume 2", 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); @@ -1328,9 +1370,9 @@ void AVRInterface::ReportAllStatus() { PCMessage("Lvl 6 Ch F L", 2, &p, M10P10dbText); PCMessage("Lvl 6 Ch F R", 2, &p, M10P10dbText); PCMessage("Lvl 6 Ch swfr", 2, &p, M20P0dbText ); - PCMessage("Zone 3 Inp", 1, &p, PlaybackToText); + PCMessage("Zone 3 Input", 1, &p, PlaybackToText); PCMessage("Zone 3 Mute", 1, &p, OffOnText); - PCMessage("Zone 3 Vol", 2, &p, VolumeDB); + PCMessage("Zone 3 Volume", 2, &p, VolumeDB); PCMessage("?????", 1, &p); PCMessage("MultiCh Select", 1, &p, SixEightText); PCMessage("MultiCh Surround", 1, &p, SurrMainText); diff --git a/AVR Working Controller/AVRInterface.h b/AVR Working Controller/AVRInterface.h index 13febac..c238f67 100644 --- a/AVR Working Controller/AVRInterface.h +++ b/AVR Working Controller/AVRInterface.h @@ -54,7 +54,7 @@ public: subZone1, subZone2, subZone3, - subSubsystemCount + subsystemCount } AVRSubsystem_T; typedef enum { @@ -249,7 +249,8 @@ public: /// @param[in] function : Power, Speaker, Volume, etc. /// @param[in] arg: on/off, etc. /// @param[in] variableData is for those functions where it needs to integrate variable value, such as setting the volume directly - /// @return + /// @return true if accepted + /// bool AVRCommand(AVRSubsystem_T subsystem, AVRFunction_E function, AVRArg_T arg, @@ -316,7 +317,22 @@ public: /// /// @brief Export all the numeric data to support a command line control option /// - void ExportInformation(); + /// @param[in] subsystem: Main | Zone 1 | Zone 2 | Zone 3 + /// @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, + AVRArg_T arg = eARGCount); + + /// VolumeDBtoAPIValue + /// + /// @brief Convert a floating point value to the internal API db units for volume + /// @param db in the range of -80.0 to +16.5 db + /// @return scaled to internal volume units + /// + uint8_t VolumeDBtoAPIValue(float db); + private: uint32_t sentAtTime_ms; diff --git a/AVR Working Controller/SerialPort/SerialPort.cpp b/AVR Working Controller/SerialPort/SerialPort.cpp index c790ab4..c968efd 100644 --- a/AVR Working Controller/SerialPort/SerialPort.cpp +++ b/AVR Working Controller/SerialPort/SerialPort.cpp @@ -17,7 +17,7 @@ #ifdef _DEBUG #undef THIS_FILE -static char THIS_FILE[]=__FILE__; +static char THIS_FILE[] = __FILE__; #define new DEBUG_NEW #endif @@ -25,23 +25,18 @@ static char THIS_FILE[]=__FILE__; // Construction/Destruction ////////////////////////////////////////////////////////////////////// -CSerialPort::CSerialPort() -: m_PortHandle(INVALID_HANDLE_VALUE) -{ +CSerialPort::CSerialPort() : m_PortHandle(INVALID_HANDLE_VALUE) { } -CSerialPort::~CSerialPort() -{ +CSerialPort::~CSerialPort() { Close(); } -BOOL CSerialPort::Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE Parity, BYTE StopBits, uint32_t DesiredAccess) -{ +bool CSerialPort::Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE Parity, BYTE StopBits, uint32_t DesiredAccess) { Close(); m_PortHandle = CreateFile(PortName, DesiredAccess, 0, NULL, OPEN_EXISTING, 0, 0); - if (m_PortHandle != INVALID_HANDLE_VALUE) - { + if (m_PortHandle != INVALID_HANDLE_VALUE) { DCB dcb; CString s; dcb.DCBlength = sizeof(dcb); @@ -67,7 +62,7 @@ BOOL CSerialPort::Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE dcb.fInX = 0; dcb.fOutX = 0; dcb.fDtrControl = DTR_CONTROL_DISABLE; //DTR and RTS 0 - dcb.fRtsControl = RTS_CONTROL_DISABLE; + dcb.fRtsControl = RTS_CONTROL_DISABLE; SetCommState(m_PortHandle, &dcb); @@ -78,186 +73,116 @@ BOOL CSerialPort::Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE touts.WriteTotalTimeoutConstant = 1; touts.WriteTotalTimeoutMultiplier = 0; SetCommTimeouts(m_PortHandle, &touts); - + //SetCommMask (m_PortHandle, EV_CTS | EV_DSR | EV_RING | EV_RLSD); PurgeComm(m_PortHandle, PURGE_TXCLEAR | PURGE_RXCLEAR); - return TRUE; - } - else - { - printf("Open COM Error: %i\n", GetLastError()); - return FALSE; // Use GetLastError() to know the reason + return true; + } else { + return false; // Use GetLastError() to know the reason } } -void CSerialPort::Close() -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +void CSerialPort::Close() { + if (m_PortHandle != INVALID_HANDLE_VALUE) { CloseHandle(m_PortHandle); m_PortHandle = INVALID_HANDLE_VALUE; } } -BOOL CSerialPort::IsOpen() -{ +bool CSerialPort::IsOpen() { return (m_PortHandle != INVALID_HANDLE_VALUE); } -uint32_t CSerialPort::Read(LPVOID Buffer, uint32_t BufferSize) -{ +uint32_t CSerialPort::Read(LPVOID Buffer, uint32_t BufferSize) { DWORD Res(0); - if (m_PortHandle != INVALID_HANDLE_VALUE) - { + if (m_PortHandle != INVALID_HANDLE_VALUE) { ReadFile(m_PortHandle, Buffer, BufferSize, &Res, NULL); } - return Res; + return Res; } -uint32_t CSerialPort::Write(const LPVOID Buffer, uint32_t BufferSize) -{ +uint32_t CSerialPort::Write(const LPVOID Buffer, uint32_t BufferSize) { DWORD Res(0); - if (m_PortHandle != INVALID_HANDLE_VALUE) - { + if (m_PortHandle != INVALID_HANDLE_VALUE) { (void)WriteFile(m_PortHandle, Buffer, BufferSize, &Res, NULL); } return Res; } -BOOL CSerialPort::Get_CD_State() -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +bool CSerialPort::Get_CD_State() { + if (m_PortHandle != INVALID_HANDLE_VALUE) { DWORD ModemStat; - if (GetCommModemStatus(m_PortHandle, &ModemStat)) - { + if (GetCommModemStatus(m_PortHandle, &ModemStat)) { return (ModemStat & MS_RLSD_ON) > 0; //Not sure } - else - { - return FALSE; - } - } - else - { - return FALSE; } + return false; } -BOOL CSerialPort::Get_CTS_State() -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +bool CSerialPort::Get_CTS_State() { + if (m_PortHandle != INVALID_HANDLE_VALUE) { DWORD ModemStat; - if (GetCommModemStatus(m_PortHandle, &ModemStat)) - { + if (GetCommModemStatus(m_PortHandle, &ModemStat)) { return (ModemStat & MS_CTS_ON) > 0; } - else - { - return FALSE; - } - } - else - { - return FALSE; } + return false; } -BOOL CSerialPort::Get_DSR_State() -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +bool CSerialPort::Get_DSR_State() { + if (m_PortHandle != INVALID_HANDLE_VALUE) { DWORD ModemStat; - if (GetCommModemStatus(m_PortHandle, &ModemStat)) - { + if (GetCommModemStatus(m_PortHandle, &ModemStat)) { return (ModemStat & MS_DSR_ON) > 0; } - else - { - return FALSE; - } - } - else - { - return FALSE; } + return false; } -BOOL CSerialPort::Get_RI_State() -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +bool CSerialPort::Get_RI_State() { + if (m_PortHandle != INVALID_HANDLE_VALUE) { DWORD ModemStat; - if (GetCommModemStatus(m_PortHandle, &ModemStat)) - { + if (GetCommModemStatus(m_PortHandle, &ModemStat)) { return (ModemStat & MS_RING_ON) > 0; } - else - { - return FALSE; + } + return false; +} + +bool CSerialPort::Set_DTR_State(bool state) { + if (m_PortHandle != INVALID_HANDLE_VALUE) { + if (0 == EscapeCommFunction(m_PortHandle, (state ? SETDTR : CLRDTR))) { + return false; } } - else - { - return FALSE; - } + return true; } -void CSerialPort::Set_DTR_State(BOOL state) -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { - EscapeCommFunction(m_PortHandle, (state ? SETDTR : CLRDTR)); - } -} - -BOOL CSerialPort::Get_DTR_State() -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +bool CSerialPort::Get_DTR_State() { + if (m_PortHandle != INVALID_HANDLE_VALUE) { DWORD ModemStat; - if (GetCommModemStatus(m_PortHandle, &ModemStat)) - { + if (GetCommModemStatus(m_PortHandle, &ModemStat)) { return (ModemStat & MS_DSR_ON) > 0; //Not sure } - else - { - return FALSE; - } - } - else - { - return FALSE; } + return false; } -void CSerialPort::Set_RTS_State(BOOL state) -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +bool CSerialPort::Set_RTS_State(bool state) { + if (m_PortHandle != INVALID_HANDLE_VALUE) { if (0 == EscapeCommFunction(m_PortHandle, (state ? SETRTS : CLRRTS))) { - printf("Set_RTS_State(%d) failed.\n", state ? 1 : 0); + return false; } } + return true; } -BOOL CSerialPort::Get_RTS_State() -{ - if (m_PortHandle != INVALID_HANDLE_VALUE) - { +bool CSerialPort::Get_RTS_State() { + if (m_PortHandle != INVALID_HANDLE_VALUE) { DWORD ModemStat; - if (GetCommModemStatus(m_PortHandle, &ModemStat)) - { + if (GetCommModemStatus(m_PortHandle, &ModemStat)) { return (ModemStat & MS_CTS_ON) > 0; //Not sure } - else - { - return FALSE; - } - } - else - { - return FALSE; } + return false; } diff --git a/AVR Working Controller/SerialPort/SerialPort.h b/AVR Working Controller/SerialPort/SerialPort.h index 28b9fd9..8b065b1 100644 --- a/AVR Working Controller/SerialPort/SerialPort.h +++ b/AVR Working Controller/SerialPort/SerialPort.h @@ -24,20 +24,20 @@ class CSerialPort { public: - void Set_RTS_State(BOOL state); - void Set_DTR_State(BOOL state); - BOOL Get_RTS_State(); - BOOL Get_DTR_State(); - BOOL Get_RI_State(); - BOOL Get_DSR_State(); - BOOL Get_CTS_State(); - BOOL Get_CD_State(); + bool Set_RTS_State(bool state); + bool Set_DTR_State(bool state); + bool Get_RTS_State(); + bool Get_DTR_State(); + bool Get_RI_State(); + bool Get_DSR_State(); + bool Get_CTS_State(); + bool Get_CD_State(); virtual uint32_t Write(const LPVOID Buffer, uint32_t BufferSize); virtual uint32_t Read(LPVOID Buffer, uint32_t BufferSize); - virtual BOOL IsOpen(); + virtual bool IsOpen(); virtual void Close(); // Use PortName usually "COM1:" ... "COM4:" note that the name must end by ":" - virtual BOOL Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE Parity, BYTE StopBits, uint32_t DesiredAccess = GENERIC_READ|GENERIC_WRITE); + virtual bool Open(LPCTSTR PortName, uint32_t BaudRate, BYTE ByteSize, BYTE Parity, BYTE StopBits, uint32_t DesiredAccess = GENERIC_READ|GENERIC_WRITE); CSerialPort(); virtual ~CSerialPort(); diff --git a/DataSheets/Yamaha RX-V2400_RS232C_Standard.pdf b/DataSheets/Yamaha RX-V2400_RS232C_Standard.pdf index 73e367a..b4d9400 100644 Binary files a/DataSheets/Yamaha RX-V2400_RS232C_Standard.pdf and b/DataSheets/Yamaha RX-V2400_RS232C_Standard.pdf differ