Tuesday, August 28, 2018

Marshalling/unmarshalling struct containing array of structs

While handling a change request I stumbled into this very peculiar scenario. I had a structure which had array of structs and I had to read/write this in a file. So to and from buffer conversions, I knew marshalling will be most effective.
I had previously used it very effectively for CAN communication.
So I had to google a bit n found how to handle this peculiar case. Below is the code.

public struct tagX
public UInt32 a;
public UInt32 b;

public struct tagY
public UInt32 x;
public UInt32 y;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = 20)]
public tagX[] stX;

To initialize this:

tagY stY = new tagY();
StY.stX = new tagX[20]; // Ensure size of array is equal to size const supplied in marshalAs directive.

Then on this object we can run marshalling / unmarshalling routines.

Monday, August 13, 2018

Adventure with ZTE Blade C (ZTE V807)

Got hold of the ZTE Blade C after almost couple of years. Last thing I remember doing with this phone is flashing shit load of custom roms and then none of them working out the way I wanted. Every ROM had some issues. The last one I flashed was called PNG v5 and had a battery bug - but that may have creeped due to some other offbeat roms I flashed earlier. Anyway, coming back, what I wanted to do was to get this phone back to Stock state. 
Unfortunately being 4Year old I could not get anything. First I started with ZTE's official website, but it's down due to US sanctions. Actually I had almost all the tools but stupidly I deleted about six months back. 
Anyway so I started digging around to find a stock ROM. Needrom came through and I found someone's ROM backup there. To download that I'll need SP Flash tools and since I formatted my laptop a year or so back, will need MTK USB and MTK PreLoader drivers. Ok, took me couple of days of hunting around the net to get that. To flash the backup - tedious procedure, install all the drivers, thhen start SP Flash Tools and load scatter, then change any settings needed and start Download. Then plug in the phone in off state, and MTK preloader shall kick in and start flashing. Damn! On first day I ran into number of driver issues, and had to reinstall the drivers couple of times and reboot laptop a few times. 
Then when the preloader situation sorted out I found out about error 8083 - which means scatter mismatch. Problem is I had changed system partition to 2GB so does not match default scatter. Anyway, coming back I dug MTK Droid Tools and and created a scatter. Then sorting out more settings, I finally got the stock loaded. 
Now later what? I checked out the battery percentage and some basic things - everything seemed to be working fine. I had earlier also prepared the backup of existing ROM for future use if this adventure fails. Anway, so coming back, with 512MB system partition, the phone is not usable, so I once again looked around the net and tried to find the MTK65xx_repartition_EN apk, using which I had earlied changed the data partition size. This time no luck - all the paths were dead, and one place I did find the APK. But it won't work, then I remembered that I need root. So further search was for framaroot/ vroot etc but nothing worked and I almost gave up. Anyway, coming back I found some zip file which promised 2GB system partition. I was totally sceptical but it did work out fine. Anyway so now the phone is usable. Lets see what I can actually use it for!