Thursday, December 19, 2013

kendo dataviz + PhoneGap + Scrolling + Windows Phone 8

The Kendo chart graph whose content is longer than its container DIV does not have scrollbar in Windows Phone 8. In contrast, it works beautifully in iOS and Android.
 <div class="chart_container" >  
           <div class="report_chart_placeholder" ></div>  
      </div>  

The graph component is built on report_chart_placeholder. Its minimum height / height is set. Overflow properties are also set correctly for chart_container. However, no scrollbar appears when the chart is higher than chart_container. Solution :
   
           <div class="chart_container" >  
           <div class="report_chart_placeholder_overlay" ></div>  
           <div class="report_chart_placeholder" ></div>  
      </div>  

I needed to use absolute position to place on top of the chart another DIV (report_chart_placeholder_overlay) with same height properties of the chart. Then the scrollbar shows up properly.

Tuesday, October 1, 2013

Symmetricds Cookies support

My problem : we need cookies support for SymmetricDS client in order to authenticate against central SymmetricDS.
Solution :
Create an extension point class
 package com.synch.extension;  
 import java.net.CookieHandler;  
 import java.net.CookieManager;  
 import java.net.CookiePolicy;  
 import org.jumpmind.extension.IExtensionPoint;  
 import org.slf4j.Logger;  
 import org.slf4j.LoggerFactory;  
 public class CookieManagerConf implements IExtensionPoint{  
      protected final Logger log = LoggerFactory.getLogger(getClass());  
      public CookieManagerConf() {  
           System.out.println("Cookie manager initialized ------------------------>");  
           log.info("Cookie manager initialized ---------------------->");  
           CookieManager manager = new CookieManager(null,CookiePolicy.ACCEPT_ALL);  
           CookieHandler.setDefault(manager);  
      }  
 }  

Create extension XML in {classpath}\conf\symmetric-extensions.xml as follow :
 <?xml version="1.0" encoding="UTF-8"?>  
 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xmlns:lang="http://www.springframework.org/schema/lang"  
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
             http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd" default-lazy-init="true">  
      <bean id="cookieManager" class="com.synch.extension.CookieManagerConf">  
      </bean>  
 </beans>  

Kalman filter with dspic33f : fixed point vs floating point speed comparison

Initially, I implemented Kalman filter for Microchip dspic33f MPU with floating point arithmetic calculations(mainly 2x2 float matrices) to measure inclination angle. The filter works brilliantly. However, I knew that fixed point calculation can greatly speed up the floating point Kalman filter. Hence, I decided to implement my Kalman filter in Q16 format. After that, I compared speed of 2 algorithms by using an oscilloscope. The output pin is set at the beginning and cleared at the end of the Kalman process.
Floating point Kalman filter :

Fixed point Kalman filter :

From above pictures, the fixed Kalman filter uses only ~46% time taken by floating point Kalman filter. Note : My dspic33f runs at 80 MHz.

Sunday, September 29, 2013

Enable fixed point math function for Microchip MPLABX IDE

I have had hard time to enable fixed point capability for MPLABX project. So I decided to document my solution here : 1. Using .
 #include <libq.h>  
2. Step 2 is adding those libs to libraries folder of the project as follow:
libq-coff.a
libq-dsp-coff.a
libq-dsp-elf.a
libq-elf.a 3. Step 3 : right-click project --> Properties. Modify configuration as follow:
Press Apply and OK. 4. Clean and rebuild project.
Edit : If the path of lib files contains spaces, build error will happen. Therefore, we can copy those lib files to another folder (without spaces in path) and include them in our project.

Friday, July 12, 2013

HTMLUnit & Vaadin Testing

