@@ -724,6 +724,41 @@ Napi::Array getImageElements(const Napi::CallbackInfo& info) {
724
724
return elements;
725
725
}
726
726
727
+ Napi::Object getTimestampsForAllReceivedMessages (const Napi::CallbackInfo& info) {
728
+ Napi::Env env = info.Env ();
729
+ std::string descriptor = info[0 ].As <Napi::String>().Utf8Value ();
730
+
731
+ std::shared_ptr<rev::usb::CANDevice> device;
732
+
733
+ { // This block exists to define how long we hold canDevicesMtx
734
+ std::scoped_lock lock{canDevicesMtx};
735
+ auto deviceIterator = canDeviceMap.find (descriptor);
736
+ if (deviceIterator == canDeviceMap.end ()) {
737
+ if (devicesRegisteredToHal.find (descriptor) != devicesRegisteredToHal.end ()) return receiveHalMessage (info);
738
+ Napi::Error::New (env, DEVICE_NOT_FOUND_ERROR).ThrowAsJavaScriptException ();
739
+ return Napi::Object::New (env);
740
+ }
741
+ device = deviceIterator->second ;
742
+ }
743
+
744
+ std::map<uint32_t , std::shared_ptr<rev::usb::CANMessage>> messages;
745
+ bool success = device->CopyReceivedMessagesMap (messages);
746
+ if (!success) {
747
+ Napi::Error::New (env, " Failed to copy the map of received messages" ).ThrowAsJavaScriptException ();
748
+ return Napi::Object::New (env);
749
+ }
750
+
751
+ Napi::Object result = Napi::Object::New (env);
752
+ for (auto & m: messages) {
753
+ uint32_t arbId = m.first ;
754
+ // GetTimestampUs() actually returns timestamps in milliseconds
755
+ uint32_t timestampMs = m.second ->GetTimestampUs ();
756
+ result.Set (arbId, timestampMs);
757
+ }
758
+
759
+ return result;
760
+ }
761
+
727
762
void cleanupHeartbeatsRunning () {
728
763
// Erase removed CAN buses from heartbeatsRunning
729
764
std::scoped_lock lock{watchdogMtx, canDevicesMtx};
0 commit comments