package Kiosk; # This implements communications to a VNE kiosk as an HTTP server # based on VNE JSON Communication Protocol Ver. 1.8 # Alessandro: add to protocol: change PIN? There is no card removed message use strict; use Device::SerialPort; #use Data::CISerializer; #use MIME::Base64; #use JSON; use Time::HiRes qw(usleep gettimeofday tv_interval time); use Data::Dumper; use Debug; use GetConfiguration; use Database; use DatabaseProcesses; $|=1; sub new { my ($class, $placard, $server, $debug_level) = @_; # config is a data structure that has serial setup information my $self = {}; $self->{me} = 'Kiosk'; $self->{class} = $class; $self->{placard} = $placard; $self->{server} = $server; $self->{debug} = Debug->new($placard, "MAIN_$placard", $debug_level); $self->{config} == GetConfiguration->new($self->{debug}, '/etc/cashcade/cashcade.conf'); $self->{debug}->prt(9, "KIOSK Config " . Dumper($self->{config}), 'KIOSK'); $self->{dbcomm} = Database->new($self->{debug}, $self->{configuration}->{config}->{local_db}); # the DB connection must go first and succeed $self->{dbcomm}->connect(); die "Database unable to connect!" if (!$self->{dbcomm}->{connected}); print "Database Connected\n"; $self->{dbproc} = DatabaseProcesses->new($self->{debug}, $self->{dbcomm}); $self->{maxDeposit} = $self->{config}->{maxDepositCents}; $self->{maxWithdraw} = $self->{config}->{maxWithdrawCents}; $self->{debug}->prt(2, "KIOSK CONFIG: kiosk_id=$self->{kiosk_id} maxDeposit=$self->{maxDeposit} maxWithdraw=$self->{maxWithdraw}", 'KIOSK INIT'); $self->{connected} = 0; $self->{verbose} = 0; $self->{kiosk_id} = $self->{dbproc}->get_kiosk_sysid_from_placard($self->{placard}); $self->{card_number} = 0; # this is the latest card number seen $self->{account_id} = 0; # this is the account id while the card is in the reader of the kiosk $self->{account_value} = 0; # value of account in cents $self->{response} = ''; $self->{server}->run(); bless($self,$class); return $self; } sub process { my ($self, $msg) = @_; # $msg is the pointer to the incoming message json hash # { "type":"cardCheck", "date":"1482307795601", "lang": "EN", "machineName":"PLUSMAKM", "cardNumber":"1234567890", "PIN": "1234" } # TODO: is message for this machine $msg->{machineName} # TODO: is date of message reasonable $msg->{date} $self->{response} = ''; if ( $msg->{type} eq 'cardCheck') { return $self->card_was_inserted($msg); } if ( $msg->{type} eq 'cardLoad') { return $self->deposit_amount_received($msg); } if ( $msg->{type} eq 'cardWithdrawal') { return $self->withdrawal_amount_requested($msg); } }