diff --git a/server/dl_lib/libkvm.so b/server/dl_lib/libkvm.so index a3a89bb..bde4c2c 100644 Binary files a/server/dl_lib/libkvm.so and b/server/dl_lib/libkvm.so differ diff --git a/server/dl_lib/libkvm_mmf.so b/server/dl_lib/libkvm_mmf.so index fc56b31..b192200 100644 Binary files a/server/dl_lib/libkvm_mmf.so and b/server/dl_lib/libkvm_mmf.so differ diff --git a/support/sg2002/additional/kvm/src/kvm_vision.cpp b/support/sg2002/additional/kvm/src/kvm_vision.cpp index 8e260f3..86af38a 100644 --- a/support/sg2002/additional/kvm/src/kvm_vision.cpp +++ b/support/sg2002/additional/kvm/src/kvm_vision.cpp @@ -216,54 +216,58 @@ void write_res_to_file(uint16_t _width, uint16_t _height) */ uint8_t get_vi_state() { - char VI_State[10]={0}; - char cmd[100] = "cat /proc/cvitek/vi_dbg | grep -A 17 VIDevFPS | awk '{print $3}'"; - uint8_t FPS[2]; - uint8_t VIWHGTLSCnt[4]; - FILE* fp = popen( cmd, "r" ); - uint8_t ret = 0; + FILE *fp = fopen("/proc/cvitek/vi_dbg", "r"); + if (fp == NULL) { + return 0; + } - if (fgets(VI_State, sizeof(VI_State), fp) != NULL){ - FPS[0] = atoi(VI_State); - // debug("VIDevFPS = %d\n", FPS[0]); - } else { - pclose(fp); - return ret; // VI not init; + unsigned int dev_fps = 0; + unsigned int fps = 0; + unsigned int width_gt = 0; + unsigned int width_ls = 0; + unsigned int height_gt = 0; + unsigned int height_ls = 0; + bool have_dev_fps = false; + bool have_fps = false; + char line[256]; + char field[32]; + unsigned int value; + while (fgets(line, sizeof(line), fp) != NULL) { + if (sscanf(line, "%31s : %u", field, &value) != 2) { + continue; + } + if (strcmp(field, "VIDevFPS") == 0) { + dev_fps = value; + have_dev_fps = true; + } else if (strcmp(field, "VIFPS") == 0) { + fps = value; + have_fps = true; + } else if (strcmp(field, "VICsiCh0WidthGTCnt") == 0) { + width_gt = value; + } else if (strcmp(field, "VICsiCh0WidthLSCnt") == 0) { + width_ls = value; + } else if (strcmp(field, "VICsiCh0HeightGTCnt") == 0) { + height_gt = value; + } else if (strcmp(field, "VICsiCh0HeightLSCnt") == 0) { + height_ls = value; + } } - if (fgets(VI_State, sizeof(VI_State), fp) != NULL){ - FPS[1] = atoi(VI_State); - // debug("VIFPS = %d\n", FPS[1]); - } - if (FPS[0] == 0){ - ret = 2; // HDMI not OK; - } else if (FPS[1] == 0){ - ret = 3; // HDMI OK ; CSI not; - } else { - ret = 1; // HDMI CSI OK; - } - if(ret == 3){ - // Ignore other information - uint8_t count = 0; - for(count = 0; count < 13; count ++){ - fgets(VI_State, sizeof(VI_State), fp); - } - // Check if the resolution might be set incorrectly - for(count = 0; count < 4; count ++){ - if (fgets(VI_State, sizeof(VI_State), fp) != NULL){ - // debug("VI_State = %s", VI_State); - VIWHGTLSCnt[count] = atoi(VI_State); - // printf("count = %d, val = %d\n", count, atoi(VI_State)); - } - } + fclose(fp); - if(VIWHGTLSCnt[0] != 0) ret = 3; // The vi width setting value is too small - else if(VIWHGTLSCnt[1] != 0) ret = 4; // The vi width setting value is too large - else if(VIWHGTLSCnt[2] != 0) ret = 5; // The vi height setting value is too small - else if(VIWHGTLSCnt[3] != 0) ret = 6; // The vi height setting value is too large - else ret = 7; // printf("[kvmv] Unexpected situation\n"); - } - pclose(fp); - return ret; + if (!have_dev_fps || !have_fps) { + return 0; + } + if (dev_fps == 0) { + return 2; + } + if (fps != 0) { + return 1; + } + if (width_gt != 0) return 3; + if (width_ls != 0) return 4; + if (height_gt != 0) return 5; + if (height_ls != 0) return 6; + return 7; } int set_hdmi_mode(uint8_t _hdmi_mode) diff --git a/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp b/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp index d98d576..6cab58a 100644 --- a/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp +++ b/support/sg2002/kvm_system/main/lib/system_state/system_state.cpp @@ -237,24 +237,24 @@ void kvm_update_usb_state() void kvm_update_hdmi_state() { static uint8_t check_times = 4; - FILE *fp; - int file_size; - uint8_t RW_Data[10]; if(++check_times > 5){ check_times = 0; - fp = popen("cat /proc/cvitek/vi_dbg | grep VIFPS | awk '{print $3}'", "r"); + FILE *fp = fopen("/proc/cvitek/vi_dbg", "r"); if (fp == NULL) { - pclose(fp); return; } - fgets((char*)RW_Data, 2, fp); - pclose(fp); - // printf("[kvmd]HDMI exist? %c\n", RW_Data[0]); - if (RW_Data[0] != '0'){ - kvm_sys_state.hdmi_state = 1; - } else { - kvm_sys_state.hdmi_state = 0; + + char line[256]; + char field[32]; + unsigned int value; + while (fgets(line, sizeof(line), fp) != NULL) { + if (sscanf(line, "%31s : %u", field, &value) == 2 && + strcmp(field, "VIFPS") == 0) { + kvm_sys_state.hdmi_state = value == 0 ? 0 : 1; + break; + } } + fclose(fp); } } @@ -519,4 +519,4 @@ int check_watchdog() return -1; } } else return 0; -} \ No newline at end of file +}