//something changed in shm for ($i = 0; $i < 128; $i++) { if (substr($do1, $i * 2, 2) != substr($dmx_outputs1, $i * 2, 2)) { //send xap dmx level change message for universe 1 send_dmx_output_level_event_message($i, XAPSRC_DMX_OUT1, XAPUID_DMX_OUT1, $do1, $donames1); $outs1_changed = 1; } if (substr($do2, $i * 2, 2) != substr($dmx_outputs2, $i * 2, 2)) { //send xap dmx level change message for universe 2 send_dmx_output_level_event_message($i, XAPSRC_DMX_OUT2, XAPUID_DMX_OUT2, $do2, $donames2); $outs2_changed = 1; } } } if ($outs1_changed) { $dmx_outputs1 = $do1; dmx_set_levels_U1(bcd_to_chr($dmx_outputs1)); } if ($outs2_changed) { $dmx_outputs2 = $do2; dmx_set_levels_U2(bcd_to_chr($dmx_outputs2)); } usleep(5000); } } dmx_set_dmx_receive_mode(SEND_ON_CHANGE_ONLY); dmx_close(); dmx_write_state_file($dstate_file, $dmx_inputs, $dmx_outputs1, $dmx_outputs2); socket_close($xap_sock_in); shmop_close($shm_id); logformat("hac_dmx exiting cleanly.\n");
$debug = $args['debug']; } else { $debug = 0; } exec('stty -F /dev/ttyUSB0 115200 raw -echo'); if ($dmx = fopen('/dev/ttyUSB0', 'w+')) { dmx_set_levels(''); $d1 = str_pad('', 128, chr(0)); $d2 = str_pad('', 128, chr(0)); dmx_set_levels_U1($d1); dmx_set_levels_U2($d2); $t = microtime(true); for ($i = 0; $i <= 255; $i++) { $d1 = str_pad('', 128, chr($i)); $d2 = str_pad('', 128, chr(255 - $i)); dmx_set_levels_U1($d1); dmx_set_levels_U2($d2); if ($must_exit) { break; } } fclose($dmx); } print microtime(true) - $t . "seconds\n"; function dmx_write($cmd, $s, $data) { global $debug, $dmx; $sLSB = $s % 256; $sMSB = floor($s / 256); $packet = chr(DMX_START_BYTE) . chr($cmd) . chr($sLSB) . chr($sMSB) . $data . chr(DMX_END_BYTE); if ($debug) {
} else { $debug = 0; } $read_buffer = str_pad('', 519, chr(0)) . chr(DMX_END_BYTE); if (!($fw = dmx_connect())) { printf("Buffer: %s\n", hex_display($read_buffer)); die("Could not talk to DMX Interface!\n"); } printf("Firmware Version: %s\n", $fw['FW_VER']); printf("DMX Output Break Time: %s x 10.67 = %.02f us\n", $fw['DMX_BR_TIME'], $fw['DMX_BR_TIME'] * 10.67); printf("DMX Mark After Break Time: %s x 10.67 = %.02f us\n", $fw['DMX_MABR_TIME'], $fw['DMX_MABR_TIME'] * 10.67); printf("DMX Output Rate: %s packets/sec\n", $fw['DMX_OUTPUT_RATE']); printf("DMX Config Data: %s\n", $fw['CONFIG_DATA']); $dmx_input = str_pad('', 128, chr(0)); $data = str_pad('', 128, chr(0)); dmx_set_levels_U1($data); dmx_set_levels_U2($data); //dmx_set_dmx_receive_mode(SEND_ALWAYS); dmx_set_dmx_receive_mode(SEND_ON_CHANGE_ONLY); while (1) { if ($must_exit) { break; } if (dmx_read($read_buffer)) { //got some input from the interface while ($packet = dmx_get_next_packet($read_buffer)) { if ($p = dmx_get_dmx_rx_data($packet)) { if ($debug) { printf("DMX Received: %s\n", hex_display($p)); } }