2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @see The GNU Public License (GPL) Version 3
7 * @brief Junsi Powerlog utility CLI
9 *****************************************************************************/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <QtCore/QCoreApplication>
28 #include <../../plugins/rawhid/pjrc_rawhid.h>
34 typedef unsigned long ULONG
; // 4 Bytes
36 typedef unsigned short USHORT
; // 2 Bytes
37 typedef unsigned char BYTE
; // 1 Byte
38 typedef unsigned short WORD
; // 2 Bytes
39 typedef unsigned long DWORD
; // 4 Bytes
42 class MyParser
: public QObject
{
43 struct POWERLOG_HID_PACK
{
59 TYPE_DATA_ONLINE
= 0x10,
60 TYPE_DATA_OFFLINE
= 0x11,
69 qDebug() << "Connect a Junsi PowerLog 6S and watch the logging output";
70 pjrc_rawhid hidHandle
;
71 int numDevices
= hidHandle
.open(1, 0x0483, 0x5750, 0, 0); // 0xff9c,0x0001);
72 if (numDevices
== 0) {
73 numDevices
= hidHandle
.open(1, 0x0483, 0, 0, 0);
76 qDebug() << numDevices
<< " device(s) opened";
78 // hidHandle.mytest(0);
84 cout
<< "Interval,Current,Volt,Cap,Cell1,Cell2,Cell3,Cell4,Cell5,Cell6,RPM,Temp1,Temp2,Temp3,Temp4,Period,Pulse" << endl
;
86 while (int received
= hidHandle
.receive(0, buf
, BUF_LEN
, 3500)) {
92 void ShowInf(char *pBuf
)
94 // qDebug() << "--------------------";
95 POWERLOG_HID_PACK Inf
;
100 Inf
.Len
= pBuf
[Count
];
101 Count
+= sizeof(Inf
.Len
);
103 Inf
.Type
= pBuf
[Count
];
104 Count
+= sizeof(Inf
.Type
);
106 Inf
.Interval
= *((DWORD
*)&pBuf
[Count
]);
107 printf("%ld,", Inf
.Interval
);
109 Count
+= sizeof(Inf
.Interval
);
111 Inf
.LogState
= pBuf
[Count
];
112 Count
+= sizeof(Inf
.LogState
);
114 if (((Inf
.Type
== TYPE_DATA_ONLINE
) || (Inf
.Type
== TYPE_DATA_OFFLINE
)) && (Inf
.Len
== 0x29)) { // 0x27
115 Inf
.Current
= *((SHORT
*)&pBuf
[Count
]);
116 Count
+= sizeof(Inf
.Current
);
117 GetShowValue(QString("Current:"), Inf
.Current
, 5, 2);
119 Inf
.Volt
= *((USHORT
*)&pBuf
[Count
]);
120 Count
+= sizeof(Inf
.Volt
);
121 GetShowValue(QString("Voltage:"), Inf
.Volt
, 5, 2);
123 Inf
.Cap
= *((DWORD
*)&pBuf
[Count
]);
124 Count
+= sizeof(Inf
.Cap
);
125 GetShowValue(QString("Cap:"), Inf
.Cap
, 6, 0);
127 for (i
= 0; i
< 6; i
++) {
128 Inf
.Cell
[i
] = *((SHORT
*)&pBuf
[Count
]);
129 Count
+= sizeof(Inf
.Cell
[i
]);
131 GetShowValue(QString("Cell 1:"), Inf
.Cell
[0], 5, 3);
132 GetShowValue(QString("Cell 2:"), Inf
.Cell
[1], 5, 3);
133 GetShowValue(QString("Cell 3:"), Inf
.Cell
[2], 5, 3);
134 GetShowValue(QString("Cell 4:"), Inf
.Cell
[3], 5, 3);
135 GetShowValue(QString("Cell 5:"), Inf
.Cell
[4], 5, 3);
136 GetShowValue(QString("Cell 6:"), Inf
.Cell
[5], 5, 3);
138 Inf
.RPM
= *((USHORT
*)&pBuf
[Count
]);
139 Count
+= sizeof(Inf
.RPM
);
140 GetShowValue(QString("RPM:"), Inf
.RPM
, 6, 0);
143 for (i
= 0; i
< 4; i
++) {
144 Inf
.Temp
[i
] = *((SHORT
*)&pBuf
[Count
]);
145 Count
+= sizeof(Inf
.Temp
[i
]);
147 GetShowValue(QString("Int Temp1:"), Inf
.Temp
[0], 4, 1);
148 if (Inf
.Temp
[1] == 0x7fff) {
149 QString txtExtTemp1
= QString("NULL");
151 GetShowValue(QString("Ext temp1:"), Inf
.Temp
[1], 4, 1);
153 if (Inf
.Temp
[2] == 0x7fff) {
154 QString txtExtTemp2
= QString("NULL");
156 GetShowValue(QString("Ext temp2:"), Inf
.Temp
[2], 4, 1);
158 if (Inf
.Temp
[3] == 0x7fff) {
159 QString txtExtTemp3
= QString("NULL");
161 GetShowValue(QString("Ext temp3:"), Inf
.Temp
[3], 4, 1);
164 Inf
.Period
= *((USHORT
*)&pBuf
[Count
]);
165 Count
+= sizeof(Inf
.Period
);
166 GetShowValue(QString("Period:"), Inf
.Period
, 6, 0);
168 Inf
.Pulse
= *((USHORT
*)&pBuf
[Count
]);
169 Count
+= sizeof(Inf
.Pulse
);
170 GetShowValue(QString("Pulse:"), Inf
.Pulse
, 6, 0);
176 void GetShowValue(QString label
, DWORD Value
, WORD Len
, WORD Dot
)
178 // cout << label .toStdString() << " ";
183 printf("-%ld.%01lu", Value
/ 10, Value
% 10);
184 } else if (Dot
== 2) {
185 printf("-%ld.%02lu", Value
/ 100, Value
% 100);
186 } else if (Dot
== 3) {
187 printf("-%ld.%03lu", Value
/ 1000, Value
% 1000);
188 } else if (Dot
== 4) {
189 printf("-%ld.%04lu", Value
/ 10000, Value
% 10000);
191 printf("-%ld", Value
);
195 printf("%ld.%01lu", Value
/ 10, Value
% 10);
196 } else if (Dot
== 2) {
197 printf("%ld.%02lu", Value
/ 100, Value
% 100);
198 } else if (Dot
== 3) {
199 printf("%ld.%03lu", Value
/ 1000, Value
% 1000);
200 } else if (Dot
== 4) {
201 printf("%ld.%04lu", Value
/ 10000, Value
% 10000);
203 printf("%ld", Value
);
211 int main(int argc
, char *argv
[])
213 QCoreApplication
a(argc
, argv
);