pslab-android icon indicating copy to clipboard operation
pslab-android copied to clipboard

feat: updated commands to achieve compatibility with PSLab V6

Open AsCress opened this issue 1 year ago • 1 comments

Fixes #2490 THIS IS A MAJOR UPDATE THAT UPDATES FUNCTIONS FOR ALL THE INSTRUMENTS AND MAKES OUR APP WORKING WITH THE V6 DEVICE (latest firmware - v3.0.0), ALONGWITH RETAINING BACKWARDS COMPATIBILITY WITH THE V5 (legacy firmware - v2.0).

Major Changes

  • Oscilloscope: Due to GET_CAPTURE_CHANNEL being unimplemented in the latest firmware, the implementation is revised to use RETRIEVE_BUFFER instead. A data splitting model is introduced along with an algorithm that handles channel indexing for input to the RETRIEVE_BUFFER command.

  • Multimeter: The implementations of several instruments of the Multimeter are revised to get them back to working again -

    1. Capacitance Measurements- The algorithm for measuring capacitance is modified to increase the range of capacitance that can be measured. Functions are introduced that handle charging and discharging properly.
    2. Logic Analyzer (Pulse Count)- Implementation is fixed to make it working again.
    3. Logic Analyzer (Frequency Measurements)- Due to GET_CHANNEL_FREQUENCY being unimplemented in the firmware, a new approach is introduced which calculates frequency based on the number of events detected by the Logic Analyzer.
  • Logic Analyzer: The implementations for getting initial states and fetching data are revised to bring the instrument back to working again. Data Splitting Model is introduced, thereby facilitating communication with the PSLab and increasing performance. RETRIEVE_BUFFER is introduced to read data from the buffer, and hence channel indexing akin to the Oscilloscope is implemented for input to the command.

  • Power Source: Perhaps the instrument which needed most work as the implementation has completely changed in the latest firmware. New functions are introduced to set and get voltages. The functionality has been modified to sync PV1, PV3 and PV2, PCS when the PSLab V6 device is connected.

  • Miscellaneous: Functions for all the new functionality (e.g.:-enterBootloader(), RGBLED(), etc.) introduced in PSLab V6 (firmware v3.0.0) have been added along with the docs for the same.

Functions changed:

  • getTemperature()
  • getCTMUVoltage()
  • startCTMU()
  • stopCTMU()
  • reset()
  • readProgramAddress()
  • deviceID()
  • readDataAddress()
  • writeDataAddress()
  • enableUARTPassThrough()
  • readLog()
  • captureTraces()
  • getLAInitialStates()
  • getCapacitance()
  • read()
  • commonRead()
  • commonWrite()
  • initialiazeVariables()
  • runInitSequence()
  • fetchBuffer()
  • getFrequency()
  • startOneChannelLA()
  • fetchIntDataFromLA()
  • fetchLAChannelFrequency()
  • captureCapacitance()
  • getCapacitanceRange()
  • setPV1()
  • setPV2()
  • setPV3()
  • setPCS()
  • getPV1()
  • getPV2()
  • getPV3()
  • getPCS()

Functions added:

  • enterBootloader()
  • RGBLED()
  • fetchData()
  • pack()
  • readLine()
  • setCap()
  • dischargeCap()
  • setVoltage()
  • setCurrent()

Functions removed:

  • ignoreCalibration()
  • getRadioLinks()
  • newRadioLink()
  • readFlash()
  • readBulkFlash()
  • writeFlash()
  • writeBulkFlash()
  • writeProgramAddress()
  • WS2812B()
  • readUARTStatus()
  • readUART()
  • writeUART()
  • setUARTBaud()
  • opticalArray()
  • estimateDistance()
  • fetchChannel()
  • captureOne()
  • captureTwo()
  • captureFour()
  • captureMultiple()
  • captureFullSpeedInitialize()
  • captureFullSpeed()
  • captureHighResolutionTraces()
  • fetchChannelOneShot()
  • autoRangeScope()
  • autoRangeSelect()
  • startStreaming()
  • stopStreaming()
  • stepperMotor()
  • stepForward()
  • stepBackward()
  • captureStart()
  • capture()

Screenshots / Recordings

N/A

Testing

I have tested all the features with a PSLab V6 device running the latest (v3.0.0) firmware as well as the legacy (v2.0) firmware. So, ideally these should also work fine with a PSLab V5 device.

Checklist:

  • [x] No hard coding: I have used resources from strings.xml, dimens.xml and colors.xml without hard coding any value.
  • [x] No end of file edits: No modifications done at end of resource files strings.xml, dimens.xml or colors.xml.
  • [x] Code reformatting: I have reformatted code and fixed indentation in every file included in this pull request.
  • [x] No extra space: My code does not contain any extra lines or extra spaces than the ones that are necessary.

@CloudyPadmal @bessman @marcnause The big task is finally done !! Any comments/suggestions are most welcome. @marcnause Could you please help me testing all the instruments on a PSLab V5 device as well, just to be sure.