I have been trying to use HTMLUnit to automate Vaadin application testing. Here are list of little tricks that I have figured out:
1. debugId for Vaadin component need to be set such as
Button :
saveButton.setDebugId("DenormalizedProductFilterForm_save");
Select :
sl_fetchSize.setDebugId("DenormalizedProductFilterForm_sl_fetchSize");
2. We need to use waitForBackgroundJavaScriptStartingBefore method to wait for DOM components .
3. Sometimes, click() does not do the job. We need to use {e.click(); e.mouseDown(); e.mouseUp();} or {div.dblClick();} to simulate click.
Sample code
 package com.wapice.epid.test;  
 import java.io.IOException;  
 import java.io.Serializable;  
 import java.net.MalformedURLException;  
 import java.util.logging.Level;  
 import org.apache.commons.logging.LogFactory;  
 import org.junit.Before;  
 import org.junit.Test;  
 import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;  
 import com.gargoylesoftware.htmlunit.WebClient;  
 import com.gargoylesoftware.htmlunit.html.HtmlDivision;  
 import com.gargoylesoftware.htmlunit.html.HtmlElement;  
 import com.gargoylesoftware.htmlunit.html.HtmlForm;  
 import com.gargoylesoftware.htmlunit.html.HtmlPage;  
 import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;  
 import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;  
 import com.gargoylesoftware.htmlunit.html.HtmlTextInput;  
 public class TestSearchProduct implements Serializable {  
      /**  
       *   
       */  
      private static final long serialVersionUID = 1L;  
      @Before  
      public void before() {  
           LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",  
                     "org.apache.commons.logging.impl.NoOpLog");  
           java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit")  
                     .setLevel(Level.OFF);  
           java.util.logging.Logger.getLogger("org.apache.commons.httpclient")  
                     .setLevel(Level.OFF);  
      }  
      public void testWithStress() {  
      }  
      @Test  
      public void test() {  
           final WebClient webClient = new WebClient();  
           webClient.getOptions().setThrowExceptionOnScriptError(false);  
           webClient.getOptions().setCssEnabled(true);  
           webClient.getOptions().setJavaScriptEnabled(true);  
           HtmlPage page;  
           try {  
                System.out.println("Starting test");  
                page = webClient  
                          .getPage("http://localhost:1123/someapp/application/");  
                // login  
                {  
                     HtmlForm form = page.getFormByName("loginform");  
                     HtmlSubmitInput button = form.getInputByName("submitButton");  
                     HtmlTextInput userName = form.getInputByName("j_username");  
                     userName.setValueAttribute("jaacco");  
                     HtmlPasswordInput password = form.getInputByName("j_password");  
                     password.setValueAttribute("jaacco");  
                     button.click();  
                }  
                // search for product  
                {  
                     page = webClient  
                               .getPage("http://localhost:1123/someapp/application/#listdenormalizedproductview");  
                     webClient.waitForBackgroundJavaScriptStartingBefore(5000);  
                     //select from Select  
                     {  
                          HtmlDivision div = page  
                                    .getHtmlElementById("DenormalizedProductFilterForm_sl_fetchSize");  
                          for (HtmlElement e : div.getElementsByTagName("div")) {  
                               e.click();  
                          }  
                          webClient.waitForBackgroundJavaScriptStartingBefore(1000);  
                          div = page.getHtmlElementById("VAADIN_COMBOBOX_OPTIONLIST");  
                          for (HtmlElement e : div.getElementsByTagName("td")) {  
                               if (e.asText().contains("200")) {  
                                    e.click();  
                                    e.mouseDown();  
                                    e.mouseUp();  
                                    break;  
                               }  
                          }  
                          webClient.waitForBackgroundJavaScriptStartingBefore(1000);  
                     }  
                     //click button  
                     {  
                          HtmlDivision div = page  
                                    .getHtmlElementById("DenormalizedProductFilterForm_save");  
                          div.dblClick();  
                     }  
                     webClient.waitForBackgroundJavaScriptStartingBefore(10000);  
                }  
           } catch (FailingHttpStatusCodeException e) {  
                e.printStackTrace();  
           } catch (MalformedURLException e) {  
                e.printStackTrace();  
           } catch (IOException e) {  
                e.printStackTrace();  
           }  
           webClient.closeAllWindows();  
      }  
 }  

Saturday, June 22, 2013

adis16209 : switch/change command delay

Recently, I have been doing testing for adis16209 sensor. I came across a strange problem when running this piece of code:
 write_spi(ROT_OUT);  
 //wait until we receive rot_out_value from SPI  
 uart_write(rot_out_value);  
 write_spi(YINCL_OUT);  
 //wait until we receive yincl_out_value from SPI  
 uart_write(yincl_out_value);  

The sensor returns false values for ROT_OUT and YINCL_OUT commands. I started to dig into the problem and came to a conclusion that if we want to change the command (For example from ROT_OUT to YINCL_OUT), we must do like this :
 //switch to ROT_OUT command  
 write_spi(ROT_OUT);  
 //small delay  
 delay_us(40);  
 write_spi(ROT_OUT);  
 //wait until we receive rot_out_value from SPI  
 uart_write(rot_out_value);  
 //switch to YINCL_OUT command  
 write_spi(YINCL_OUT);  
 //small delay  
 delay_us(40);  
 write_spi(YINCL_OUT);  
 //wait until we receive yincl_out_value from SPI  
 uart_write(yincl_out_value);  

Wednesday, June 19, 2013

TOMEE java.lang.OutOfMemoryError: PermGen space

In order to solve this annoying problem with PermGen space in TomEE (possibly Tomcat as well) when we try to run startup.bat:
- Create file with name setenv.bat in bin folder with content as follow :
set "CATALINA_OPTS=-Xms1024m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m"