1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#include "FirmwareUpdateManager.h"
#include "lmdfu.h"
#include "lmdfuwrap.h"
#include "DFUMode.h"
namespace Tango
{
namespace FirmwareUpdateLib
{
void FirmwareUpdateManager::Initialize()
{
tLMDFUErr eRetcode = _LMDFUInit();
if (eRetcode != DFU_OK)
{
switch (eRetcode)
{
case DFU_ERR_NOT_FOUND:
throw gcnew InvalidOperationException(DFU_ERR_NOT_FOUND_ERROR);
break;
case DFU_ERR_INVALID_ADDR:
throw gcnew InvalidOperationException(DFU_ERR_INVALID_ADDR_ERROR);
break;
default:
throw gcnew InvalidOperationException(DFU_ERR_UNKNOWN_ERROR);
break;
}
}
}
List<DFUDevice^>^ FirmwareUpdateManager::GetAvailableDevices(bool fetchTwineExtras)
{
int iDevIndex = 0;
tLMDFUDeviceInfo devInfo;
tLMDFUHandle hHandle;
tLMDFUErr eRetcode;
unsigned short usStringLen;
char pcStringBuf[256];
bool g_bReset = false;
List<DFUDevice^>^ devices = gcnew List<DFUDevice^>();
do
{
eRetcode = _LMDFUDeviceOpen(iDevIndex, &devInfo, &hHandle);
if (eRetcode == DFU_OK)
{
tLMDFUDeviceInfo *psDevInfo = &devInfo;
DFUDevice^ device = gcnew DFUDevice(psDevInfo, hHandle);
device->VID = String::Format("0x{0}", psDevInfo->usVID);
device->PID = String::Format("0x{0}", psDevInfo->usPID);
//Device Name.
usStringLen = sizeof(pcStringBuf);
eRetcode = _LMDFUDeviceASCIIStringGet(hHandle, psDevInfo->ucProductString,
pcStringBuf, &usStringLen);
device->DeviceName = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown";
//Manufacturer.
usStringLen = sizeof(pcStringBuf);
eRetcode = _LMDFUDeviceASCIIStringGet(hHandle,
psDevInfo->ucManufacturerString,
pcStringBuf, &usStringLen);
device->Manufacturer = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown";
//DFU Interface.
usStringLen = sizeof(pcStringBuf);
eRetcode = _LMDFUDeviceASCIIStringGet(hHandle,
psDevInfo->ucDFUInterfaceString,
pcStringBuf, &usStringLen);
device->DFUInterface = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown";
//Serial Number.
usStringLen = sizeof(pcStringBuf);
eRetcode = _LMDFUDeviceASCIIStringGet(hHandle, psDevInfo->ucSerialString,
pcStringBuf, &usStringLen);
device->SerialNumber = eRetcode == DFU_OK ? gcnew String(pcStringBuf) : "Unknown";
//Max bytes transfer.
device->MaxTransfer = psDevInfo->usTransferSize;
//Current device mode.
device->Mode = psDevInfo->bDFUMode ? DFUMode::DFU : DFUMode::RunTime;
//Supports Tiva extensions. (Good for updates)
device->SupportsTivaExtensions = psDevInfo->bSupportsTivaExtensions;
//Attributes.
device->WillDetach = psDevInfo->ucDFUAttributes & DFU_ATTR_WILL_DETACH;
device->ManifestTolerant = psDevInfo->ucDFUAttributes & DFU_ATTR_MANIFEST_TOLERANT;
device->UploadCable = psDevInfo->ucDFUAttributes & DFU_ATTR_CAN_UPLOAD;
device->DownloadCable = psDevInfo->ucDFUAttributes & DFU_ATTR_CAN_DOWNLOAD;
//Read device flash parameters.
tLMDFUParams sDFU;
if (device->SupportsTivaExtensions)
{
eRetcode = _LMDFUParamsGet(hHandle, &sDFU);
if (eRetcode == DFU_OK)
{
device->AppStartAddress = sDFU.ulAppStartAddr;
device->FlashTopAddress = sDFU.ulFlashTop;
device->FlashBlockSize = sDFU.usFlashBlockSize;
device->NumFlashBlocks = sDFU.usNumFlashBlocks;
device->ImageLength = device->FlashTopAddress - device->AppStartAddress;
device->FlashSize = device->FlashBlockSize * device->NumFlashBlocks;
if (fetchTwineExtras)
{
device->FetchTwineExtras();
}
}
}
devices->Add(device);
}
iDevIndex++;
} while (eRetcode == DFU_OK);
return devices;
}
}
}
|