source: WorldVistAEHR/trunk/r/CMOP-PSX/PSXSND.m@ 1582

Last change on this file since 1582 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 3.6 KB
Line 
1PSXSND ;BIR/BAB,WPB-Transmit a Message ;[ 05/13/97 8:39 AM ]
2 ;;2.0;CMOP;**1**;11 Apr 97
3GETMSG ;Get first message in queue
4 S PSXQN=$O(^PSX(552.2,"AQ",PSXB,"")) K PSXPOP
5 S PSXMSGID=$P(^PSX(552.2,PSXQN,0),"^")
6 G:'PSXQN ^PSXJOB
7 G:$G(PSXBHS)'=1 HDR
8 S BHST=0
9 D GETTXT Q:$G(QRYPOP)=1
10 G:PSXPOP ^PSXJOB
11 I PSXPOP D SND8 D LOG^PSXUTL,FLUSH1^PSXUTL
12 I PSXPOP G DONE ;dont store last if mess never sent
13 S ^PSX(553,1,99)=$P(^PSX(552.2,PSXQN,0),"^") ;last message sent, wait for ACK message
14DONE W *EOT,*TERM ;send termination sequence to slave
15 D EN^PSXACK ;get ACK message
16 G ^PSXJOB
17FILE Q:$G(PSXDA)="" D NOW^%DTC S REC=PSXDA L +^PSX(552.1,REC):30 G:'$T FILE S $P(^PSX(552.1,REC,0),U,2)=3,DIE="^PSX(552.1,",DA=REC,DR="16////"_%_";18////"_$G(PSXMSH)_$G(PSXMSA)_";20////@"
18 D ^DIE L -^PSX(552.1,REC) K DIE,REC S DIK="^PSX(552.1," D IX^DIK K DA,DIK
19 S LOG(1)="Transmission # "_PSXB_" finished downloading." D LOG^PSXUTL
20 S $P(^PSX(554,1,0),"^",2)=PSXB
21 D ACK^PSXNOTE
22 Q
23HDR D TSOUT^PSXUTL
24 S PSXBLK=1,PSXBHS=0,LOG(1)="Downloading Transmission # "_PSXB D LOG^PSXUTL
25 ;S $P(^PSX(552.1,PSXDA,0),"^",2)=7
26 S PSXTXT="BHS|^~\&|DHCP||"_$S($G(PSXVNDR)>0:"SI BAKER",1:"ELECTROCOM")_"||"_PSXTS_"||ORM|"_PSXB_"|P|2.1|",PSXLAST=0 D XMIT G:$G(PSXPOP) ^PSXJOB
27 S PSXBLK=PSXBLK+1
28 S REC=PSXDA,PSXMSGID=PSXB
29 F CNT=0:0 S CNT=$O(^PSX(552.1,REC,"S",CNT)) Q:CNT'>0 S PSXBLK=(CNT#8)+1,PSXTXT=$G(^PSX(552.1,REC,"S",CNT,0)),PSXLAST=$S($O(^PSX(552.1,REC,"S",CNT)):0,1:1) S:PSXBLK>7 PSXBLK=0 D XMIT G:$G(PSXPOP) ^PSXJOB
30 W *EOT,*TERM
31 D EN^PSXACK K:$G(PSXBHS)>0 XTRY G:PSXBHS=1 BID1^PSXMST
32 S XTRY=$G(XTRY)+1 S LOG(1)="Batch Header Rejected by Vendor for Transmission "_$G(PSXB) D LOG^PSXUTL G:$G(XTRY)'>5 ^PSXJOB
33 I $G(XTRY)>5 S LOG(1)="Batch Header for transmission "_$G(PSXB)_" rejected max times.",LOG(2)="DHCP Stopping interface." D LOG^PSXUTL G STOP^PSXJOB
34 Q
35GETTXT F I=0:0 S I=$O(^PSX(552.2,PSXQN,"T",I)) Q:'I K PSXTXT S PSXBLK=I#8,PSXTXTN=I,PSXTXT=$G(^(PSXTXTN,0)),PSXLAST=$S($O(^PSX(552.2,PSXQN,"T",I)):0,1:1) Q:PSXTXT="" D XMIT Q:PSXPOP
36 Q
37XMIT S (PSXPOP,PSXTRYN)=0
38 S PSXLEN=$L(PSXTXT)
39 S PSXLEN=$E("00000",1,5-$L(PSXLEN))_PSXLEN
40 S PSXTXT=PSXBLK_PSXLEN_PSXTXT_$S(PSXLAST:$C(ETX),1:$C(ETB))
41 ;Get 2 byte hex Csum
42 S X=PSXTXT X ^%ZOSF("LPC") S PSXHEX=Y D HEX^PSXUTL
43 S PSXTXT=$C(STX)_PSXTXT_PSXHEX_$C(TERM)
44RETRY W PSXTXT
45 S PSXBLK=$A(PSXBLK)
46TRY R *X:PSXDLTA E D SND1 G ERROR ;look for ACK or NAK
47 I X=ACK R *X:PSXDLTA D:('$T)!(X'=PSXBLK) SND2 G:('$T)!(X'=PSXBLK) ERROR R *X:PSXDLTA D:('$T)!(X'=TERM) SND9 G:('$T)!(X'=TERM) ERROR Q
48 I X=NAK R *X:PSXDLTA D:('$T)!(X'=TERM) SND3 D SND4 G ERROR
49 I X=EOT R *X:PSXDLTA D:('$T)!(X'=TERM) SND5 D SND7 G:('$T)!(X'=TERM) ERROR S PSXTRYN=9999 G ERROR
50 D SND6
51ERROR D FLUSH1^PSXUTL,LOG^PSXUTL
52 S PSXTRYN=PSXTRYN+1
53 S PSXBLK=$C(PSXBLK)
54 G:PSXTRYN'>PSXTRYL RETRY
55 S PSXPOP=1
56 Q
57SND1 K LOG S LOG(1)="SND1 Timer A timeout after sending a line of text."_$G(PSXBLK) Q
58SND2 K LOG S LOG(1)="SND2 ACK Received with bad block number after sending line of text, ASCII ("_$G(X)_") "_X
59 S LOG(2)="Expected ASCII ("_$G(PSXBLK)_")." Q
60SND3 K LOG S LOG(1)="SND3 NAK Received with no terminator after sending a line of text." Q
61SND4 K LOG S LOG(1)="SND4 NAK Received after sending a line of text." Q
62SND5 K LOG S LOG(1)="SND5 EOT Received with no terminator after sending a line of text." Q
63SND6 K LOG S LOG(1)="SND6 Garbage received after sending a line of text. ("_X_")" Q
64SND7 K LOG S LOG(1)="SND7 EOT Received, aborting send." Q
65SND8 K LOG S LOG(1)="SND8 Aborting Send. Error processing order # "_$P($G(^PSX(552.2,PSXQN,0)),"^",1)_". Text: "_PSXTXT Q
66SND9 K LOG S LOG(1)="SND9 ACK,"_$G(PSXBLK)_" received with no terminator after sending",LOG(2)="a line of text." Q
Note: See TracBrowser for help on using the repository browser.