it3256_control.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef It3256_CONTROL_H
  2. #define It3256_CONTROL_H
  3. #include "it3256_stub.h"
  4. #include "advio.h"
  5. #include "it3256_log.h"
  6. #include <iostream>
  7. #include <cstdio>
  8. #include <string>
  9. #include <memory>
  10. namespace OHOS{
  11. namespace It3256 {
  12. class It3256IOControl : public It3256IOStub {
  13. public:
  14. It3256IOControl();
  15. ~It3256IOControl();
  16. bool GetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
  17. bool SetAIRangeCode(unsigned char startch, unsigned char stopch, unsigned char *poutbuf) override;
  18. std::string executeCommand(const std::string& command) {
  19. // 使用 popen 执行命令并捕获其输出
  20. std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose);
  21. if (!pipe) {
  22. std::cerr << ": Failed to execute command: " << command << std::endl;
  23. return "-1";
  24. }
  25. // 读取命令的输出
  26. char buffer[128];
  27. std::string result;
  28. while (fgets(buffer, sizeof(buffer), pipe.get()) != nullptr) {
  29. result += buffer;
  30. }
  31. return result;
  32. }
  33. private:
  34. bool initialized_ = false;
  35. };
  36. }
  37. } // namespace It3256
  38. #endif // It3256_CONTROL_H