Monday, December 30, 2013

netbeans 7.4 maven javafx project doesn't run

Executing a javafx/maven project in netbeans doesn't work. The fix is here:

https://netbeans.org/bugzilla/show_bug.cgi?id=233613

It involves changing the following two step:
Step 1: Add the following to the projects pom.xml file:

<execution>
    <id>default-cli</id>
    <goals>
        <goal>exec</goal>                            
    </goals>
    <configuration>
        <executable>java</executable>
        <commandlineArgs>${runfx.args}</commandlineArgs>
    </configuration>
</execution>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
..

    </organization>

    <build>
        <plugins>

  ..
  ..
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${java.home}/../bin/javafxpackager</executable>
                            <arguments>
                                <argument>-createjar</argument>
                                <argument>-nocss2bin</argument>
                                <argument>-appclass</argument>
                                <argument>${mainClass}</argument>
                                <argument>-srcdir</argument>
                                <argument>${project.build.directory}/classes</argument>
                                <argument>-outdir</argument>
                                <argument>${project.build.directory}</argument>
                                <argument>-outfile</argument>
                                <argument>${project.build.finalName}.jar</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    
                    <execution>
                        <id>default-cli</id>
                        <goals>
                            <goal>exec</goal>                            
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <commandlineArgs>${runfx.args}</commandlineArgs>
                        </configuration>
                    </execution>                    
                    
                </executions>  
            </plugin>
            <plugin>
   ..
            </plugin>
        </plugins>
    </build>
</project>

Step 2: Exchange the project's nbaction.xml with
<?xml version="1.0" encoding="UTF-8"?>
<actions>
    <action>
        <actionName>run</actionName>
        <goals>
            <goal>clean package</goal>
            <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
        </goals>
        <properties>
            <runfx.args>-jar ${project.build.directory}/${project.build.finalName}.jar</runfx.args>
            <skipTests>true</skipTests>
        </properties>
    </action>
    <action>
        <actionName>debug</actionName>
        <goals>
            <goal>clean package</goal>
            <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
        </goals>
        <properties>
            <runfx.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -jar ${project.build.directory}/${project.build.finalName}.jar</runfx.args>
            <skipTests>true</skipTests>
            <jpda.listen>true</jpda.listen>
        </properties>
    </action>        
</actions>

Sunday, December 29, 2013

Analysing USB traffic with USBPcap and wireshark

In order to trouble should the concept 2 CSafe libraries I needed to see the bytes traveling across the wire on the USB bus. To do this I, I used USBPcap.

The need to look at the bytes being sent over the USB bus became necessary when I was working with the CSafe libraries from concept2.

The USBPcap programm can be download here:


(Watch the installation. If you change the default directory and don't watchout it won't add back a application directory for itself. When you try to deinstall it, it will delete the whole directory!)



The USBPcapCMD application runs as a command line programm. One of the things it will ask you for is a output file name. If you name this with a ".pcap" extension and you've installed wireshark (Version 1.10.5), you'll be able to open the file with wireshark and look at very comfortably. 


concept2 + PM + SDK

Concept2 SDK

The SDK libraries from concept 2 should allow one to write 3rd party application for the rower. I've managed to create a prototype, which uses a javafx control (jfxtra control), a shim library written in C using Visual C++ 2010 Express and the libraries delivered with the SDK. See (https://www.youtube.com/watch?v=9wshu_TufRs)

The documentation for the SDK I've store here.

Programming the original prototype as described above was not a problem; however, when I tried to improve parts of it I ran into troubles. One of these was the ability to bundle PM commands together as I've described here in the online forum from concept2 (http://www.c2forum.com/viewtopic.php?f=15&t=16490)

bundling commands with 

CSAFE_SETUSERCFG1_CMD for PM4


Hello,

I’m trying to use the CSAFE_SETUSERCFG1_CMD with the tkcmdsetCSAFE_command function as a wrapper for three other PM commands; namely: CSAFE_GETHORIZONTAL_CMD, CSAFE_GETCADENCE_CMD and CSAFE_GETPACE_CMD; but have not been successful. My call to the above CSAFE method returns without any error but I never get any results back. 

