Skip to content

Commit b23b0ef

Browse files
committed
usb: Print correct firmware version number
Blob #3 is the main one in the firmware's 7 blobs, and should represent version of other blobs, except the bootloader blobs which is never updated and not to be bothered with about their versions. The official SDK uses only blob #3 to report the version. Use it for the version number here.
1 parent 68e6c24 commit b23b0ef

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

include/internal/libfreenect2/protocol/response.h

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class SerialNumberResponse
4646
public:
4747
SerialNumberResponse(const unsigned char *data, int length)
4848
{
49-
char *c = new char[length / 2];
49+
char *c = new char[length / 2 + 1]();
5050

5151
for(int i = 0, j = 0; i < length; i += 2, ++j)
5252
{
@@ -70,18 +70,16 @@ class FirmwareVersionResponse
7070
private:
7171
struct FWSubsystemVersion
7272
{
73-
uint16_t minor;
74-
uint16_t major;
75-
uint16_t build;
76-
uint16_t revision;
77-
uint16_t reserved0[4];
73+
uint32_t maj_min;
74+
uint32_t revision;
75+
uint32_t build;
76+
uint32_t reserved0;
7877

7978
FWSubsystemVersion()
8079
{
81-
major = 0;
82-
minor = 0;
83-
build = 0;
80+
maj_min = 0;
8481
revision = 0;
82+
build = 0;
8583
}
8684
};
8785

@@ -92,24 +90,23 @@ class FirmwareVersionResponse
9290
int n = length / sizeof(FWSubsystemVersion);
9391
const FWSubsystemVersion *sv = reinterpret_cast<const FWSubsystemVersion *>(data);
9492

95-
for(int i = 0; i < n && sv->major > 0; ++i, ++sv)
93+
for(int i = 0; i < 7 && i < n; ++i)
9694
{
97-
versions_.push_back(*sv);
95+
versions_.push_back(sv[i]);
9896
}
9997
}
10098

10199
std::string toString()
102100
{
103101
FWSubsystemVersion max;
104-
for(int i = 0; i < versions_.size(); ++i)
102+
std::stringstream version_string;
103+
// the main blob's index
104+
int i = 3;
105+
if (i < versions_.size())
105106
{
106-
max.major = std::max<uint16_t>(max.major, versions_[i].major);
107-
max.minor = std::max<uint16_t>(max.minor, versions_[i].minor);
108-
max.build = std::max<uint16_t>(max.build, versions_[i].build);
109-
max.revision = std::max<uint16_t>(max.revision, versions_[i].revision);
107+
const FWSubsystemVersion &ver = versions_[i];
108+
version_string << (ver.maj_min >> 16) << "." << (ver.maj_min & 0xffff) << "." << ver.revision << "." << ver.build;
110109
}
111-
std::stringstream version_string;
112-
version_string << max.major << "." << max.minor << "." << max.build << "." << max.revision << "." << versions_.size();
113110

114111
return version_string.str();
115112
}

0 commit comments

Comments
 (0)