Эх сурвалжийг харах

Improve status encoding -- allow more characters and improve human readability

Zachary Kotlarek 13 жил өмнө
parent
commit
c227ee1edc
4 өөрчлөгдсөн 24 нэмэгдсэн , 15 устгасан
  1. 9 9
      dmx/DMX.pm
  2. 11 1
      dmx/debug.pl
  3. 1 1
      dmx/rifftrax.pl
  4. 3 4
      dmx/state.pl

+ 9 - 9
dmx/DMX.pm

@@ -122,8 +122,7 @@ sub stateSocket($) {
 # Parse the state->client comm string
 # Parse the state->client comm string
 sub parseState($$$) {
 sub parseState($$$) {
 	my ($text, $exists, $mtime) = @_;
 	my ($text, $exists, $mtime) = @_;
-	my $cmdState    = undef();
-	my $exists_text = undef();
+	my $cmdState = undef();
 	if (!defined($exists)) {
 	if (!defined($exists)) {
 		my %tmp = ();
 		my %tmp = ();
 		$exists = \%tmp;
 		$exists = \%tmp;
@@ -136,14 +135,15 @@ sub parseState($$$) {
 	# Parse the string
 	# Parse the string
 	%{$exists} = ();
 	%{$exists} = ();
 	%{$mtime}  = ();
 	%{$mtime}  = ();
-	($cmdState, $exists_text) = $text =~ /^(\w+)(?:\s+\(([^\)]+)\))?/;
+	my @lines = split("\n", $text);
+	$cmdState = shift(@lines);
 	if (!defined($cmdState)) {
 	if (!defined($cmdState)) {
 		print STDERR 'State parse error: ' . $text . "\n";
 		print STDERR 'State parse error: ' . $text . "\n";
 		next;
 		next;
 	}
 	}
-	if (defined($exists_text)) {
-		foreach my $exists_val (split(/\s*,\s*/, $exists_text)) {
-			my ($name, $value, $time) = $exists_val =~ /(\w+)\:([^\,\:]*)\:(\d*)/;
+	if (scalar(@lines)) {
+		foreach my $line (@lines) {
+			my ($name, $value, $time) = $line =~ /(\w+)\|([^|]*)\|(\d*)/;
 			if (!defined($name) || !defined($value) || !defined($time)) {
 			if (!defined($name) || !defined($value) || !defined($time)) {
 				print STDERR 'State parse error (exists): ' . $text . "\n";
 				print STDERR 'State parse error (exists): ' . $text . "\n";
 				next;
 				next;
@@ -154,10 +154,10 @@ sub parseState($$$) {
 	}
 	}
 	if ($DEBUG) {
 	if ($DEBUG) {
 		my @exists_tmp = ();
 		my @exists_tmp = ();
-		foreach my $key (keys(%{$exists})) {
-			push(@exists_tmp, $key . ':' . $exists->{$key} . ':' . $mtime->{$key});
+		foreach my $key (sort(keys(%{$exists}))) {
+			push(@exists_tmp, $key . ":\t" . $exists->{$key} . ' @ ' . $mtime->{$key});
 		}
 		}
-		print STDERR 'Got state: ' . $cmdState . ' (' . join(', ', @exists_tmp) . ")\n";
+		print STDERR 'Got state: ' . $cmdState . "\n" . join("\n", @exists_tmp) . "\n";
 	}
 	}
 
 
 	# Translate INIT to OFF
 	# Translate INIT to OFF

+ 11 - 1
dmx/debug.pl

@@ -30,12 +30,22 @@ while (1) {
 	my $state = DMX::readState($DELAY, \%exists, \%mtime, undef());
 	my $state = DMX::readState($DELAY, \%exists, \%mtime, undef());
 
 
 	if ($state) {
 	if ($state) {
+
+		# Find the latest modification timestamp
 		my $file = undef();
 		my $file = undef();
 		foreach my $key (keys(%mtime)) {
 		foreach my $key (keys(%mtime)) {
 			if (!defined($file) || $mtime{$key} > $mtime{$file}) {
 			if (!defined($file) || $mtime{$key} > $mtime{$file}) {
 				$file = $key;
 				$file = $key;
 			}
 			}
 		}
 		}
-		print STDERR "\tLast update: " . $file . ': ' . localtime($mtime{$file}) . "\n";
+
+		# Pretty print
+		my $time = 0;
+		if (defined($file)) {
+			$time = $mtime{$file};
+		} else {
+			$file = '<NO MTIME DATA>';
+		}
+		print STDERR "\tLast update: " . $file . ': ' . localtime($time) . "\n";
 	}
 	}
 }
 }

+ 1 - 1
dmx/rifftrax.pl

@@ -219,7 +219,7 @@ while (1) {
 		my $videoTime = $exists{'PLAYING_POSITION'};
 		my $videoTime = $exists{'PLAYING_POSITION'};
 
 
 		# Convert to seconds
 		# Convert to seconds
-		my @parts = split(/\-/, $videoTime);
+		my @parts = split(/\:/, $videoTime);
 		$videoTime = 0;
 		$videoTime = 0;
 		if (scalar(@parts) == 3) {
 		if (scalar(@parts) == 3) {
 			$videoTime = ($parts[0] * 3600) + ($parts[1] * 60) + $parts[2];
 			$videoTime = ($parts[0] * 3600) + ($parts[1] * 60) + $parts[2];

+ 3 - 4
dmx/state.pl

@@ -333,11 +333,10 @@ while (1) {
 		foreach my $file (values(%files)) {
 		foreach my $file (values(%files)) {
 			my $text = $file->{'status'};
 			my $text = $file->{'status'};
 			$text =~ s/\s/ /g;
 			$text =~ s/\s/ /g;
-			$text =~ s/[\,\(\)]/_/g;
-			$text =~ s/\:/-/g;
-			push(@statTime, $file->{'name'} . ':' . $text . ':' . $file->{'update'});
+			$text =~ s/\|/-/g;
+			push(@statTime, $file->{'name'} . '|' . $text . '|' . $file->{'update'});
 		}
 		}
-		$status = ' (' . join(', ', @statTime) . ')';
+		$status = "\n" . join("\n", @statTime);
 	}
 	}
 
 
 	# Clear EXISTS_CLEAR files immediately (but after we append their status)
 	# Clear EXISTS_CLEAR files immediately (but after we append their status)