Friday, November 30, 2018

PWM of a signal

Pulse Width Modulation can be used to convert an analog signal to digital or mimic an analog signal with digital (e.g. Arduino's analogWrite()). PWM basically converts the signal sample values into pulse width values (amplitude of pulses is constant). Below is a Matlab script that demonstrates PWM of a sine wave.


Thursday, November 29, 2018

Software bug target

Any complex software will have bugs in it, no matter how hard you try to fix them all. When testing software, aim for bug free operation in 95% of all operational cases. Note that I say "all operational cases" and not "all possible cases" because possbilities might be infinite due to combinatorial explosion and 95% of inifinity still infinity!

Users / domain experts can tell you realistic edge cases. If you don't constrain your bug target this way, you might spend a lot of time on fixing bugs/optimizing of unimportant scenarios. That is why having a freqent iteration development methodology (e.g. agile) and lots of tests with real users is very important in building a reliable product.

Wednesday, November 14, 2018

Mixing C++ and C and calling a C/C++ dll from Java

In Visual Studio, it is possible to mix C++ and C code, C++ files should have cpp extension, C files should have C extension, the compiler takes care of the rest. When including a C header file inside a C++ file, wrap it inside extern "C { #include "somfile.h"}. Otherwise, you will get LNK2019 (the dreaded "unresolved external symbol" error).

When you want to create a dll from this mixed project to be used with Java, in your wrapper header file of cpp implementation, you have to wrap the header body inside #ifdef __cplusplus extern "C" { #endif ...  #ifdef __cplusplus } #endif. Otherwise you will be able load the dll in Java but when you call a dll method, you will get UnsatisfiedLinkError.

When naming your functions in C/C++ Java interface functions section, do not use underscores at the end of the function name like "Java_package_name_myFunction_rad_s()" because in Java interface functions, undescores are only used as package name separators. If you ignore this, you will get UnsatisfiedLinkError and wonder why.

Monday, November 12, 2018

The cost of refactoring

Today a colleague was proposing a design change to the backend of a GUI heavy application with the main rationale that the backend would be more elegant and the change would be easy to implement. I told him that the real cost of refactoring is the necessity to repeat all the manual UI tests (our automated Macro Scheduler tests are not ready yet). A GUI application has many paths to failure and we have been developing this particular application for a couple of years now. Changing the backend would certainly break some edge cases and from the users perspective, the app would have regressed.

The only acceptable reason for a backend refactoring would be if we had lots of functionality to add in the short term and the change would make such additions a breeze, being a net saving in effort, in addition to being elegant.

Thursday, November 01, 2018

Baby / child sleep training

Last weekend we met with friends who have a couple of months old baby. They asked us about sleep training. We told them that we first tried it according to the book but then changed it dramatically.

The main problem was that our son, who was 1 year old at the time of training start, resisted being laid down into the crib. Resisted means that he cried and wept with a terrified "I am going to die" look on his face and arms extended towards you begging for help for 45 minutes! We could not bring ourselves to leave him alone in his room like that. So, we laid besides him in the crib until he fell asleep (took about an hour) and sneaked away.

After a couple of months, we put some pillows beside his crib and waited there for him to fall asleep which again took about 1 hour each day. Every half an hour, I changed places with my spouse. It sometimes took 1.5 hours. After he fell asleep he usually woke up when we put him into the crib and the whole procedure lasted for another half an hour. Trying to carefully lift and place him into the crib was bad for our backs too.


Finally we decided to buy an adult size matress and laid it on the floor of his room and gave up on the crib altogether. At bed time, we cuddled him, played children's music, and when he fell asleep, we simply left the room without the crib hassle. Win-win :)