ticalc-usb icon indicating copy to clipboard operation
ticalc-usb copied to clipboard

Add device.getDirectory

Open commandblockguy opened this issue 4 years ago • 11 comments

Adds a method to get the list of variables on a device.

This PR also adds support for receiving fragmented virtual packets and an expectAny method for receiving a virtual packet of unknown type.

It also makes several changes to parameter handling:

  • Adds a public function for getting parameters from the device
  • Allows non-numerical parameters to be constructed and destructed
  • Fixes a bug in which an unrecognized parameter caused parsing to fail, as the code always expected a size to be provided, despite this not being the case when the device doesn't return a value for the parameter.
  • Fixed a test case which relied on this bug
  • Changed the return type of destructParameters to be an object rather than an array and to only include valid parameters
  • Updated the test cases to use the new return format

I've only tested this on the CE, so it will probably need additional testing before being merged.

commandblockguy avatar Sep 14 '21 23:09 commandblockguy

Hey there! Another great looking PR at first glance, thanks a lot! I'll have a better look this weekend, when I hope to have a little spare time and access to my calculator. One thing that jumps out to me is the dropped test coverage. It would be nice to have a unit test for the mergeBuffers method and a replay for the getDirectory. I can make the latter, can you maybe do the former?

Timendus avatar Sep 16 '21 18:09 Timendus

I've added a test for mergeBuffers. It didn't affect the coverage percentage, since it's already used by another function, but it did find a bug, so I guess it served its purpose?

commandblockguy avatar Sep 17 '21 03:09 commandblockguy

I've added a recording and tests for the TI-83 Premium CE, which work fine if you mark the device as "supported" and completely fail otherwise. I'm not really sure how to fix that, as the required support level isn't explicitly specified anywhere during the test.

commandblockguy avatar Sep 17 '21 04:09 commandblockguy

Alright, I made the build and CodeClimate (and myself 😉) happy again.

However, there's this annoyance in the test output a couple of times now:

console.log
    Warning: Unlogged read of property 'vendorId', value: 1105

      at Player._expectProperty (src/webusb/player.js:72:17)
          at Array.every (<anonymous>)
          at Array.find (<anonymous>)

  console.log
    Warning: Unlogged read of property 'productId', value: 57352

      at Player._expectProperty (src/webusb/player.js:72:17)
          at Array.every (<anonymous>)
          at Array.find (<anonymous>)

  console.log
    Warning: Unlogged read of property 'productName', value: TI-83 Premium CE

      at Player._expectProperty (src/webusb/player.js:72:17)
          at Array.every (<anonymous>)
          at Array.find (<anonymous>)

I'm not entirely sure why that didn't show up before, when I just changed the support type of the TI-83 Premium CE to supported. It's not really a huge issue I suppose. But if you have any ideas... 😄

If you're still happy after my changes, I'll merge the PR.

Timendus avatar Sep 19 '21 18:09 Timendus

Oh, and by the way, it works perfectly on my TI-84 Plus 👍🏻

Timendus avatar Sep 19 '21 18:09 Timendus

I'm also seeing those warnings - I'm guessing it's because changing the support level caused it to check if the device was supported again? I'll investigate it later today, and if necessary, re-record the tests.

commandblockguy avatar Sep 19 '21 19:09 commandblockguy

Tbh, I don't think it's an issue with the recording. There shouldn't really be something like a second check for different support levels. Not sure what it is though.

So maybe this shouldn't be a blocking issue. I guess it's a good idea if I add a getDirectory recording for TI-84+ though, and we should add this to the readme file, to round off this PR.

Timendus avatar Sep 21 '21 20:09 Timendus

Found anything? I myself am a bit pressed for time last week and this week, but I'll attempt to find a moment to make the TI-84+ recording and add it to the PR.

Timendus avatar Sep 27 '21 18:09 Timendus

I believe the issue is here. The properties required for device matching are checked once for each device for the current support level, so changing the support level changed the number of devices and caused the properties to be read more times than before. So, this is only a testing issue, not an issue with the actual code. The simplest solution would simply be to create a copy of the device parameters before comparing to each device. This would also speed up recognizing devices when there are many supported calculators.

commandblockguy avatar Oct 06 '21 03:10 commandblockguy

You're a genius. That could very well be the issue 🎉

Timendus avatar Oct 06 '21 18:10 Timendus

It would be nice if this support was added.

SpaceSaver avatar Apr 06 '23 20:04 SpaceSaver