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!

Paytm games

I am not on any digital payment bandwagon. In fact I started using debit card only when the merchants stopped charging the stupid 2% transaction charge. And since I'm cautious about my money I have stayed away from payment wallets and the new app based payment methods. 
I primarily use cash for small payments. And shop where the merchants don't charge extra for using debit card. Anyway last week I tried to use Paytm app. It's a popular payment app. Many of my friends do use it for small payments. My feedback from them was positive, so I decide to take plunge. Also another major reason was - paytm food wallet. 
In india we get about 50Rs per day tax free out of salary for food. This you can collect monthly as Sodexo coupons. If you don't take sodexo coupons then this becomes taxable and you lose 10/20/30% depending on your income bracket. 
Anyway, coming back to Paytm, I tried to install the app. My poor panasonic was not a match - google play store said - device not compatible. Ok. Got hold of an APK and installed it, worked fine. Then created an account and logged in. So far so good!
Now comes the hard part - in India, now Reserve bank of India has made mandatory for wallet apps for user KYC. So I had to register one of my unique identity docs - like Adhaar or PAN card etc. No such option in App.
Then I went to website and logged in - and a popup asked me to give my Adhaar or other identity details. I filled it in and alas - error - please select proper option!!! WTF!!!
I retried number of times and even used different browsers. There were few posts going so far as giving some very complex directions to reach offline kyc, and too complex for me! Searched a number of forums etc. and even raised a support request. And the reply was - our systems are busy now- we will get back to you later!!!
Well, that did it in - I logged out, deleted the paytm app, and thought about this. The guys who can not handle a simple user kyc, cannot handle my money!! Alas!