-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
121 lines (97 loc) · 2.82 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "Aesimhei.h"
#include <windows.h>
#include <winver.h>
int getMoney(int amount);
int payMoney(int amount);
void disableCoinChannels(int channels[]);
int main( int argc, char * argv [] ){
int OpenStatus = OpenMHE ();
if(OpenStatus != 0){
printf("ERROR, Paylink device not connected." );
fflush(stdout);
return 1;
}
//checking whether correct number of arguments
if(argc <3){
printf("ERROR, nothing to do." );
fflush(stdout);
return 1;
}
//calling disableCoinChannels() function
if(argc == 4){
if(strlen(argv[3]) == 8){
int channels[8];
int j;
for( j= 0; j < 8; j++){
if(argv[3][j] - '0' == 1){
channels[j] = argv[3][j] - '0';
}else channels[j] = 0;
}
disableCoinChannels(channels);
}
}
//calling getMoney() function
if(!strncmp(argv[1], "getMoney", 8)){
getMoney(atoi(argv[2]));
}
//calling payMoney() function
if(!strncmp(argv[1], "payMoney", 8)){
payMoney(atoi(argv[2]));
}
return 0;
}
int getMoney(int amount){
int LastCurrencyValue = CurrentValue() ;
int NewCurrencyValue;
EnableInterface() ;
while (amount > 0){
NewCurrencyValue = CurrentValue() ;
if (NewCurrencyValue != LastCurrencyValue){
//printf("The user has just inserted %d \n", NewCurrencyValue - LastCurrencyValue) ;
printf("%d", NewCurrencyValue - LastCurrencyValue) ;
fflush(stdout);
LastCurrencyValue = NewCurrencyValue ;
amount =0;//--amount;
}
Sleep(100) ;
}
DisableInterface();
return 0;
}
int payMoney(int amount){
//long CurrentPayOut;
long initialValue = CurrentPaid();
EnableInterface();
PayOut(amount) ;
while (LastPayStatus() == PAY_ONGOING){
if (CurrentPayOut != CurrentPaid()){
//CurrentPayOut = CurrentPaid() ;
//printf("CurrentPayOut %ld\n", CurrentPaid()) ;
}
Sleep(100) ;
}
printf("%ld", CurrentPaid() - initialValue) ;
if (LastPayStatus() != PAY_FINISHED){
printf("Error %d \n", LastPayStatus()) ;
}
//else{
// printf("PAY FINISHED\n") ;
//}
DisableInterface();
return 0;
}
//Enabel Coin Channels
void disableCoinChannels(int channels[]){
AcceptorBlock AcceptorDetails ;
int AcceptorNo ;
int CoinNo ;
for (AcceptorNo = 0 ; ReadAcceptorDetails(AcceptorNo, &AcceptorDetails) ; ++ AcceptorNo){
for (CoinNo = 0 ; CoinNo < AcceptorDetails.NoOfCoins ; ++CoinNo){
AcceptorDetails.Coin[CoinNo].Inhibit = channels[CoinNo];
WriteAcceptorDetails(AcceptorNo, &AcceptorDetails );
}
}
}