通讯协议(例子)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
进程模块说明3(pss)
MODULE mpss() VAR busy[0..ML]: 0..1; obuf[0..ML]: {ack,red,green,blue}; q: 0..ML; s: 0..ML; //q=oldest unacked,s=next to send y: 0..ML; wd: 0..W; INIT (for xx in [0..ML]): busy[xx]=0; (for xx in [0..ML]): obuf[xx]=0; q=0; s=0; y=0; wd=0; TRANS wd<W&cha.len>0&chr.len<QS: mpsscase1(wd,s)&(wd):=(wd); chs.len>0: chget(ss,ack,y)&(busy[y]):=(0); wd>0&busy[q]=0: (wd,q):=(wd-1,(q+1)%M); chr.len<QS&wd>0&busy[q]=1: mpsscase2(q)&(wd):=(wd);
过程说明3a
PROCEDURE mpsscase1(wd,s) VAR pc: {s0,s1,s2,s3}; tmp: {ack,red,green,blue}; INIT pc=s0; tmp=0; TRANS pc=s0: chget(aa,tmp,s)&(pc):=(s1); pc=s1: (wd,pss.busy[s],pss.obuf[s],pc):=(wd+1,1,tmp,s2); pc=s2: chput(rr,tmp,s)&(s):=((s+1)%M)&RETURN;
过程说明3b
进程模块说明2(通道)
MODULE chab() VAR contents[0..QSL]: {ack,red,green,blue}; len: 0..QS; start: 0..QSL; INIT (for xx in [0..QSL]): contents[xx]=0; len=0; start=0; TRANS FALSE: TRUE;
通讯协议 (例子)
通讯协议
A B
通讯协议
A B
S
R
通讯协议
A B
S
R
通讯协议
A B
cha
S百度文库
chb chr
R
chs
通讯协议
pra prb
cha
pss
chb chr
prr
obuf[] busy[] s q
chs
M W QS
ibuf[] recv[] m p
通讯协议模型(主程序)
VVM ft001 DEFINE QS=2 QSL=1 M=4 ML=3 W=2 WL=1 rr=0 ss=1 aa=2 bb=3 VAR err: 0..1; INIT err=0; PROC chr: chrs(); chs: chrs(); cha: chab(); chb: chab(); pra: mpra(); prb: mprb(); SPEC AG(err!=1);
进程模块说明1(通道)
MODULE chrs() VAR contents[0..QSL]: {ack,red,green,blue}; seq[0..QSL]: 0..ML; len: 0..QS; start: 0..QSL; INIT (for xx in [0..QSL]): contents[xx]=0; (for xx in [0..QSL]): seq[xx]=0; len=0; start=0; TRANS len>0: (len,start):=(len-1,(start+1)%M); //loosy channel
过程说明2
PROCEDURE chput(nn,c,s) VAR pc: {s0,s1}; pos: 0..QS; INIT pc=s0; pos=0; TRANS nn=0&pc=s0: (pos,pc):=((chr.start+chr.len)%QS,s1); nn=0&pc=s1: (chr.contents[pos],chr.seq[pos],chr.len):=( c,s,chr.len+1)&RETURN; nn=1&pc=s0: (pos,pc):=((chs.start+chs.len)%QS,s1); nn=1&pc=s1: (chs.contents[pos],chs.seq[pos],chs.len):=( c,s,chs.len+1)&RETURN; nn=2&pc=s0: (pos,pc):=((cha.start+cha.len)%QS,s1); nn=2&pc=s1: (cha.contents[pos],cha.len):=(c,cha.len+1)&RETURN; nn=3&pc=s0: (pos,pc):=((chb.start+chb.len)%QS,s1); nn=3&pc=s1: (chb.contents[pos],chb.len):=(c,chb.len+1)&RETURN;
过程说明1
PROCEDURE chget(nn,c,s) VAR INIT TRANS nn=rr: (c,s,chr.start,chr.len):=( chr.contents[chr.start],chr.seq[chr.start], (chr.start+1)%QS,chr.len-1)&RETURN; nn=ss: (c,s,chs.start,chs.len):=( chs.contents[chs.start],chs.seq[chs.start], (chs.start+1)%QS,chs.len-1)&RETURN; nn=aa: (c,cha.start,cha.len):=( cha.contents[cha.start],(cha.start+1)%QS,cha.len-1)&RETURN; nn=bb: (c,chb.start,chb.len):=( chb.contents[chb.start],(chb.start+1)%QS,chb.len-1)&RETURN;