-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpostcach.src
executable file
·140 lines (124 loc) · 4.5 KB
/
postcach.src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'##########################################################################
'
' Post Cache
'
'##########################################################################
'$include:'const.inc'
'$include:'util.def'
'$include:'util.inc'
'$include:'input.def'
'$include:'input.inc'
'$include:'screen.def'
'$include:'screen.inc'
'$include:'com.def'
'$include:'com.inc'
'$include:'postcach.def'
'-- shared const variable
private PostCache.PostDataFileName$[20]
'------------------------------------------------------------
' queue post
'------------------------------------------------------------
function PostCache.Queue%(barcode$,num$,id$,func%)
private fileNum%:fileNum% = 4
private funcStr$[1]
funcStr$=mid$(str$(func%),2)
private flen&
'-- check file size
open PostCache.PostDataFileName$ AS #fileNum% RECORD PostCache.RECORDLEN
field #fileNum%, PostCache.BARCODELEN as barcode$, PostCache.NUMLEN as num$, PostCache.IDLEN as id$, PostCache.FUNCLEN as funcStr$
flen&=lof(#fileNum%)
close #fileNum%
if flen&>=PostCache.RECORDLEN then
private ret%
ret%=PostCache.Flush% '-- flush
flen&=0
end if
'-- add a request to queue
open PostCache.PostDataFileName$ AS #fileNum% RECORD PostCache.RECORDLEN
field #fileNum%, PostCache.BARCODELEN as barcode$, PostCache.NUMLEN as num$, PostCache.IDLEN as id$, PostCache.FUNCLEN as funcStr$
put #fileNum%, flen&+1
close #fileNum%
PostCache.Queue%=0
end function
'------------------------------------------------------------
' flush post
'------------------------------------------------------------
function PostCache.Flush%
private startTime$[8]
private endTime$[8]
startTime$ = time$ '-- start measuring
private ret$[Com.RECVSIZE]
private status%
status%=Com.Status.Init '-- init status
private fileNum%:fileNum% = 4
private barcode$[PostCache.BARCODELEN]
private num$[PostCache.NUMLEN]
private id$[PostCache.IDLEN]
private func$[PostCache.FUNCLEN]
private flen&
private idx&
idx&=1
open PostCache.PostDataFileName$ AS #fileNum% RECORD PostCache.RECORDLEN
field #fileNum%, PostCache.BARCODELEN as barcode$, PostCache.NUMLEN as num$, PostCache.IDLEN as id$, PostCache.FUNCLEN as func$
flen&=lof(#fileNum%)
if flen&>0 then
call Screen.Init
call Screen.Footer
locate 1,1
print "サーバーと同期してます..."
'-- state machine
while status%<>Com.Status.DeviceClosed
select status%
case Com.Status.Init
status%=Com.TcpIp.OpenDevice%(status%)
case Com.Status.DeviceOpened
status%=Com.TcpIp.Open%(status%)
case Com.Status.Opened
status%=Com.TcpIp.OpenSocket%(status%)
case Com.Status.SocketConnected
locate 1,3
print idx&;
print "/";
print flen&
print " "
get #fileNum%, idx&
if id$="" then
status%=Com.Http.SendData%(Com.Http.PostMode,Com.Http.URLPREFIX$+"/postItem.php","c="+barcode$+"&n="+num$+"&f="+func$,status%)
else
status%=Com.Http.SendData%(Com.Http.PostMode,Com.Http.URLPREFIX$+"/updateItem.php","c="+barcode$+"&n="+num$+"&id="+id$+"&f="+func$,status%)
end if
case Com.Status.DataSent
status%=Com.Http.RecvData%(ret$,status%)
case Com.Status.DataReceived
idx&=idx&+1
if idx&<=flen& then
status%=Com.Status.SocketConnected
else
status%=Com.Status.DataReceivedEnd
end if
case Com.Status.DataReceivedEnd
status%=Com.TcpIp.CloseSocket%(status%)
case Com.Status.SocketClosed
status%=Com.TcpIp.Close%(status%)
case Com.Status.Closed
status%=Com.TcpIp.CloseDevice%(status%)
end select
wend
clfile #fileNum% '-- delete file
call Screen.Init
call Screen.Footer
locate 1,1
print "サーバーとの同期が終了しました"
end if
close #fileNum%
PostCache.Flush% = 0
endTime$=time$
APP.ELAPSEDTIME% = Util.GetSeconds%(startTime$, endTime$)
APP.DEBUGMSG$ = ""
end function
'------------------------------------------------------------
' init
'------------------------------------------------------------
sub PostCache.Init
PostCache.PostDataFileName$="POST.DAT"
end sub