11
2- #include < stdio.h>
3- #include " pico/stdlib.h"
2+ // #include "hardware/i2c.h"
43#include " pico/binary_info.h"
5- #include " hardware/i2c .h"
4+ #include " pico/stdlib .h"
65#include " tusb.h"
76#include < mv.h>
7+ #include < stdio.h>
88
9+ #include " pico/cyw43_arch.h"
10+
11+ constexpr uint32_t DD0_PIN = 2 ;
12+ constexpr uint32_t DD1_PIN = 3 ;
13+ constexpr uart_pins_t UART0PINS = uart0_pins[1 ];
14+ constexpr uart_pins_t UART1PINS = uart1_pins[0 ];
15+
16+ // UART -----------------------------------------------------------
17+ pico_uart_set (UART0PINS);
18+ pico_uart_set (UART1PINS);
19+ bi_decl (bi_1pin_with_func(DD0_PIN, GPIO_FUNC_SIO));
920
1021int main () {
1122 // Enable UART so we can print status output
1223 stdio_init_all ();
24+ // stdio_usb_init(); // do this in cmake right now
25+ // pico_stdio_uart(); // do this in cmake right now
1326
27+ // wait for usb serial connection
1428 while (!tud_cdc_connected ()) {
15- printf (" w" );
1629 sleep_ms (500 );
1730 }
1831
32+ cyw43_arch_init ();
33+
34+ // Protocol1::PacketDecoder dec;
35+
1936 ServoPort s;
37+ uint32_t baud = s.open (UART0PINS,DD0_PIN);
2038
21- uint8_t data[] = {1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,0 };
22- s.write (data, 10 );
23- s.read (data, 10 );
24- s.write (data, 10 );
25- s.read (data, 10 );
26- s.write (data, 10 );
27- s.read (data, 10 );
28- s.write (data, 10 );
29- s.read (data, 10 );
30- s.write (data, 10 );
31- s.read (data, 10 );
32- s.write (data, 10 );
33- s.read (data, 10 );
39+ ServoPort ss;
40+ uint32_t baud2 = ss.open (UART1PINS,DD1_PIN);
41+
42+ mvpkt_t serv = AX12::makeMovePacket (1 ,140 .0f );
43+ s.write (serv);
3444
3545 while (1 ) {
36- printf (" ." );
46+ printf (" ServoPort at: %d %d\n " , (int )baud, (int )baud2);
47+
48+ mvpkt_t outpkt = Protocol1::makePingPacket ();
49+
50+ s.write (outpkt);
51+ s.write (outpkt);
52+ s.write (outpkt);
53+ s.write (outpkt);
54+ s.write (outpkt);
55+
56+ s.write (outpkt);
57+ s.write (outpkt);
58+ s.write (outpkt);
59+ s.write (outpkt);
60+ s.write (outpkt);
61+
62+ mvpkt_t inpkt = ss.read ();
63+ if (inpkt.size () > 0 ) {
64+ // printf("inpkt size: %d\n", (int)inpkt.size());
65+ // for (const uint8_t &b: inpkt) printf("%d,", (int)b);
66+ // printf("\n");
67+ mvpkts_t recv;
68+ bool ok = Protocol1::parsePacket (inpkt, recv);
69+ printf (" messages found UART 1: %s %d\n " , ok ? " ok" : " bad" , (int )recv.size ());
70+ }
71+ else printf (" *** inpkt no data on UART 1 ***\n " );
72+
73+
74+ mvpkt_t inpkt2 = s.read ();
75+ if (inpkt2.size () > 0 ) {
76+ // printf("inpkt2 size: %d\n", (int)inpkt2.size());
77+ // for (const uint8_t &b: inpkt2) printf("%d,", (int)b);
78+ // printf("\n");
79+ mvpkts_t recv2;
80+ bool ok = Protocol1::parsePacket (inpkt2, recv2);
81+ printf (" messages found UART 0: %s %d\n " , ok ? " ok" : " bad" , (int )recv2.size ());
82+ }
83+ else printf (" *** inpkt2 no data on UART 0 ***\n " );
84+
3785 sleep_ms (1000 );
3886 }
3987}
0 commit comments