99在易經(jīng)中代表什么(易經(jīng)99是什么意思)
2024-08-03
更新時間:2024-08-03 18:00:45作者:佚名
說明前面講到用通訊解析框架一般mcu或者其他的嵌入式系統(tǒng)或多或少涉及到通訊不光有各種各樣的字節(jié)指令還有字符串指令比如本文要講的AT指令很多模塊都涉及使用at指令作為指令集去做命令比如電話模塊wifi模塊藍(lán)牙模塊等等一般at指令解析比較繁瑣如果用到統(tǒng)一的框架做解析呢
注通訊解析框架的介紹可以看之前我寫的文章內(nèi)容這里不再贅述
下面我們著重講解使用通訊解析框架解析at指令
以漢楓wifi模塊為例
h框架文件
typedefstruct
U8Readbuf讀內(nèi)容
U16BufLen讀內(nèi)容長度
U8isUp主動上傳還是下載
intYALWifiCmdPos其他命令位置
YALWifiCmdPM讀數(shù)據(jù)地址
typedefstruct
constcharBufat內(nèi)容
U8HandleYALWifiCmdPMbuf長度
U16GetID獲取的CMDId
YALWifiCMDHandle讀數(shù)據(jù)框架結(jié)構(gòu)
enum
YALWIFICMDGETENTERAT1進(jìn)入AT
YALWIFICMDGETANAENTERAT應(yīng)答進(jìn)入AT
YALWIFICMDSETCLOSESHOWAT關(guān)閉回顯
C內(nèi)容文件
U8GetYALWIFIEnterAtYALWifiCmdPMCmdPm
U8GetYALWIFIAckEnterAtYALWifiCmdPMCmdPm
U8GetYALWIFICloseShowAtYALWifiCmdPMCmdPm
U8YALWIFILINKENDr結(jié)尾
獲取指令
constU8YALWIFIREQAT
constYALYALWifiCMDHandleYALWIFICmdhandle
GetYALWIFIEnterAtYALWIFICMDGETENTERAT進(jìn)入AT
aGetYALWIFIAckEnterAtYALWIFICMDGETANAENTERAT應(yīng)答AT
EGetYALWIFICloseShowAtYALWIFICMDSETCLOSESHOWAT關(guān)閉回顯
intYALWifiCMDfindCmdPosU16Cmd
inti
U8CmdCtsizeofYALWIFICmdhandlesizeofYALWIFICmdhandle0
fori0iisGet
returnYALWIFIReadCMDCmdPmYALWifiCmdPos
else
ifStrcmpCmdPmReadbufU8a1
err0
returnerr
函數(shù)名稱GetYALWIFIMacID
描述獲取WiFi版本號和MACID
輸入形參
返回值無
U8GetYALWIFIAckEnterAtYALWifiCmdPMCmdPm
u8err1
ifCmdPmisGet
returnYALWIFIReadCMDCmdPmYALWifiCmdPos
else
ifYALWifiCmdisOkCmdPmReadbuf
SetAtMode1
err0
returnerr
函數(shù)名稱GetYALWIFICloseShowAt
描述關(guān)閉回顯
輸入形參
返回值無
U8GetYALWIFICloseShowAtYALWifiCmdPMCmdPm
u8err1
ifCmdPmisGet
U8infostr10
轉(zhuǎn)義字符處理
memsetinfostr0sizeofinfostr
sprintfscharinfostrsizeofinfostroffsYALWIFILINKEND
strcatcharinfostrcharYALWIFILINKEND
returnYALWIFIReadWriteCMDCmdPmYALWifiCmdPosinfostr
else
ifYALWifiCmdisOkCmdPmReadbuf
err0
returnerr
函數(shù)名稱YALWIFIReadCMD
描述讀WiFi指令
輸入形參YALWifiCmdPos列表位置
返回值0成功1失敗
u8YALWIFIReadCMDintYALWifiCmdPos
ifCheckCmdPosYALWifiCmdPosreturn0
memcpySENDBUFYALWIFICmdhandleYALWifiCmdPosBufstrlencharYALWIFICmdhandleYALWifiCmdPosBuf
USART1SendStringSENDBUFstrlencharSENDBUF
return0
intYALWifiCMDfindCmdPosU16Cmd
inti
U8CmdCtsizeofYALWIFICmdhandlesizeofYALWIFICmdhandle0
fori0iCmdCti
ifCmdYALWIFICmdhandleiGetIDreturni
return1
解析at指令將字符串?dāng)?shù)據(jù)內(nèi)容解析到該函數(shù)中
U8YALAnaDatarevcmdU8BufU16BufLen
intYALWifiCmdPos
YALWifiCmdPMcmdPm
YALWifiCmdPosYALWifiCMDfindCmdPosGetLastCmdId上一次請求的內(nèi)容
ifCheckCmdPosYALWifiCmdPosreturn1
cmdPmReadbufBuf
cmdPmBufLenBufLen
cmdPmYALWifiCmdPosYALWifiCmdPos
cmdPmisGet0
returnYALWIFICmdhandleYALWifiCmdPosHandlecmdPm回調(diào)函數(shù)
發(fā)送cmd消息通過CMDId請求對應(yīng)的at指令
voidYALWifiCMDSetCmdU16Cmd
intWifiCmdPos
YALWifiCmdPMcmdPm
cmdPmReadbufSendBuf
cmdPmBufLen0
cmdPmisGet1
WifiCmdPosWifiCMDfindCmdPosCmd
ifWifiCmdPos1return
ifCheckCmdPosWifiCmdPosreturn
cmdPmWifiCmdPosWifiCmdPos
YALWIFICmdhandleWifiCmdPosHandlecmdPm
SetLastCmdIdYALWIFICmdhandleWifiCmdPosGetID
總結(jié)通過框架將AT指令的頭尾等公共部分作為框架一部分可變的內(nèi)容部分作為識別的內(nèi)容實(shí)體用于解析和發(fā)送比如作為識別碼ATE中的E作為識別碼
識別解析的內(nèi)容通過各種的handle回調(diào)處理當(dāng)發(fā)送一條AT指令對應(yīng)的回一條AT指令解析和發(fā)送對應(yīng)LastCmdId的關(guān)系去解對應(yīng)的回應(yīng)的AT指令內(nèi)容當(dāng)然AT指令多變本文只是
拋磚引玉可相互交流歡迎評論轉(zhuǎn)發(fā)加關(guān)注