13
13
$ dest = $ argv [1 ];
14
14
$ cmd = $ argv [2 ];
15
15
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 " )
17
21
{
18
22
request_access_level ();
19
23
}
@@ -26,27 +30,50 @@ function usage()
26
30
{
27
31
echo "Usage: airmar.php <dest> <command> \n\n" ;
28
32
echo "where command is one of: \n" ;
33
+ echo " set-depth-offset <offset> in millimeters \n" ;
29
34
echo " request-access-level \n" ;
30
35
echo "and <dest> is the decimal device number of the Airmar sensor on the CAN bus, or 255 for broadcast \n" ;
31
36
exit (1 );
32
37
}
33
38
34
- function request_access_level ( )
39
+ function set_depth_offset ( $ offset )
35
40
{
36
41
global $ dest ;
37
42
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" ;
41
46
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 ]))
44
53
{
45
- echo "Looks like the sensor denied the request. \n" ;
54
+ echo "New depth sentence \n" ;
55
+ print_r ($ response [128267 ]);
46
56
}
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 ]))
48
75
{
49
- echo "Some response received \n" ;
76
+ echo "Airmar data received \n" ;
50
77
$ response = $ response ['65287 ' ];
51
78
print_r ($ response );
52
79
}
@@ -56,7 +83,7 @@ function n2k_request_response($request, $description = 'N2K')
56
83
{
57
84
$ errno = 0 ;
58
85
$ errstr = '' ;
59
- $ n2k = @fsockopen ('localhost ' , 2597 , & $ errno , & $ errstr , 15 );
86
+ $ n2k = @fsockopen ('localhost ' , 2597 , $ errno , $ errstr , 15 );
60
87
if (!$ n2k )
61
88
{
62
89
echo "Cannot connect to N2KD: $ errstr \n" ;
@@ -67,7 +94,11 @@ function n2k_request_response($request, $description = 'N2K')
67
94
# Ask for device list
68
95
#
69
96
70
- fwrite ($ n2k , $ request ."\n" );
97
+ if ($ request !== null )
98
+ {
99
+ fwrite ($ n2k , $ request ."\n" );
100
+ }
101
+ $ s = '' ;
71
102
while (!feof ($ n2k ))
72
103
{
73
104
$ s .= fgets ($ n2k , 1024 );
@@ -81,4 +112,26 @@ function n2k_request_response($request, $description = 'N2K')
81
112
}
82
113
return $ data ;
83
114
}
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
+ }
84
137
?>
0 commit comments