112 lines
2.8 KiB
C
Executable File
112 lines
2.8 KiB
C
Executable File
#include <stdio.h>
|
|
#include <time.h>
|
|
#include <string.h>
|
|
|
|
/* 硬件类型 */
|
|
#define MODEL "SG368Z(RK3568) HDMI+VGA (Linux)"
|
|
|
|
typedef struct {
|
|
char *name; /* 固件版本 */
|
|
char *description; /* 版本说明 */
|
|
}version;
|
|
|
|
static version versions[] = {
|
|
{"V1.03 20240329", "添加IO状态的控制与读取"},
|
|
{"V1.04 20240403", "修改获取XS9922摄像头拔插状态的方法"},
|
|
{"V1.05 20240406", "移植QT环境"},
|
|
{"V1.06 20240407", "添加魔视模型库"},
|
|
{"V1.07 20240425", "1.继承SDK1.3版本; 2. rtsp-server 更新; 3. 有线网卡脚本优化;"},
|
|
{"V1.08 20240430", "修复485+RTC"},
|
|
{"V1.09 20240508", "1.添加 i2c-tools、can-utils、ifmetric、network-manager等测试工具包; 2.解决QT界面程序编译报错问题"},
|
|
{"V1.10 20240514", "重写网络控制脚本"},
|
|
};
|
|
|
|
/* 获取版本信息说明 */
|
|
void get_version_process(void);
|
|
|
|
/* 执行命令 */
|
|
static void exec(char* data, char* command, char* filter);
|
|
|
|
/* 函授入口 */
|
|
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", "");
|
|
|
|
int count = sizeof(versions) / sizeof(versions[0]);
|
|
|
|
/* 系统版本 */
|
|
printf("OS: %s\r\n", os_data);
|
|
/* 硬件类型 */
|
|
printf("MODEL: %s\r\n", MODEL);
|
|
/* 固件版本 */
|
|
printf("FIRMWARE: %s\r\n", versions[count - 1].name);
|
|
/* 版本说明 */
|
|
printf("DESCRIPTION: %s\r\n", versions[count - 1].description);
|
|
/* 系统内核版本信息 */
|
|
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', ' ');
|
|
}
|