Skip to content

Commit d4a02c1

Browse files
committed
Add capability to set depth offset for Airmar DST 200/800 transducers
1 parent 2198da2 commit d4a02c1

File tree

1 file changed

+65
-12
lines changed

1 file changed

+65
-12
lines changed

airmar/airmar.php

+65-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
$dest = $argv[1];
1414
$cmd = $argv[2];
1515

16-
if ($cmd == "request-access-level")
16+
if ($cmd == "set-depth-offset" && $argc == 4)
17+
{
18+
set_depth_offset($argv[3]);
19+
}
20+
else if ($cmd == "request-access-level")
1721
{
1822
request_access_level();
1923
}
@@ -26,27 +30,50 @@ function usage()
2630
{
2731
echo "Usage: airmar.php <dest> <command>\n\n";
2832
echo "where command is one of:\n";
33+
echo " set-depth-offset <offset> in millimeters\n";
2934
echo " request-access-level\n";
3035
echo "and <dest> is the decimal device number of the Airmar sensor on the CAN bus, or 255 for broadcast\n";
3136
exit(1);
3237
}
3338

34-
function request_access_level()
39+
function set_depth_offset($offset)
3540
{
3641
global $dest;
3742

38-
# Usage: ./rel/linux-i586/send-group-function <dest> <prio> <pgn> <field>=<value> ...
39-
$command = shell_exec("/usr/local/bin/send-group-function $dest 5 65287 1=135 3=4");
40-
echo $command;
43+
$command = shell_exec("command-group-function $dest 5 128267 3=" . sprintf("%04x", $offset));
44+
$analyzed = shell_exec("echo '$command' | analyzer 2>/dev/null");
45+
echo "Sending request to device $dest: $analyzed\n";
4146

42-
$response = n2k_request_response($command, 'Request Access Level');
43-
if (is_array($response[126208][$dest."_0"]))
47+
$response = n2k_request_response($command, 'set-depth-offset');
48+
show_command_response($response);
49+
50+
Sleep(0.2);
51+
$response = n2k_request_response(null, 'set-depth-offset');
52+
if (array_key_exists(128267, $response) && is_array($response[128267]))
4453
{
45-
echo "Looks like the sensor denied the request.\n";
54+
echo "New depth sentence\n";
55+
print_r($response[128267]);
4656
}
47-
if (is_array($response[65287]))
57+
}
58+
59+
function request_access_level()
60+
{
61+
global $dest;
62+
63+
$command = shell_exec("command-group-function $dest 5 65287 1=0087 3=04");
64+
echo "Sending request to device $dest to report PGN 65287: $command\n";
65+
$analyzed = shell_exec("echo '$command' | analyzer 2>/dev/null");
66+
echo "Sending request to device $dest to report PGN 65287: $analyzed\n";
67+
68+
$response = n2k_request_response($command, 'Request Access Level');
69+
70+
echo "Response: ".print_r($response);
71+
72+
show_command_response($response);
73+
74+
if (array_key_exists(65287, $response) && is_array($response[65287]))
4875
{
49-
echo "Some response received\n";
76+
echo "Airmar data received\n";
5077
$response = $response['65287'];
5178
print_r($response);
5279
}
@@ -56,7 +83,7 @@ function n2k_request_response($request, $description = 'N2K')
5683
{
5784
$errno = 0;
5885
$errstr = '';
59-
$n2k = @fsockopen('localhost', 2597, &$errno, &$errstr, 15);
86+
$n2k = @fsockopen('localhost', 2597, $errno, $errstr, 15);
6087
if (!$n2k)
6188
{
6289
echo "Cannot connect to N2KD: $errstr\n";
@@ -67,7 +94,11 @@ function n2k_request_response($request, $description = 'N2K')
6794
# Ask for device list
6895
#
6996

70-
fwrite($n2k, $request."\n");
97+
if ($request !== null)
98+
{
99+
fwrite($n2k, $request."\n");
100+
}
101+
$s = '';
71102
while (!feof($n2k))
72103
{
73104
$s .= fgets($n2k, 1024);
@@ -81,4 +112,26 @@ function n2k_request_response($request, $description = 'N2K')
81112
}
82113
return $data;
83114
}
115+
116+
function show_command_response($response)
117+
{
118+
global $dest;
119+
120+
if (array_key_exists(126208, $response) && is_array($response[126208]))
121+
{
122+
if (array_key_exists($dest, $response[126208]) && is_array($response[126208][$dest]))
123+
{
124+
$fields = $response[126208][$dest]['fields'];
125+
echo "Device response: ". $fields['Function Code'] . " for PGN " . $fields['PGN'];
126+
if ($fields['Parameter Error'] != 0)
127+
{
128+
echo " - ERROR\n";
129+
}
130+
else
131+
{
132+
echo " - OK\n";
133+
}
134+
}
135+
}
136+
}
84137
?>

0 commit comments

Comments
 (0)