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