29 #ifndef HDMI_CCEC_OPERANDS_HPP_
30 #define HDMI_CCEC_OPERANDS_HPP_
41 #include "Operand.hpp"
43 #include "ccec/CECFrame.hpp"
44 #include "ccec/Exception.hpp"
51 CECBytes(
const uint8_t val) : str(1, val) {}
52 CECBytes(
const uint8_t *buf,
size_t len) {
54 for (
size_t i = 0; i < len; i++) {
55 str.push_back(buf[i]);
60 bool validate(
void)
const {
61 return (str.size() && (str.size() <= getMaxLen()));
71 const uint8_t *buf = 0;
73 frame.getBuffer(&buf, &frameLen);
75 len = ((startPos + len) > frameLen) ? frameLen - startPos : len;
76 str.insert(str.begin(), buf + startPos, buf + startPos + len);
85 for (
size_t i = 0; i < str.size(); i++) {
91 using Operand::serialize;
95 virtual const std::string toString(
void)
const {
96 std::stringstream stream;
97 for (
size_t i = 0; i < str.size(); i++) {
98 stream << std::hex << (int)str[i];
103 bool operator == (
const CECBytes &in)
const {
104 return this->str == in.str;
108 std::vector<uint8_t> str;
109 virtual size_t getMaxLen(
void)
const {
110 return CECFrame::MAX_LENGTH;
128 const std::string toString(
void)
const {
129 return std::string(str.begin(), str.end());
132 size_t getMaxLen()
const {
return MAX_LEN;}
142 OSDName(
const char *str) :
CECBytes((
const uint8_t *)str, strlen(str)) {
149 const std::string toString(
void)
const {
150 return std::string(str.begin(), str.end());
153 size_t getMaxLen()
const {
return MAX_LEN;}
165 NOT_IN_CORRECT_MODE_TO_RESPOND,
166 CANNOT_OVERIDE_SOURCE,
174 const std::string toString(
void)
const {
175 static const char *names_[] = {
176 "Unrecognized opcode",
177 "Not in correct mode to respond",
178 "Cannot provide source",
181 "Unable to determine",
186 return names_[str[0]];
190 CCEC_LOG(LOG_WARN,
"Unknown abort reason:%x\n", str[0]);
195 bool validate(
void)
const {
196 return ((str[0]<= UNABLE_TO_DETERMINE));
199 int toInt(
void)
const {
207 size_t getMaxLen()
const {
return MAX_LEN;}
231 const std::string toString(
void)
const {
232 static const char *names_[] = {
245 return names_[str[0]];
249 CCEC_LOG(LOG_WARN,
"Unknown device type:%x\n", str[0]);
254 bool validate(
void)
const {
255 return ((str[0] <= VIDEO_PROCESSOR));
263 size_t getMaxLen()
const {
return MAX_LEN;}
280 const std::string toString(
void)
const {
281 return std::string(str.begin(), str.end());
284 size_t getMaxLen()
const {
return MAX_LEN;}
295 VendorID(uint8_t byte0, uint8_t byte1, uint8_t byte2) :
CECBytes (NULL, 0) {
296 uint8_t bytes[MAX_LEN];
300 str.insert(str.begin(), bytes, bytes + MAX_LEN);
303 VendorID(
const uint8_t *buf,
size_t len) :
CECBytes (buf, len > MAX_LEN ? MAX_LEN : len) {
310 size_t getMaxLen()
const {
return MAX_LEN;}
322 uint8_t bytes[MAX_LEN];
323 bytes[0] = (byte0 & 0x0F)<< 4 | (byte1 & 0x0F);
324 bytes[1] = (byte2 & 0x0F)<< 4 | (byte3 & 0x0F);
325 str.insert(str.begin(), bytes, bytes + MAX_LEN);
329 Assert(len >= MAX_LEN);
337 uint8_t bytes[MAX_LEN];
338 size_t dotposition = 0;
341 Assert((addr.length() != 0 && addr.length() == 7));
343 while (addr.length() && i < 4)
345 byte[i++] = stoi(addr,&dotposition,16);
346 if (addr.length() > 1)
348 addr = addr.substr(dotposition+1);
356 bytes[0] = (
byte[0] & 0x0F)<< 4 | (
byte[1] & 0x0F);
357 bytes[1] = (
byte[2] & 0x0F)<< 4 | (
byte[3] & 0x0F);
358 str.insert(str.begin(), bytes, bytes + MAX_LEN);
361 const uint8_t getByteValue(
int index)
const {
370 val = (int) ((str[0] & 0xF0) >> 4);
375 val = (int) (str[0] & 0x0F);
381 val = (int) ((str[1] & 0xF0) >> 4);
387 val = (int) (str[1] & 0x0F);
395 const std::string toString(
void)
const {
396 std::stringstream stream;
397 stream << (int)((str[0] & 0xF0) >> 4)<<
"." << (
int)(str[0] & 0x0F) <<
"." << (
int)((str[1] & 0xF0) >> 4) <<
"." << (int)(str[1] & 0x0F);
401 const std::string name(
void)
const {
402 return "PhysicalAddress";
406 size_t getMaxLen()
const {
return MAX_LEN;}
420 RECORDING_DEVICE_1 = 1,
421 RECORDING_DEVICE_2 = 2,
423 PLAYBACK_DEVICE_1 = 4,
427 PLAYBACK_DEVICE_2 = 8,
428 RECORDING_DEVICE_3 = 9,
430 PLAYBACK_DEVICE_3 = 11,
435 BROADCAST = UNREGISTERED,
440 const std::string toString(
void)
const
442 static const char *names_[] = {
444 "Recording Device 1",
445 "Recording Device 2",
452 "Recording Device 3",
458 "Broadcast/Unregistered",
463 return names_[str[0]];
467 CCEC_LOG(LOG_WARN,
"Unknown logical address:%x\n", str[0]);
472 int toInt(
void)
const {
476 bool validate(
void)
const {
477 return ((str[0] <= BROADCAST) && (str[0] >= TV));
480 int getType(
void)
const {
486 static int _type[] = {
488 DeviceType::RECORDING_DEVICE,
489 DeviceType::RECORDING_DEVICE,
491 DeviceType::PLAYBACK_DEVICE,
492 DeviceType::AUDIO_SYSTEM,
495 DeviceType::PLAYBACK_DEVICE,
496 DeviceType::RECORDING_DEVICE,
498 DeviceType::PLAYBACK_DEVICE,
499 DeviceType::RESERVED,
500 DeviceType::RESERVED,
501 DeviceType::RESERVED,
502 DeviceType::RESERVED,
505 return _type[str[0]];
511 size_t getMaxLen()
const {
return MAX_LEN;}
532 bool validate(
void)
const {
533 return ((str[0] <= V_1_4) && (str[0] >= V_1_3a));
536 const std::string toString(
void)
const
538 static const char *names_[] = {
549 return names_[str[0]];
553 CCEC_LOG(LOG_WARN,
"Unknown version:%x\n", str[0]);
561 size_t getMaxLen()
const {
return MAX_LEN;}
574 IN_TRANSITION_STANDBY_TO_ON = 0x02,
575 IN_TRANSITION_ON_TO_STANDBY = 0x03,
576 POWER_STATUS_NOT_KNOWN = 0x4,
577 POWER_STATUS_FEATURE_ABORT = 0x05,
582 bool validate(
void)
const {
583 return ((str[0] <= IN_TRANSITION_ON_TO_STANDBY));
586 const std::string toString(
void)
const
588 static const char *names_[] = {
591 "In transition Standby to On",
592 "In transition On to Standby",
599 return names_[str[0]];
603 CCEC_LOG(LOG_WARN,
"Unknown powerstatus:%x\n", str[0]);
608 int toInt(
void)
const {
616 size_t getMaxLen()
const {
return MAX_LEN;}
628 SAD_FMT_CODE_LPCM =1 ,
636 SAD_FMT_CODE_ONE_BIT_AUDIO,
637 SAD_FMT_CODE_ENHANCED_AC3,
641 SAD_FMT_CODE_WMA_PRO,
642 SAD_FMT_CODE_EXTENDED,
646 const std::string toString(
void)
const
648 static const char *AudioFormtCode[] = {
664 "Reserved for Audio format 15",
667 return AudioFormtCode[str[0] & 0xF];
669 int getAudioformatId(
void)
const {
674 int getAudioformatCode(
void)
const {
676 return (str[0] & 0x3F);
680 size_t getMaxLen()
const {
return MAX_LEN;}
692 SAD_FMT_CODE_LPCM =1 ,
700 SAD_FMT_CODE_ONE_BIT_AUDIO,
701 SAD_FMT_CODE_ENHANCED_AC3,
705 SAD_FMT_CODE_WMA_PRO,
706 SAD_FMT_CODE_EXTENDED,
711 Assert(len >= MAX_LEN);
715 const std::string toString(
void)
const
718 static const char *AudioFormtCode[] = {
734 "Reserved for Audio format 15",
737 return AudioFormtCode[(str[0] >> 3) & 0xF];
740 uint32_t getAudiodescriptor(
void)
const {
741 uint32_t audiodescriptor;
743 audiodescriptor = (str[0] | str[1] << 8 | str[2] << 16);
744 return audiodescriptor;
748 int getAudioformatCode(
void)
const {
749 uint8_t audioformatCode;
750 audioformatCode = ((str[0] >> 3) & 0xF);
751 return audioformatCode;
754 uint8_t getAtmosbit(
void)
const {
756 bool atmosSupport =
false;
757 if ((((str[0] >> 3) & 0xF) >= 9) && (((str[0] >> 3) & 0xF) <= 15))
759 if((str[2] & 0x3) != 0)
769 size_t getMaxLen()
const {
return MAX_LEN;}
786 bool validate(
void)
const {
787 return ((str[0] <= ON) );
790 const std::string toString(
void)
const
792 static const char *names_[] = {
799 return names_[str[0]];
803 CCEC_LOG(LOG_WARN,
"Unknown SystemAudioStatus:%x\n", str[0]);
808 int toInt(
void)
const {
816 size_t getMaxLen()
const {
return MAX_LEN;}
826 AUDIO_MUTE_OFF = 0x00,
827 AUDIO_MUTE_ON = 0x01,
831 bool validate(
void)
const {
832 return (((str[0] & 0x80) >> 7) <= AUDIO_MUTE_ON) ;
834 const std::string toString(
void)
const
836 static const char *names_[] = {
842 return names_[((str[0] & 0x80) >> 7)];
846 CCEC_LOG(LOG_WARN,
"Unknown Audio Mute Status:%x\n", str[0]);
850 int getAudioMuteStatus(
void)
const {
851 return ((str[0] & 0x80) >> 7);
853 int getAudioVolume(
void)
const {
854 return (str[0] & 0x7F);
859 size_t getMaxLen()
const {
return MAX_LEN;}
869 UI_COMMAND_VOLUME_UP = 0x41,
870 UI_COMMAND_VOLUME_DOWN = 0x42,
871 UI_COMMAND_MUTE = 0x43,
872 UI_COMMAND_MUTE_FUNCTION = 0x65,
873 UI_COMMAND_RESTORE_FUNCTION = 0x66,
874 UI_COMMAND_POWER_OFF_FUNCTION = 0x6C,
875 UI_COMMAND_POWER_ON_FUNCTION = 0x6D,
876 UI_COMMAND_UP = 0x01,
877 UI_COMMAND_DOWN = 0x02,
878 UI_COMMAND_LEFT = 0x03,
879 UI_COMMAND_RIGHT = 0x04,
880 UI_COMMAND_SELECT = 0x00,
881 UI_COMMAND_HOME = 0x09,
882 UI_COMMAND_BACK = 0x0D,
883 UI_COMMAND_NUM_0 = 0x20,
884 UI_COMMAND_NUM_1 = 0x21,
885 UI_COMMAND_NUM_2 = 0x22,
886 UI_COMMAND_NUM_3 = 0x23,
887 UI_COMMAND_NUM_4 = 0x24,
888 UI_COMMAND_NUM_5 = 0x25,
889 UI_COMMAND_NUM_6 = 0x26,
890 UI_COMMAND_NUM_7 = 0x27,
891 UI_COMMAND_NUM_8 = 0x28,
892 UI_COMMAND_NUM_9 = 0x29,
897 int toInt(
void)
const {
902 size_t getMaxLen()
const {
return MAX_LEN;}