-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcmd2jura.pl
executable file
·100 lines (89 loc) · 3.25 KB
/
cmd2jura.pl
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
#!/usr/bin/perl
#
# cmd2jura.pl, V1.00
#
# Send control commands to a Jura coffee machine via the (serial) maintenance port
#
# (C) 2016 Hajo Noerenberg
#
# http://www.noerenberg.de/
# https://github.com/hn/jura-coffee-machine
#
# The Jura protocol has been reverse engineered by the guys from http://protocol-jura.do.am
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3.0 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>.
#
# apt-get install libdevice-serialport-perl
use strict;
use Time::HiRes qw(usleep);
use Device::SerialPort qw( :PARAM :STAT 0.07 );
my $port="/dev/ttyAMA0"; # Raspberry GPIO UART: Pin6=GND, Pin8=TXD, Pin10=RXD
my $sp;
sub cmd2jura {
foreach my $outbyte ( split( //, shift() . "\r\n" ) ) {
my $outbits = unpack( 'b8', $outbyte );
for ( my $i = 0 ; $i < 7 ; $i += 2 ) {
$sp->write(
pack( 'b8', '11' . substr( $outbits, $i + 0, 1 ) . '11' . substr( $outbits, $i + 1, 1 ) . '11' )
);
}
usleep( 8 * 1000 );
}
my $inbytes;
my $inbits;
my $stime = time();
while ( substr( $inbytes, -2 ) ne "\r\n" ) {
my ( $count, $rawbyte ) = $sp->read(1);
if ( $count > 0 ) {
my $rawbits = unpack( 'b8', $rawbyte );
$inbits .= substr( $rawbits, 2, 1 ) . substr( $rawbits, 5, 1 );
if ( length($inbits) == 8 ) {
$inbytes .= pack( 'b8', $inbits );
$inbits = undef;
}
} else {
usleep( 42 * 1000 );
}
if ( $stime + 5 < time() ) {
print STDERR "Timeout reading result\n";
return undef;
}
}
return $inbytes;
}
if ( not defined $ARGV[0] ) {
print STDERR "Usage: $0 <cmd>\n";
print STDERR "Where <cmd> is a valid Jura control command depending on ";
print STDERR "machine type, try searching the web for more information):\n";
print STDERR " TY: = get type of machine\n";
print STDERR " AN:01 = turn machine on\n";
print STDERR " AN:02 = turn machine off\n";
print STDERR " RE:xx = read EEPROM word at address xx (00 .. 7F)\n";
print STDERR " RT:xx = read EEPROM line (16 words) at address xx (00 .. 70)\n";
print STDERR " RR:xx = read RAM line (16 bytes) at address xx (00 .. F0)\n";
print STDERR " FA:xx = product e.g. coffee small, large, steam, flush (01 .. )\n";
print STDERR " FN:xx = mechanical components on/off e.g. pump, heat, grinder (01 .. )\n";
print STDERR " [...]\n";
print STDERR "WARNING: Wrong commands may damage your machine permanently!\n";
exit 64;
}
$sp = new Device::SerialPort($port) || die "Can't open serial port: $!";
$sp->baudrate(9600);
$sp->databits(8);
$sp->parity("none");
$sp->stopbits(1);
$sp->handshake('none');
$sp->write_settings;
print cmd2jura( $ARGV[0] );
$sp->close;