// // // #include "CommandDecoder.h" byte CommandDecoder::_CheckSUM(byte main, byte data1, byte data2, byte data3) { return ((byte)((main + data1 + data2 + data3) % 0xFF)); } CommandDecoder::CommandDecoder() { } CommandDecoder::CommandDecoder(byte* arr) { cmd[0] = arr[0]; cmd[1] = arr[1]; cmd[2] = arr[2]; cmd[3] = arr[3]; cmd[4] = arr[4]; cmd[5] = arr[5]; cmd[6] = arr[6]; cmd[7] = arr[7]; } bool CommandDecoder::CommandValidate() { if ((cmd[0] != CommandData::FrameHead) || (cmd[7] != CommandData::FrameEnd)) return false; byte checksum = _CheckSUM(cmd[2], cmd[3], cmd[4], cmd[5]); if (cmd[6] != checksum) return false; return true; } byte CommandDecoder::GetDevice() { return cmd[1]; } byte CommandDecoder::GetMainCommand() { return cmd[2]; } byte CommandDecoder::GetDataBit(byte num) { if ((num < 1) || (num > 3)) return -1; return cmd[2 + num]; }