AsCress avatar Jul 04 '24 13:07 AsCress

Build successful. APKs to test: https://github.com/fossasia/pslab-android/actions/runs/10236756408/artifacts/1773701466

github-actions[bot] avatar Jul 04 '24 13:07 github-actions[bot]

I am sorry that it took me so long to test the branch of this PR. I tested with the PSLab v5 and as far as I can tell, everything works as expected. I hope that I did not miss anything.

marcnause avatar Jul 06 '24 20:07 marcnause

@marcnause Thanks so much for testing and confirming that everything works well ! Your suggestions regarding the version checks sound great to me ! However, how about if we implement something like this: instead of checking version each time whenever it is needed in different files, we check it once when the connection is opened, i.e., in CommunicationHandler.java. There if we find it to be incompatible, we throw an exception then and there (something like the app isn't compatible with this version or so). How does this sound to you ?

AsCress avatar Jul 07 '24 05:07 AsCress

👍 Sounds good to me!

marcnause avatar Jul 07 '24 07:07 marcnause

@marcnause I have now dropped support for the legacy firmware in this PR (see edit). Can you once test this and confirm that the dialog appears when you connect your device running the legacy firmware on it ? You may have to clone my branch for this, I don't know why the comment workflow has failed, so the comment above might not be having the latest APK.

AsCress avatar Jul 09 '24 08:07 AsCress

I have built from your branch and I get the warning if I connect my PSLab with the legacy firmware.

Screenshot_20240709-215127

marcnause avatar Jul 09 '24 19:07 marcnause

I updated my PSLab v5 to firmware version 3.0.1 and as far as I can tell, it works fine. My PSLab v5 is reported as a v6 board in the "Connect Device" screen, but AFAIK the displayed String is read from the firmware and displayed by the app as is.

marcnause avatar Jul 11 '24 18:07 marcnause

@sourcery-ai review

mariobehling avatar Jul 22 '24 06:07 mariobehling

Reviewer's Guide by Sourcery

This pull request updates the PSLab Android app to be compatible with the PSLab V6 device and its latest firmware (v3.0.0). Major changes include revising methods for oscilloscopes, multimeters, logic analyzers, and power sources to align with the new firmware. Unused functionalities related to calibration and flash memory have been removed. New methods for handling PSLab V6 specific features like RGB LED control and bootloader mode have been introduced. Additionally, legacy firmware detection has been added to notify users about the need for firmware updates.

File-Level Changes

Files Changes
app/src/main/java/io/pslab/communication/ScienceLab.java
app/src/main/java/io/pslab/communication/peripherals/I2C.java
app/src/main/java/io/pslab/communication/peripherals/MCP4728.java
Revised methods and removed unused functionalities to align with PSLab V6 firmware changes.
app/src/main/java/io/pslab/activity/PowerSourceActivity.java
app/src/main/java/io/pslab/communication/PacketHandler.java
app/src/main/java/io/pslab/communication/CommandsProto.java
app/src/main/java/io/pslab/communication/CommunicationHandler.java
Updated power source control and communication handling to support new PSLab V6 features.
app/src/main/java/io/pslab/activity/MainActivity.java
app/src/main/java/io/pslab/fragment/HomeFragment.java
Added legacy firmware detection and removed calibration checks during initialization.
app/src/main/java/io/pslab/activity/MultimeterActivity.java
app/src/main/java/io/pslab/fragment/ControlFragmentRead.java
Updated method calls to remove null timeout parameters.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

sourcery-ai[bot] avatar Jul 22 '24 06:07 sourcery-ai[bot]

I have tested with my PSLab v5 with firmware version 3.0.2 and I noticed a few things:

  • Oscilloscope: I only get waveforms on CH3 if the internal microphone or the MIC of the board is active
  • Multimeter: LA1 and LA2 measure the frequency of a sinus wave produced by the Wave Generator correctly. LA3 and LA4 show different values which are much higher
  • Multimeter: Measuring the capacitance results in "Cannot measure!". I only get values when I remove the capacitor during measurement
  • Logic Analyzer: Even though I only have on channel connected (LA1), I get results on all 4 channels
  • Power Source: PV1 and PV2 always stay at the initial value, even if I change them in the app

I cannot rule out the possibility that some of the points are the result of my own incompetence.

marcnause avatar Aug 04 '24 14:08 marcnause

Addendum:

I have created new tickets for some of the issues mentioned above:

  • https://github.com/fossasia/pslab-android/issues/2521
  • https://github.com/fossasia/pslab-android/issues/2522
  • https://github.com/fossasia/pslab-android/issues/2523
  • https://github.com/fossasia/pslab-android/issues/2525

I tested the last two issues again with the same result as earlier.

Regarding the capacitance issue: I tested with a 100µF capacitor. @AsCress mentioned that this value is too high for the PSLab to measure. I tried again with a 100pF resistor and measurement worked fine.

marcnause avatar Aug 04 '24 20:08 marcnause