英創公司十余年來都專注于嵌入式工控主板的開發,推出了很多不同型號的產品,也和許多客戶建立了長期的合作和信任。隨著英創公司不斷的對產品進行更新,推出性能越來越好的新產品,很多客戶也對自己的產品進行更新,并且推出新的項目。
經過長時間的累積,已經有許多客戶的多個項目使用了英創公司不同型號的板卡,為了讓客戶更方便的管理應用程序,英創公司整理了一個方便客戶識別板卡型號的方法,通過這個方法,客戶可以將多個項目的程序整合起來,通過一個管理程序,對板卡進行判斷,然后執行相應的操作,十分簡單和方便。
客戶只需要讀取板卡文件系統中的/etc/hostname這個文件就可以了,英創公司目前主要的產品型號和hostname文件的對應可以參考下面的表格:
板卡型號 | hostname文件 |
em9x60系列板卡 | EM9X60 |
em928x系列板卡 | EM9280 |
em335x系列板卡 | EM335X |
esm335x系列板卡 | ESM335X |
esm6800板卡 | ESM6800 |
esm6802板卡 | ESM6802 |
客戶可以用過C語言標準的I/O讀寫函數來實現這一功能,使用fopen打開文件,然后fread將文件內容讀取到buffer中,進行對比。
下面的是一個簡單的例程,判斷板卡型號并打印出來,可以供需要的客戶參考:
#include
#include
#include
#include
/* the boardtype of Emtronix */
enum type{em9x60 = 1, em928x, em335x, esm335x, esm6800};
/* get the boadrtype from /etc/hostname */
int main(int argc, char *argv[])
{
FILE *fp;
char buf[50];
int boardtype = 0;
/* open the /etc/hostname read only */
fp = fopen("/etc/hostname", "rb");
if(fp == NULL)
{
perror("/etc/hostname");
return errno;
}
fread( buf, sizeof(char), 50, fp );
/* check the boardtype */
if(strstr(buf, "EM9X60") > 0)
boardtype = em9x60;
else if(strstr(buf, "EM9280") > 0)
boardtype = em928x;
else if(strstr(buf, "EM335X") > 0)
boardtype = em335x;
else if(strstr(buf, "ESM335X") > 0)
boardtype = esm335x;
else if(strstr(buf, "ESM6800") > 0)
boardtype = esm6800;
fclose(fp);
/* printf the boardtype */
switch(boardtype)
{
case em9x60:
printf("the boardtype is EM9x60\n");
break;
case em928x:
printf("the boardtype is EM928x\n");
break;
case em335x:
printf("the boardtype is EM335x\n");
break;
case esm335x:
printf("the boardtype is ESM335x\n");
break;
case esm6800:
printf("the boardtype is ESM680x\n");
break;
default:
printf("the boardtype is unknow, please check the platform!\n");
break;
}
return 0;
}
-
嵌入式主板
+關注
關注
7文章
6086瀏覽量
35614
發布評論請先 登錄
相關推薦
評論