PCM Hammer data filtering improvement help needed
Posted: Mon Jul 29, 2024 12:40 pm
Hi,
Question to those with more C# skills than myself. I am trying to solve this annoyance where PCM Hammer gets out of sync at the end of a read on some PCMs and requires a device reset before starting another operation. I could easily put in a hack to flush the buffer at the start of a new operation, but I'd rather improve data filtering, which would probably also improve reliability when flashing in a car.
Here is an example. At the end of the previous flash process. This example is on the bench, a vehicle bus would be more noisy. PCM Hammer finishes the flash process and sends out a couple more tool present broadcasts (8C FE F0 14 meaning 8C Priority (not important) FE=Target is broadcast, F0=from Tool, 14=Tool Present) before everything wraps up. Even though they are sent to a broadcast address FE, the PCM responds to the tool with 8C F0 10 54 meaning from PCM 10, to Tool F0, Mode 54 response to mode 14. Essentially an Ack that does nothing.
The problem is, it genuinely is a packet from the PCM to the Tool, just not one we care about. So then when the next operation begins, PCM Hammer sends a mode 3C packet for data 01, and even though we see the PCM responds correctly with a mode 7C 01 in the universal patcher logger, PCM Hammer has nothing in it to ignore or filter the previous 2 tool present responses, and breaks as it is out of sync.
So the thought is, that we need to implement filtering better. Device ID isnt going to help here, rather I think something in the device or protocol layer needs to know that it sent a mode 3C, then it should receive and discard for a second of two and search for the expected response eg 7C, then pass that back. Then the top level logic can just send its 3C, receive its 7C and the other packets wont get in the way.
The hard part is, how to do this cleanly. Ive had a look, I could hack something in to receive in device.cs to just discard unexpected packets by prioritiy which would hide this and make this particular scenario work, but its an abuse of the priority and not a clean solution.
There is similar verification code here https://github.com/LegacyNsfw/PcmHacks/ ... Utility.cs
But none of that searches for the received messages. The logic probably should go in the protocol class somewhere, though. Then some of the flow logic could be moved out the places it is repeated, and this code could be used more widely improving pcmhammer overall.
I don't do C# or OO programming as a day job and I don't have a strong network of C# devs around me to suggest the best place or best path forward. Ideas to solve this properly welcome.
Would a state machine that sets the next expected packet globally help? Does it belong in the API to protocol.cs in each call and the app updated to that even though the best device drivers stream data the main logic can send a packet and get back a matched response? Other ideas?
Question to those with more C# skills than myself. I am trying to solve this annoyance where PCM Hammer gets out of sync at the end of a read on some PCMs and requires a device reset before starting another operation. I could easily put in a hack to flush the buffer at the start of a new operation, but I'd rather improve data filtering, which would probably also improve reliability when flashing in a car.
Here is an example. At the end of the previous flash process. This example is on the bench, a vehicle bus would be more noisy. PCM Hammer finishes the flash process and sends out a couple more tool present broadcasts (8C FE F0 14 meaning 8C Priority (not important) FE=Target is broadcast, F0=from Tool, 14=Tool Present) before everything wraps up. Even though they are sent to a broadcast address FE, the PCM responds to the tool with 8C F0 10 54 meaning from PCM 10, to Tool F0, Mode 54 response to mode 14. Essentially an Ack that does nothing.
The problem is, it genuinely is a packet from the PCM to the Tool, just not one we care about. So then when the next operation begins, PCM Hammer sends a mode 3C packet for data 01, and even though we see the PCM responds correctly with a mode 7C 01 in the universal patcher logger, PCM Hammer has nothing in it to ignore or filter the previous 2 tool present responses, and breaks as it is out of sync.
So the thought is, that we need to implement filtering better. Device ID isnt going to help here, rather I think something in the device or protocol layer needs to know that it sent a mode 3C, then it should receive and discard for a second of two and search for the expected response eg 7C, then pass that back. Then the top level logic can just send its 3C, receive its 7C and the other packets wont get in the way.
The hard part is, how to do this cleanly. Ive had a look, I could hack something in to receive in device.cs to just discard unexpected packets by prioritiy which would hide this and make this particular scenario work, but its an abuse of the priority and not a clean solution.
There is similar verification code here https://github.com/LegacyNsfw/PcmHacks/ ... Utility.cs
But none of that searches for the received messages. The logic probably should go in the protocol class somewhere, though. Then some of the flow logic could be moved out the places it is repeated, and this code could be used more widely improving pcmhammer overall.
I don't do C# or OO programming as a day job and I don't have a strong network of C# devs around me to suggest the best place or best path forward. Ideas to solve this properly welcome.
Would a state machine that sets the next expected packet globally help? Does it belong in the API to protocol.cs in each call and the app updated to that even though the best device drivers stream data the main logic can send a packet and get back a matched response? Other ideas?