1+ /*
2+ Arlo Serial through fdserial.c
3+ */
4+
5+ #include "simpletools.h"
6+ #include "fdserial.h"
7+
8+ #define SERVO_L 12
9+
10+ char dhb10_reply [48 ];
11+ char * reply ;
12+
13+ fdserial * arlo ;
14+
15+ char * config (void );
16+
17+ int main ()
18+ {
19+ arlo = fdserial_open (SERVO_L , SERVO_L , 0b1100 , 19200 );
20+ pause (10 );
21+
22+ print ("SPEED & DISTANCE\n\n" );
23+ print ("To DHB-10 From DHB-10\n" );
24+ print ("------------- ----------------\n" );
25+
26+ print ("gospd 32 32\\r " );
27+ dprint (arlo , "gospd 32 32\r" );
28+ reply = config ();
29+ if (* reply == '\r' ) print ("\\r\n" );
30+ else print ("%s" , reply );
31+
32+ pause (2000 );
33+
34+ print ("gospd 0 0\\r " );
35+ dprint (arlo , "gospd 0 0\r" );
36+ reply = config ();
37+ if (* reply == '\r' ) print ("\\r\n" );
38+ else print ("%s" , reply );
39+
40+ // Display distance reply as text
41+ print ("dist\\r " );
42+ dprint (arlo , "dist\r" );
43+ reply = config ();
44+ if (* reply == '\r' ) print ("\\r\n" );
45+ else print ("%s" , reply );
46+
47+ print ("------------- ----------------\n" );
48+
49+ // Convert distance reply text to numeric values to use in
50+ // calculations, and display the results stored by int variables.
51+ int countLeft , countRight ;
52+ print ("\nVARIABLE VALUES\n" , reply );
53+ sscan (reply , "%d%d" , & countLeft , & countRight );
54+ print ("countLeft = %d, countright = %d\n" , countLeft , countRight );
55+ }
56+
57+ char * config (void )
58+ {
59+ memset (dhb10_reply , 0 , 48 );
60+ int i = 0 , cta = 0 , ca = 0 ;
61+ int t = CNT ;
62+ int dt = CLKFREQ ;
63+ while (1 )
64+ {
65+ cta = fdserial_rxCount (arlo );
66+ if (cta )
67+ {
68+ ca = readChar (arlo );
69+ dhb10_reply [i ] = ca ;
70+ if (dhb10_reply [i ] == '\r' )
71+ {
72+ reply = dhb10_reply ;
73+ break ;
74+ }
75+ i ++ ;
76+ }
77+ if (CNT - t > dt )
78+ {
79+ * reply = 0 ;
80+ break ;
81+ }
82+ }
83+ return reply ;
84+ }
0 commit comments