英創(chuàng)公司十余年來都專注于嵌入式工控主板的開發(fā),推出了很多不同型號的產(chǎn)品,也和許多客戶建立了長期的合作和信任。隨著英創(chuàng)公司不斷的對產(chǎn)品進(jìn)行更新,推出性能越來越好的新產(chǎn)品,很多客戶也對自己的產(chǎn)品進(jìn)行更新,并且推出新的項目。
經(jīng)過長時間的累積,已經(jīng)有許多客戶的多個項目使用了英創(chuàng)公司不同型號的板卡,為了讓客戶更方便的管理應(yīng)用程序,英創(chuàng)公司整理了一個方便客戶識別板卡型號的方法,通過這個方法,客戶可以將多個項目的程序整合起來,通過一個管理程序,對板卡進(jìn)行判斷,然后執(zhí)行相應(yīng)的操作,十分簡單和方便。
客戶只需要讀取板卡文件系統(tǒng)中的/etc/hostname這個文件就可以了,英創(chuàng)公司目前主要的產(chǎn)品型號和hostname文件的對應(yīng)可以參考下面的表格:
板卡型號 | hostname文件 |
em9x60系列板卡 | EM9X60 |
em928x系列板卡 | EM9280 |
em335x系列板卡 | EM335X |
esm335x系列板卡 | ESM335X |
esm6800板卡 | ESM6800 |
esm6802板卡 | ESM6802 |
客戶可以用過C語言標(biāo)準(zhǔn)的I/O讀寫函數(shù)來實現(xiàn)這一功能,使用fopen打開文件,然后fread將文件內(nèi)容讀取到buffer中,進(jìn)行對比。
下面的是一個簡單的例程,判斷板卡型號并打印出來,可以供需要的客戶參考:
#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;
}
-
嵌入式主板
+關(guān)注
關(guān)注
7文章
6086瀏覽量
35619
發(fā)布評論請先 登錄
相關(guān)推薦
評論