@@ -39,13 +39,19 @@ int main(int argc, char** argv)
3939 std::cout << " CAN socket bound to can0 interface successfully."
4040 << std::endl;
4141
42- Config config = Config::create_default ();
43- auto session = Session::open (std::move (config));
42+ auto config = Config::create_default ();
43+ if (argc == 2 )
44+ {
45+ config = Config::from_file (argv[1 ]);
46+ }
47+ auto session = Session::open (std::move (config));
4448
4549 auto pubSpeed =
4650 session.declare_publisher (KeyExpr (" seame/car/1/speedSensor" ));
4751 auto pubBattery =
4852 session.declare_publisher (KeyExpr (" seame/car/1/batterySensor" ));
53+ auto pubLights = session.declare_publisher (KeyExpr (" seame/car/1/lights" ));
54+ auto pubGear = session.declare_publisher (KeyExpr (" seame/car/1/gear" ));
4955
5056 while (1 )
5157 {
@@ -67,7 +73,7 @@ int main(int argc, char** argv)
6773 speed = wheelDiame * 3.14 * speed * 10 / 60 ;
6874 std::string speed_str = std::to_string (speed);
6975
70- printf (" Publishing speed: '%d'\n " , speed);
76+ // printf("Publishing speed: '%d'\n", speed);
7177 pubSpeed.put (speed_str.c_str ());
7278 }
7379 else if (frame.can_id == 0x02 )
@@ -80,9 +86,36 @@ int main(int argc, char** argv)
8086 battery = std::min (100 .0f , std::max (0 .0f , percentage));
8187 std::string battery_str = std::to_string (battery);
8288
83- printf (" Publishing battery: '%lf\n " , battery);
89+ // printf("Publishing battery: '%lf\n", battery);
8490 pubBattery.put (battery_str.c_str ());
8591 }
92+ else if (frame.can_id == 0x03 )
93+ {
94+ char lights;
95+
96+ memcpy (&lights, frame.data , sizeof (char ));
97+
98+ printf (" Can received lights: " );
99+ for (int i = 7 ; i >= 0 ; i--)
100+ {
101+ printf (" %d" , (lights >> i) & 0x01 );
102+ }
103+ printf (" \n " );
104+
105+ // printf("Publishing lights: '%lf\n", lights[0]);
106+ std::string light_str (1 , lights);
107+ pubLights.put (light_str);
108+ }
109+ else if (frame.can_id == 0x04 )
110+ {
111+ char gear;
112+
113+ memcpy (&gear, frame.data , sizeof (char ));
114+
115+ // printf("Publishing gear: '%lf\n", gear[0]);
116+ std::string gear_str (1 , gear);
117+ pubGear.put (std::to_string (gear_str));
118+ }
86119 usleep (10 );
87120 }
88121 return 0 ;
0 commit comments