rk3568_ubuntu_r60_v1.3.2/yocto/meta-tvis-app/recipes/hvgo-tvis/files/hvgo.c

108 lines
2.5 KiB
C
Raw Normal View History

#include <stdio.h>
#include <time.h>
#include <string.h>
/* 硬件类型 */
#define MODEL "SG368Z(RK3568) HDMI+VGA (Linux)"
2024-04-06 01:56:01 +08:00
typedef struct {
char *name; /* 固件版本 */
char *description; /* 版本说明 */
}version;
2024-04-06 01:56:01 +08:00
static version versions[] = {
{"V1.03 20240329", "添加IO状态的控制与读取"},
{"V1.04 20240403", "修改获取XS9922摄像头拔插状态的方法"},
{"V1.05 20240406", "移植QT环境"},
{"V1.06 20240407", "添加魔视模型库"},
2024-04-06 01:56:01 +08:00
};
/* 获取版本信息说明 */
void get_version_process(void);
2024-04-06 01:56:01 +08:00
/* 执行命令 */
static void exec(char* data, char* command, char* filter);
2024-04-06 01:56:01 +08:00
/* 函授入口 */
int main(int argc, char *argv[])
{
if(argc == 1)
{
printf("Usage:\r\n");
printf("hvgo: show this usage\r\n");
printf("hvgo version: get version\r\n");
printf("\r\n");
return 0;
}
if(strcmp(argv[1], "version") == 0)
get_version_process();
return 0;
}
void get_version_process(void)
{
char os_data[1024] = {0}, kernel_data[1024] = {0};
exec(os_data, "cat /etc/issue", "\\n \\l");
exec(kernel_data, "cat /proc/version", "");
2024-04-06 01:56:01 +08:00
int count = sizeof(versions) / sizeof(versions[0]);
/* 系统版本 */
2024-04-06 01:56:01 +08:00
printf("OS: %s\r\n", os_data);
/* 硬件类型 */
2024-04-06 01:56:01 +08:00
printf("MODEL: %s\r\n", MODEL);
/* 固件版本 */
2024-04-06 01:56:01 +08:00
printf("FIRMWARE: %s\r\n", versions[count - 1].name);
/* 版本说明 */
printf("DESCRIPTION: %s\r\n", versions[count - 1].description);
/* 系统内核版本信息 */
2024-04-06 01:56:01 +08:00
printf("KERNEL: %s\r\n", kernel_data);
}
void replace(char *str, char *orig, char *rep)
{
if(strlen(orig) > 0)
{
static char buffer[1024];
char *p;
while (p = strstr(str, orig))
{
memcpy(buffer, str, p-str);
buffer[p-str] = '\0';
strcat(buffer, rep);
strcat(buffer, p+strlen(orig));
strcpy(str, buffer);
}
}
}
void replace_char(char *str, char find, char replace)
{
for (int i = 0; str[i]; i++){
if (str[i] == find){
str[i] = replace;
}
}
}
static void exec(char* data, char* command, char* filter)
{
FILE *fp;
char buffer[1024];
fp = popen(command, "r"); // 打开 messages 日志文件并只显示最后一行
fgets(buffer, sizeof(buffer), fp);
strcpy(data, buffer);
pclose(fp);
replace(data, filter, "");
replace_char(data, '\n', ' ');
replace_char(data, '\r', ' ');
}