2323
2424rev::usb::CandleWinUSBDriver* driver = new rev::usb::CandleWinUSBDriver();
2525std::map<std::string, std::shared_ptr<rev::usb::CANDevice>> CANDeviceMap;
26- std::map<std::string, uint8_t *> SparkMaxHeartbeatData;
2726std::set<std::string> devicesRegisteredToHal;
2827bool halInitialized = false ;
2928uint32_t m_notifier;
@@ -39,7 +38,6 @@ void removeExtraDevicesFromDeviceMap(std::vector<std::string> descriptors) {
3938 }
4039 if (!inDevices) {
4140 CANDeviceMap.erase (itr->first );
42- SparkMaxHeartbeatData.erase (itr->first );
4341 }
4442 }
4543}
@@ -50,8 +48,6 @@ bool addDeviceToMap(std::string descriptor) {
5048 std::unique_ptr<rev::usb::CANDevice> canDevice = driver->CreateDeviceFromDescriptor (descriptor_chars);
5149 if (canDevice != nullptr ) {
5250 CANDeviceMap[descriptor] = std::move (canDevice);
53- uint8_t heartbeat[] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
54- SparkMaxHeartbeatData[descriptor] = heartbeat;
5551 return true ;
5652 }
5753 return false ;
@@ -600,20 +596,18 @@ void setSparkMaxHeartbeatData(const Napi::CallbackInfo& info) {
600596 std::string descriptor = info[0 ].As <Napi::String>().Utf8Value ();
601597 Napi::Array dataParam = info[1 ].As <Napi::Array>();
602598
603- auto heartbeatIterator = SparkMaxHeartbeatData.find (descriptor);
604- if (heartbeatIterator == SparkMaxHeartbeatData.end ()) return ;
605-
599+ uint8_t heartbeat[] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
606600 auto deviceIterator = CANDeviceMap.find (descriptor);
607601 if (deviceIterator == CANDeviceMap.end ()) return ;
608- _sendCANMessage (descriptor, 0x2052C80 , heartbeatIterator-> second , 8 , -1 );
602+ _sendCANMessage (descriptor, 0x2052C80 , heartbeat , 8 , -1 );
609603 std::this_thread::sleep_for (std::chrono::milliseconds (50 ));
610604
611605 int sum = 0 ;
612606 for (uint32_t i = 0 ; i < dataParam.Length (); i++) {
613- heartbeatIterator-> second [i] = dataParam.Get (i).As <Napi::Number>().Uint32Value ();
614- sum+= heartbeatIterator-> second [i];
607+ heartbeat [i] = dataParam.Get (i).As <Napi::Number>().Uint32Value ();
608+ sum+= heartbeat [i];
615609 }
616610
617- if (sum == 0 ) _sendCANMessage (descriptor, 0x2052C80 , heartbeatIterator-> second , 8 , -1 );
618- else _sendCANMessage (descriptor, 0x2052C80 , heartbeatIterator-> second , 8 , 1 );
611+ if (sum == 0 ) _sendCANMessage (descriptor, 0x2052C80 , heartbeat , 8 , -1 );
612+ else _sendCANMessage (descriptor, 0x2052C80 , heartbeat , 8 , 1 );
619613}
0 commit comments