Sunday, December 29, 2013

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.






No comments:

Post a Comment