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
packet = bytearray(0x30)
if timezone < 0:
packet[0x08] = 0xff + timezone - 1
packet[0x09] = 0xff
packet[0x0a] = 0xff
packet[0x0b] = 0xff
else:
packet[0x08] = timezone
packet[0x09] = 0
packet[0x0a] = 0
packet[0x0b] = 0
packet[0x0c] = year & 0xff
packet[0x0d] = year >> 8
packet[0x0e] = datetime.now().minute
packet[0x0f] = datetime.now().hour
subyear = str(year)[2:]
packet[0x10] = int(subyear)
packet[0x11] = datetime.now().isoweekday()
packet[0x12] = datetime.now().day
packet[0x13] = datetime.now().month
packet[0x18] = int(address[0])
packet[0x19] = int(address[1])
packet[0x1a] = int(address[2])
packet[0x1b] = int(address[3])
packet[0x1c] = port & 0xff
packet[0x1d] = port >> 8
packet[0x26] = 6
checksum = 0xbeaf
packet[0x26] = 6
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
use integer; my @datetime = localtime(); my $year = $datetime[5]+1900; my $timezone = 1; my $port = 80; my @address=(192,168,0,42); my @data = ( (0) x 39 ); if($timezone < 0 ) { $data[8] = 255 + $timezone - 1; @data[9,10,11] = ( 255,255,255 ); } else { $data[8] = $timezone; @data[9,10,11] = ( 0,0,0 ); } $data[12] = $year & 255; $data[13] = $year >> 8; $data[14] = $datetime[1]; $data[15] = $datetime[2]; $data[16] = int(substr($year,2)); $data[17] = $datetime[6]; $data[18] = $datetime[3]; $data[19] = $datetime[4]+1; $data[24] = int($address[0]); $data[25] = int($address[1]); $data[26] = int($address[2]); $data[27] = int($address[3]); $data[28] = $port & 255; $data[29] = $port >> 8; $data[38] = 6; my $packet = pack('C*',@data);
my @data = unpack('C*',$packet);
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
my @datetime = localtime(); my $year = $datetime[5]+1900; my $timezone = 1; my $port = 80; my @address=(168,191,0,1); my @data = ( (0) x 37 ); my @form = ( ('C') x 37 ); if($timezone < 0 ) { $data[8] = 255 + $timezone - 1; @data[9,10,11] = ( 255,255,255 ); } else { $data[8] = $timezone; @data[9,10,11] = ( 0,0,0 ); } $data[12] = $year; $form[12] = 'v'; $data[13] = $datetime[1]; $data[14] = $datetime[2]; $data[15] = int(substr($year,2)); $data[16] = $datetime[6]; $data[17] = $datetime[3]; $data[18] = $datetime[4]+1; $data[23] = int($address[0]); $data[24] = int($address[1]); $data[25] = int($address[2]); $data[26] = int($address[3]); $data[27] = $port; $form[27] = 'v'; $data[36] = 6; my $packet = pack(join('',@form),@data);
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
my($timezone) = (timegm(localtime(time)) - timelocal(localtime(time))) / -3600;
my($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
$year += 1900;
my @data = ((0) x 39);
if($timezone < 0 ) {
$data[8] = 255 + $timezone - 1;
@data[9, 10, 11] = (255, 255, 255);
} else {
$data[8] = $timezone;
@data[9, 10, 11] = (0, 0, 0);
}
$data[12] = $year & 255;
$data[13] = $year >> 8;
$data[14] = $min;
$data[15] = $hour;
$data[16] = $year - 1900;
$data[17] = $wday;
$data[18] = $yday;
$data[19] = $mon;
$data[24] = int($ipSeg1);
$data[25] = int($ipSeg2);
$data[26] = int($ipSeg3);
$data[27] = int($ipSeg4);
$data[28] = $port & 255;
$data[29] = $port >> 8;
$data[38] = 6;
my($packet) = pack('C*', @data);
Character in 'C' format wrapped in pack at broadlink.pl line ...
QuoteCharacter in 'C' format wrapped
my $bin = pack "C*", 256;
$seq = pack "CCCC", 1,2,3,4;