Saturday, 20 August 2016

Pondering back on my project: Scalability of MVC architecture on Windows CE (with multiple Windows Forms)

I had been working with Windows CE for 2+ years and I would like to ponder back regarding the architectural decisions that were made at the beginning of the projects based from the book that I used as a reference for my MVC implementation on my project. I followed this book (I won't be mentioning the exact name of the book here), because it seems the author is very confident about MVC. He has a very simple example code in Java and I took a leap of faith on it. But then I slowly see the problems as the project grows larger.

In my project, there are 50+ UIs/View/Windows Forms, Data Layer SQL, Interop with another DLL, 3 product variants of the same software (heavy use of Strategy Pattern and Template Method Pattern on this), Cloud, XML/JSON/Protobuf Serialization and unique features based from the OEM variants of our product. I would say that this is a huge and complex project. And I have around more than 150+ source files where I had written 90% to 95% of the total code base. In that book, I saw that the Model was almost repeated on the Controller (but with the views references and manipulation). This has caused pain because of the redundancy just to achieve great separation of concern. I felt that the author's approach is ok on small projects, but I have great doubts on it on big projects unless you have all the time and resources to accomplish that (but we are on a small company and time is gold to us). So midway on the schedule of the project, I found myself refactoring a lot to keep everything under control and to keep the flames down.

With the aforementioned issues, I did more research and found articles regarding Skinny Controllers-Fat Model, Model-Mediator-GUI and MVP(in Supervising Controller). From there and based from the issues I faced, I was able to come up with this Model-Mediator-Controller-View (MMCV - which I coined the term by myself). This is still in current version and may still change, but I have confidence that this will solve most of the scalability issues that I had encountered. This is not yet final and I may modify it, depending on the circumstances that I may face.



Saturday, 6 August 2016

FreeRTOS on Renesas RX62N

Just recently, I would like to learn VxWorks. But with the cost of the license, I turned to FreeRTOS. I saw that it supports Renesas RX62N and luckily, I have the development kit.

I downloaded the latest software for Renesas RX62N (HEW,Segger, and other toolchain) as well as updating the GCC compiler. Then I used the information here http://www.freertos.org/FreeRTOS_RX62N_GCC_GNURX.html.

After opening the project on folder FreeRTOSv9.0.0\FreeRTOS\Demo\RX600_RX62N-RDK_GNURX , I was able to start working with it and was able to create tasks, implement mutexes,etc easily.  I would say that it is almost the same with the MQX RTOS that I previously used in one of the RF products that I was involved with (except for the API syntax).

All my experiments are located here: https://github.com/fwswdev/RenesasRX62NFreeRTOSDemo


Monday, 30 May 2016

Weekend Project: 3D Printed 26dB Pre-amp Booster

This is my weekend project: a 3d Printed 26dB Preamp Booster. This uses a OPA2134 op-amp. Simulated and verified using LTSpice.





Tuesday, 16 February 2016

S Pen Digitizer (Source Code Fork)

Lately, I had been looking for a way to transform my Galaxy Note 2 into a graphics tablet. I stumbled into this open-source software, Link . It works, however on my first tries, I noticed that there are some unwanted offseting during drawing. I then forked the source code and debugged the code made changes to it. Now the unwanted offset has been fixed and I added a top-left calibration. The down-right calibration will be added in my free time.

Here is the forked source code with the fix  Link

Despite of the quirks, I believe this is still a great idea/software by the original author. Thank you to https://github.com/artursgirons

Monday, 15 February 2016

Boost Smart Pointers

Nowadays, we have the luxury of having Garbage Collectors in C#, Java, Python, etc. But we don't have that luxury in C++. Nobody can deny that managing pointers is a good to have skill, however, things had changed, the technology evolved as well and we might as well delegate the handling of pointers to someone else. Enter Boost Library. This is a superb library with lots of tools. The smart pointers on Boost library can greatly reduce the risk of memory leaks. Let's see the following samples run on Visual Studio 2015 with the memory leak detector enabled.

class ABasePerson
{
public:
    virtual void ShoutDescription() = 0;
};

class Fireman :public ABasePerson
{
public:
    void ShoutDescription()
    {
        cout << "I am a Fireman!";
    }
};


Above is a classic usage of polymorphism and we will use this as the basis of our example.
----------------------------------------------------------------------------------------------------------------
Example #1
{
ABasePerson *basePerson = new Fireman();
basePerson->ShoutDescription();
delete (basePerson);

}
This example will work well.
----------------------------------------------------------------------------------------------------------------
Example #2
{
ABasePerson *basePerson = new Fireman();
basePerson->ShoutDescription();

}
On this example, the developer forgot to delete the basePerson and now we have memory leak!
----------------------------------------------------------------------------------------------------------------
Example #3
{
boost::shared_ptr<ABasePerson> basePerson2(new Fireman());
basePerson2->ShoutDescription();
}

On this example, the basePerson2 will automatically be freed once it goes out of scope. Very convenient!
----------------------------------------------------------------------------------------------------------------
Example #4
boost::shared_ptr<ABasePerson> basePerson2(new Fireman());
basePerson2->ShoutDescription();

basePerson2 = NULL;
On this example, the basePerson2 will automatically be freed once it was set to NULL.
----------------------------------------------------------------------------------------------------------------

On this post, we saw the convenience of using Boost Smart Pointers.

Update: I am not using the Boost Smart Pointers as of the moment. Instead, I am using C++11's smart pointers since they are almost included in every compiler. (I use GCC in Linux and MSVC on Windows and they both include C++11's Smart Pointers)

Saturday, 13 February 2016

Arduino Signal Experiment #4: DC Offset Removal using Arduino

From my first post Arduino Signal Experiment #1, we can see that I added a DC offset so that Arduino will be able to measure the peak to peak signals of the sine wave that I am producing. Now, in this post, I will show how to simply remove that DC offset.

This is the code that I wrote for Arduino. http://codepad.org/A2ckv1ER

On the code, I reused the code that I wrote in Signal Experiment #1, but this time, I refactored it and placed it in a class that inherits from a base class with one abstract method. This way, it will be easier to experiment and add some more experiments. The class that we will be focusing  on is the  SamplingWithDCBiasRemoval class. After running the code, here is the resulting waveform:



As seen on the waveform, the DC offset was gone. Noticed the Gain value which I set to 0.8? Feel free to adjust that value and see what will happen on the waveform.

Friday, 12 February 2016

Arduino Signal Experiment #3-B: Goertzel using Arduino

On my last blog post, I discussed the library that I will be using on this blog post. We will be using the library that I forked and modified. Same as before, we will be using a PC speaker output going straight to an Arduino Mega. This is the arduino code that I used http://codepad.org/ezlp9tKT .

On Audacity, I generated two sine waves - 425Hz and 700Hz.


On Audacity, we can mute the channels to be  able to verify if the Goertzel algorithm works.  

Experiment 1 - Both Channels muted
Magnitude(425Hz): 15
Magnitude(700Hz): 11 

Experiment 2 - 700Hz Active / 425Hz Muted
Magnitude(425Hz) 234
Magnitude(700Hz) 5984 

Experiment 3 - 700Hz Muted / 425Hz Active
Magnitude(425Hz) 6299
Magnitude(700Hz) 152 

Experiment 4 - 700Hz and 425Hz Active
Magnitude(425Hz) 4328
Magnitude(700Hz) 4243

If I adjust the master volume of my laptop, the Goertzel algorithm reports the change of magnitude. To conclude, we can see that the Goertzel Algorithm can detect and distinguish the target frequencies.

Special Thanks to jacobrosenthal.