I’ve had no problems calling the commands individually (see here: https://www.youtube.com/watch?v=9wshu_TufRs) but now I would like to bundle them together for efficiency reasons.

I got the idea to do so from the documentation: “Command Example #2 – Get PM3Worktime and Get PM3Workdistance Command” but now believe that I may have misunderstood something.

My code without the initialization looks as follows:

/----------------------------------------------------------------------------------------------/
void pollpm4()
{
UINT16_T unit_address = 0;
UINT16_T cmd_data_size = 0;
UINT32_T cmd_data[64] = {0x00};
UINT16_T rsp_data_size = 100;
UINT32_T rsp_data[64] = {0x00};
ERRCODE_T ecode;
unit_address = 0;

cmd_data[0] = (UINT32_T) 0x1A;
cmd_data[1] = (UINT32_T) 3;
cmd_data[2] = (UINT32_T) 0xA1; //CSAFE_GETHORIZONTAL_CMD
cmd_data[3] = (UINT32_T) 0xA7; //CSAFE_GETCADENCE_CMD
cmd_data[4] = (UINT32_T) 0xA6; //CSAFE_GETPACE_CMD 0xA6
cmd_data_size = 5;

int cnt = 1;
while(1){

rsp_data_size = 100;
memset(rsp_data, 0x00, sizeof(rsp_data));

ecode = tkcmdsetCSAFE_command(unit_address, cmd_data_size, cmd_data, &rsp_data_size, rsp_data);
printf("%04d -> %d %d : %X %u : %X %u %u %u : %X %u %u %u : %X %u %u %u \n",
cnt, ecode, rsp_data_size,
rsp_data[0], rsp_data[1],
rsp_data[2], rsp_data[3], rsp_data[4], rsp_data[5],
rsp_data[6], rsp_data[7], rsp_data[8], rsp_data[9],
rsp_data[10], rsp_data[11], rsp_data[12], rsp_data[13]);

cnt++;
if(ecode){
printError(ecode);
}

//
Sleep(500);
}
}
/----------------------------------------------------------------------------------------------/

And the output as follows:

intialization successful
COMMAND_DISCOVER successful: message is: PM's discovered: 1
COMMAND_GET_SERIAL_NUM successful: message is: 4XXXXXXXX
COMMAND_INIT_PROTOCOL successful: message is:
0001 -> 0 2 : 1A 0 : 0 0 0 0 : 0 0 0 0 : 0 0 0 0
0002 -> 0 2 : 1A 0 : 0 0 0 0 : 0 0 0 0 : 0 0 0 0
0003 -> 0 2 : 1A 0 : 0 0 0 0 : 0 0 0 0 : 0 0 0 0
0004 -> 0 2 : 1A 0 : 0 0 0 0 : 0 0 0 0 : 0 0 0 0
0005 -> 0 2 : 1A 0 : 0 0 0 0 : 0 0 0 0 : 0 0 0 0

Many thanks for your help,
William

/-----------------------------my 1st reply--------------------------------------------------/
Ok, maybe I’ve found it. It seems as if I should be using the CSAFE_GETPMDATA_CMD as a command wrapper instead of the CSAFE_SETUSERCFG1_CMD; however, this is a proprietary command, which requires “authentication”. Can someone tell me what is meant by authentication is this case?

In the SDK documentation, I found the following: These commands are not accessible via the “public” interface and require special “authentication” with the PM3/PM4 to function.

/-----------------------------my 2nd reply--------------------------------------------------/
 downloaded the code for the “Concept2 Watt Challenge” and built is using the libraries supplied with the code and it worked. The application bundles the PM commands together exactly as I would like to. 

I then rebuilt the application to run with the “newer” libraries from the SDK and it didn't work anymore. I get a checksum error:
C2Erg::PollThread->Error (-161): TKFRAME_CSAFE_FRAME_CHKSM_ERR CSAFE frame checksum error.

I realize that I had to change some minor things in the application in oder for it to work with the new libraries but I don’t think my changes have anything to do with the above error.
On the wire they every thing looks fine: 
Request:
f0:fd:00:1a:03:a3:a6:b4:a8:f2:00:00:00:3a:f2
Reply:
f0:00:fd:01:1a:07:a3:05:00:00:00:00:00:ba:f2

So I don’t understand the error message.

I guess I could use the libraries provided with the Watt Challenge application rather than those with the SDK but that wouldn’t be so nice.


/-------------------------------------------------------------------------------------------/

The Watt Challenge can be cound here.

http://www.concept2.com/service/software/concept2-watt-challenge

Recompiling it involved down loading Qt building it and then creating a VC++ project that would be with it. This required creating the following batch file:

set QTDIR=C:\Programms\Qt\4.8.4
set PATH=%PATH%;%QTDIR%\bin
set QMAKESPEC=win32-msvc2010
qmake your_qmake_proj.pro
pause

The  your_qmake_proj.pro file was like this ( of course the name should have been something other than your_qmake_proj.pro):

 TEMPLATE = vcapp
 DESTDIR  = C:/Projekte/concept2/workspace/devstudio/c2watt
 HEADERS += C2Logger.h
 HEADERS += c2watt.h
 //all header files here...
 HEADERS += wattmeter.h
 SOURCES += C2Logger.cpp
 SOURCES += c2watt.cpp
//all source files here ...
 SOURCES += WattMeter.cpp
 DEFINES += QT_DLL
 CONFIG  += qt warn_on release

After running the above batch, I had a VC++ project, which I could open and build. Of course, I had to add in the libraries path and what not.