contents
int SCardTransmit(
int hCard,
Pointer<SCARD_IO_REQUEST> pioSendPci,
Pointer<Uint8> pbSendBuffer,
int cbSendLength,
Pointer<SCARD_IO_REQUEST> pioRecvPci,
Pointer<Uint8> pbRecvBuffer,
Pointer<Uint32> pcbRecvLength)
The code I wrote
int SCARD_PROTOCOL = 0;
switch (pdwActiveProtocol.value) {
case SCARD_PROTOCOL_T0:
SCARD_PROTOCOL = SCARD_PROTOCOL_T0;
break;
case SCARD_PROTOCOL_T1:
SCARD_PROTOCOL = SCARD_PROTOCOL_T1;
break;
default:
print("Unknown protocol");
break;
}
int hCard = phCard.value;
List<int> data = [0xff, 0xca, 0x00, 0x00, 0x00];
Uint8List bytes = Uint8List.fromList(data);
Pointer<Uint8> pbSendBuffer = bytes.allocatePointer();
Pointer<Uint8> pbRecvBuffer = calloc<Uint8>();
int cbSendLength = bytes.length;
Pointer<Uint32> pcbRecvLength = pbRecvBuffer.cast<Uint32>();
Pointer<SCARD_IO_REQUEST> pioSendPci = calloc<SCARD_IO_REQUEST>()
..ref.cbPciLength = sizeOf<SCARD_IO_REQUEST>()
..ref.dwProtocol = SCARD_PROTOCOL;
ret = SCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength, nullptr,
pbRecvBuffer, pcbRecvLength);
This was successful, but I cannot get the UID. What is the problem?
I know there is something missing or wrong, but I don't know what it is.
What we use :https://pub.dev/packages/win32
Card reader used: RC-380
add
Uint8List byte = pbRecvBuffer.asTypedList(pcbRecvLength.value);
1:[0, 0, 0, 0, 0, 0, 0, 0, 224, 159]
2:[0, 0, 0, 0, 0, 0, 0, 0, 204, 107]
Different from the first and second time.
int sendCommandToCard(int hCard, int SCARD_PROTOCOL, List<int> command) {
Uint8List bytes = Uint8List.fromList(command);
Pointer<Uint8> pbSendBuffer = bytes.allocatePointer();
int cbSendLength = bytes.length;
const int pbRecvBufferLength = 256; // 缓冲区长度
Pointer<Uint8> pbRecvBuffer = Uint8List(pbRecvBufferLength).allocatePointer();
Pointer<Uint32> pcbRecvLength = calloc<Uint32>();
pcbRecvLength.value = pbRecvBufferLength;
Pointer<SCARD_IO_REQUEST> pioSendPci = calloc<SCARD_IO_REQUEST>()
..ref.cbPciLength = sizeOf<SCARD_IO_REQUEST>()
..ref.dwProtocol = SCARD_PROTOCOL;
int retCode = SCardTransmit(hCard, pioSendPci, pbSendBuffer, cbSendLength, nullptr, pbRecvBuffer, pcbRecvLength);
if (retCode == SCARD_S_SUCCESS) {
Uint8List byte = pbRecvBuffer.asTypedList(pcbRecvLength.value);
debugPrint("SCardTransmit - result:$retCode lenght:${pcbRecvLength.value} byte:$byte");
}
return retCode;
}
Related
Using a legacy IF field code:
enter image description here
and content controls:
private static byte[] mergingDocxFileWithXml(File file, File fileXml) {WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(file)
MainDocumentPart mainDocumentPart = wordMLPackage.getMainDocumentPart()
ArrayList<String> datas
List<Object> contentControls = ContentControl.getAllContentControl(mainDocumentPart)
List<String> arrayListXpathToBoucle = new ArrayList<>()
for (Object contenControl : contentControls) {
ContentControl cControl = new ContentControl(contenControl)
String xPath = cControl.getXPath()
String title = cControl.getTitle()
if (xPath != null) {
datas = XmlPath.getXmlDataFrom(fileXml, xPath)
}
switch (title) {
case "DateDuJour":
cControl.setValue(getDateDay())
break
case "checkbox":
String checkValue = new String(Character.toChars(0x2612))
if (datas[0] != "1") {
checkValue = new String(Character.toChars(0x2610))
}
cControl.setValue(checkValue)
break
case "Boucle_Ligne":
xPath = cControl.getTag()
int indexBoucleContent = getIndexContentBoucle(wordMLPackage.mainDocumentPart.getContent(), xPath)
NodeList nodeList = XmlPath.getNodeListXmlFile(fileXml, xPath)
List<String> dataXpath = getAllXpathForBoucle(contentControls, xPath)
for (int i = 0; i < dataXpath.stream().count(); i++) {
arrayListXpathToBoucle.add(dataXpath.get(i))
}
int totalNode = nodeList.getLength()
for (int j = 0; j < totalNode; j++) {
wordMLPackage = mapingDataNode(j, cControl, contentControls, fileXml, dataXpath, wordMLPackage, indexBoucleContent, null, 0)
}
wordMLPackage.mainDocumentPart.getContent().remove(indexBoucleContent)
break;
case "Boucle_Colonne":
xPath = cControl.getTag()
NodeList nodeList = XmlPath.getNodeListXmlFile(fileXml, xPath)
List<String> dataXpath = getAllXpathForBoucle(contentControls, xPath)
int totalNode = nodeList.getLength()
for (int i = 0; i < dataXpath.stream().count(); i++) {
arrayListXpathToBoucle.add(dataXpath.get(i))
}
String boucleValue = ""
for (int i = 0; i < totalNode; i++) {
datas = XmlPath.getXmlDataFrom(fileXml, dataXpath.get(0))
boucleValue += datas.get(i) + ", "
}
boucleValue = boucleValue.substring(0, boucleValue.length() - 2)
addValueInContentControl(contentControls, dataXpath.get(0), 0, boucleValue, null, wordMLPackage)
break
case "Boucle_Ligne_Table":
xPath = cControl.getTag()
NodeList nodeList = XmlPath.getNodeListXmlFile(fileXml, xPath)
int indexBoucleContent = getIndexContentBoucle(wordMLPackage.mainDocumentPart.getContent(), xPath)
List<String> dataXpath = getAllXpathForBoucle(contentControls, xPath)
int totalNode = nodeList.getLength()
for (int i = 0; i < dataXpath.stream().count(); i++) {
arrayListXpathToBoucle.add(dataXpath.get(i))
}
int nodeIndex = 0
Tbl arraysBoucle = getArraysBoucle(wordMLPackage, indexBoucleContent)
Tr trContent
for (int i = 0; i < totalNode; i++) {
nodeIndex = i + 1
if (arraysBoucle.getContent().stream().count() > 1) {
trContent = WoeDocx4jFunction.getTr(arraysBoucle.getContent().get(1))
} else {
trContent = WoeDocx4jFunction.getTr(arraysBoucle.getContent().get(0))
}
wordMLPackage = mapingDataNode(i, cControl, contentControls, fileXml, dataXpath, wordMLPackage, indexBoucleContent, trContent, nodeIndex)
}
int lastIndexTr = wordMLPackage.getMainDocumentPart().getContent().get(indexBoucleContent).sdtContent.content.get(1).value.content.stream().count()
wordMLPackage.getMainDocumentPart().getContent().get(indexBoucleContent).sdtContent.content.get(1).value.content.remove(lastIndexTr - 1)
break
case "IMAGE":
datas = XmlPath.getXmlDataFrom(fileXml, xPath)
byte[] imageByte = base64ToImage(datas.get(0))
Inline inlineImage = newImage(wordMLPackage, imageByte)
cControl.setValue(null, inlineImage)
break
default:
String xpathBoucle = arrayListXpathToBoucle.find { it.startsWith(xPath) }
if (xpathBoucle != xPath) {
addValueInContentControl(contentControls, xPath, 0, "", fileXml,wordMLPackage)
}
break
}
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
wordMLPackage= mergingFieldWordMlPackage(wordMLPackage)
FieldUpdater updater = new FieldUpdater(wordMLPackage)
updater.update(true);
wordMLPackage.save(outputStream);
return outputStream.toByteArray();
}
Docx4j's legacy field processing does not parse IF fields: http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/IF.html
If you need to do that, you'll need to write code to do the parsing.
An alternative would be to use OpenDoPE conditional content controls. With one of these, the content of the SDT is included only if the associated XPath evaluates to true.
I'm very new to OR-Tools and I'm trying to solve a modified VRP with capacity constraints from Google's guide.
In my problem vehicles transport multiple types of items. Some types can be transported together and others cannot.
What I tried
In the following code the types are A and B (they should not be transported together).
First I defined the two callbacks for demands and added the dimensions to the routing model
int demandACallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) => {
var fromNode = manager.IndexToNode(fromIndex);
return demandsA[fromNode];
});
int demandBCallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) => {
var fromNode = manager.IndexToNode(fromIndex);
return demandsB[fromNode];
});
routing.AddDimensionWithVehicleCapacity(demandACallbackIndex, 0,
capacitiesA,
true,
"CapacityA");
routing.AddDimensionWithVehicleCapacity(demandBCallbackIndex, 0,
capacitiesB,
true,
"CapacityB");
Then I retrieved the dimensions and added constraints to routing.solver() for every node
var capacityADimension = routing.GetDimensionOrDie("CapacityA");
var capacityBDimension = routing.GetDimensionOrDie("CapacityB");
for (int i = 0; i < noDeliveries; i++) {
var index = manager.NodeToIndex(i);
routing.solver().Add(capacityADimension.CumulVar(index) * capacityBDimension.CumulVar(index) == 0);
}
When I run the solver (with two vehicles) these constraints seem to be ignored (one vehicle remains parked while the other does all the work even though it shouldn't transport both types of items).
Is this even possible with OR-Tools? If yes, what did I do wrong?
Full code
public SimpleVehicleRoutingSolutionDto SolveVehicleRoutingWithItemConstraints(long[,] distances, long[] capacitiesA, long[] capacitiesB, long[] demandsA, long[] demandsB, int depot)
{
int noVehicles = capacitiesA.Length;
int noDeliveries = deliveriesA.Length;
RoutingIndexManager manager =
new RoutingIndexManager(noDeliveries, noVehicles, depot);
RoutingModel routing = new RoutingModel(manager);
int transitCallbackIndex = routing.RegisterTransitCallback((long fromIndex, long toIndex) => {
var fromNode = manager.IndexToNode(fromIndex);
var toNode = manager.IndexToNode(toIndex);
return distances[fromNode, toNode];
});
routing.SetArcCostEvaluatorOfAllVehicles(transitCallbackIndex);
int demandACallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) => {
// Convert from routing variable Index to demand NodeIndex.
var fromNode = manager.IndexToNode(fromIndex);
return demandsA[fromNode];
});
int demandBCallbackIndex = routing.RegisterUnaryTransitCallback((long fromIndex) => {
// Convert from routing variable Index to demand NodeIndex.
var fromNode = manager.IndexToNode(fromIndex);
return demandsB[fromNode];
});
routing.AddDimensionWithVehicleCapacity(demandACallbackIndex, 0,
capacitiesA,
true,
"CapacityA");
routing.AddDimensionWithVehicleCapacity(demandBCallbackIndex, 0,
capacitiesB,
true,
"CapacityB");
var capacityADimension = routing.GetDimensionOrDie("CapacityA");
var capacityBDimension = routing.GetDimensionOrDie("CapacityB");
for (int i = 0; i < noDeliveries; i++) {
var index = manager.NodeToIndex(i);
routing.solver().Add(capacityADimension.CumulVar(index) * capacityBDimension.CumulVar(index) == 0);
}
RoutingSearchParameters searchParameters =
operations_research_constraint_solver.DefaultRoutingSearchParameters();
searchParameters.FirstSolutionStrategy = FirstSolutionStrategy.Types.Value.PathCheapestArc;
searchParameters.LocalSearchMetaheuristic = LocalSearchMetaheuristic.Types.Value.GuidedLocalSearch;
searchParameters.TimeLimit = new Duration { Seconds = 1 };
Assignment solution = routing.SolveWithParameters(searchParameters);
var ret = new SimpleVehicleRoutingSolutionDto();
long totalDistance = 0;
for (int i = 0; i < noVehicles; ++i)
{
var vecihle = new VehiclePathDto { Index = i };
long routeDistance = 0;
var index = routing.Start(i);
while (routing.IsEnd(index) == false)
{
long nodeIndex = manager.IndexToNode(index);
vecihle.Waypoints.Add(new WaypointDto { Index = nodeIndex });
var previousIndex = index;
index = solution.Value(routing.NextVar(index));
routeDistance += routing.GetArcCostForVehicle(previousIndex, index, 0);
}
vecihle.Distance = routeDistance;
ret.Vehicles.Add(vecihle);
totalDistance += routeDistance;
}
ret.TotalDistance = totalDistance;
return ret;
}
And the input:
long[,] dist = {
{ 0, 5, 6 },
{ 5, 0, 3 },
{ 6, 3, 0 }
};
long[] capA = { 5, 5 };
long[] capB = { 5, 5 };
long[] demA = { 0, 1, 0 };
long[] demB = { 0, 0, 1 };
var routingSolution = vehicleRouting.SolveVehicleRoutingWithItemConstraints(dist, capA, capB, demA, demB, 0);
I fixed the problem.
The issue was that the number of nodes was 3 (noDeliveries), however the number of indices was 6, so I only set the constraint on half of them.
Fixed code:
for (int i = 0; i < manager.GetNumberOfIndices(); i++) {
routing.solver().Add(capacityADimension.CumulVar(i) * capacityBDimension.CumulVar(i) == 0);
}
EDIT:
Even better if constraints are set only for the route end node, since the CumulVar value is strictly increasing.
for (int j = 0; j < noVehicles; j++) {
var index = routing.End(j);
routing.solver().Add(capacityADimension.CumulVar(index) * capacityBDimension.CumulVar(index) == 0);
}
I am facing issue with calling to recvfrom function:
recvfrom(sock, dat, sizeof(dat), 0, (void *)&peername, &peernamelen);
Until this all functions are working.
Please let me know where I am making mistake. Should I use bind or not, or any mistake from this.
Output:
before sockname
after sockname
after sock
after setsockopt
after Bind
before recvfrom
My code:
struct sockaddr_can sockname = {
.can_family = AF_CAN,
.can_addr.j1939 = {
.addr = J1939_NO_ADDR,
.name = J1939_NO_NAME,
.pgn = J1939_NO_PGN,
},
}, peername = {
.can_family = AF_CAN,
.can_addr.j1939 = {
.addr = J1939_NO_ADDR,
.name = J1939_NO_NAME,
.pgn = J1939_NO_PGN,
},
};
uint8_t dat[128];
int valid_peername = 0;
unsigned int todo_send = 0;
int todo_recv = 0, todo_echo = 0, todo_prio = -1;
int todo_connect = 0, todo_names = 0, todo_wait = 0, todo_rebind = 0;
int todo_broadcast = 0, todo_promisc = 0;
int no_bind = 0,i;
printf("before sockname\n");
sockname.can_ifindex = if_nametoindex(CAN_SOCKET_NAME);
printf("after sockname\n");
sock = socket(PF_CAN, SOCK_DGRAM, CAN_J1939);
printf("after sock\n");
setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &todo_broadcast, sizeof(todo_broadcast));
printf("after setsockopt\n");
ret = bind(sock, (void *)&sockname, sizeof(sockname));
if (ret < 0)
err(1, "bind()");
printf("after Bind\n");
while(1){
peernamelen = sizeof(peername);
printf("before recvfrom\n");
recvfrom(sock, dat, sizeof(dat), 0, (void *)&peername, &peernamelen);
printf("%02x %05x:", peername.can_addr.j1939.addr, peername.can_addr.j1939.pgn);
for (i = 0, j = 0; i < ret; ++i, j++) {
if (j == 8) {
printf("\n%05x ", i);
j = 0;
}
printf(" %02x", dat[i]);
}
printf("\n");
}
Please help me to solve this issue.
I donwloaded BIOS rom and get list of files using UEFITool:
ROM Structure
So i know "names" of all files that exist. Then i tried to get file using "GetSectionFromAnyFv" but can't get all files, just files in volume under red arrow. For example volume under violet arrow also have files, but i can't get it.
LocateHandleBuffer (ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &NumberOfHandles, &HandleBuffer) return only 1 handle [NumberOfHandles = 1], but as i can see there are more than 1 volume.
Same if i try get file using for(for NumberOfHandles) and iterate over all files getting guids. Just can't get all files.
What could be the problem?
P.S.: ProcessFirmwareVolume for every FV2 HOBs return 20 so that means that "firmware volume block protocol" is alredy processed.
#include "FileByGuid.h"
EFI_GUID TextToGuid(CHAR16* stGUID)
{
EFI_GUID NameGuid;
stGUID[8] = '\0';
stGUID[13] = '\0';
stGUID[18] = '\0';
NameGuid.Data1 = (UINT32)StrHexToUintn(&stGUID[0]);
NameGuid.Data2 = (UINT16)StrHexToUintn(&stGUID[9]);
NameGuid.Data3 = (UINT16)StrHexToUintn(&stGUID[14]);
for (int i = 23; i < 37; i++)
{
Print(L"");
stGUID[i] = stGUID[i + 1];
}
UINTN D4 = StrHexToUintn(&stGUID[19]);
for (int i = 7; i >= 0; i--)
{
NameGuid.Data4[i] = (UINT8)(D4 & 0xFF);
D4 = D4 >> 8;
}
return NameGuid;
}
EFI_STATUS
EFIAPI
FileByGuidDriverEntryPoint(
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE* SystemTable
)
{
EFI_FIRMWARE_VOLUME2_PROTOCOL* fv;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* fs;
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL* fvb;
EFI_DEVICE_PATH_PROTOCOL* dp;
EFI_BLOCK_IO2_PROTOCOL* bio;
EFI_BLOCK_IO_PROTOCOL* bio2;
EFI_FILE_PROTOCOL *OpenedFileHandle;
EFI_FILE_HANDLE Root;
EFI_STATUS Status, GetSectionStatus;
UINTN index;
EFI_HANDLE *sfsHandleBuffer = NULL;
EFI_HANDLE *fvHandleBuffer = NULL;
EFI_HANDLE *fvbHandleBuffer = NULL;
EFI_HANDLE* bioHandleBuffer = NULL;
EFI_HANDLE* bio2HandleBuffer = NULL;
EFI_HANDLE FvProtocolHandle;
UINTN sfsHandleCount = 0;
UINTN fvHandleCount = 0;
UINTN fvbHandleCount = 0;
UINTN bioHandleCount = 0;
UINTN bio2HandleCount = 0;
UINTN Size;
EFI_FV_FILETYPE FileType;
UINTN counter = 0;
VOID *Buffer;
VOID *Key;
EFI_GUID fvNameGuid;
EFI_GUID NameGuid;
CHAR16* stGUID = L"114CA60C-D965-4C13-BEF7-C4062248E1FA";
// UINTN EventIndex;
// EFI_INPUT_KEY Keys;
EFI_FV_FILE_ATTRIBUTES Attributes;
EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader;
EFI_PEI_HOB_POINTERS Hob;
// BOOLEAN MediaPresent;
// PARTITION_DETECT_ROUTINE* Routine;
// BOOLEAN MediaPresent;
// EFI_DISK_IO_PROTOCOL* DiskIo;
// EFI_DISK_IO2_PROTOCOL* DiskIo2;
gBS->SetWatchdogTimer(0, 0, 0, NULL);
gST = SystemTable;
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiFirmwareVolumeBlock2ProtocolGuid, NULL, &fvbHandleCount, &fvbHandleBuffer);
AsciiPrint("\r\nfv2_block_HandleCount: %d\r\n", fvbHandleCount);
for (index = 0; index < (int)fvbHandleCount; index++)
{
//Status = gBS->OpenProtocol(fvbHandleBuffer[index], &gEfiFirmwareVolumeBlock2ProtocolGuid, (VOID**)&fvb, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL);
Status = gBS->HandleProtocol(fvbHandleBuffer[index], &gEfiFirmwareVolume2ProtocolGuid, &fvb);
AsciiPrint("-HP fv_block fv2 Status: %d; DevicePath: %s\r\n", Status, ConvertDevicePathToText(DevicePathFromHandle(fvbHandleBuffer[index]), TRUE, TRUE));
}
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &sfsHandleCount, &sfsHandleBuffer);
AsciiPrint("\r\nsfsHandleCount: %d\r\n", sfsHandleCount);
for (index = 0; index < (int)sfsHandleCount; index++)
AsciiPrint("-sfs[%d] handle: %d; device path: %s\r\n", index, sfsHandleBuffer[index], ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiDevicePathProtocolGuid, NULL, &sfsHandleCount, &sfsHandleBuffer);
AsciiPrint("\r\nDevicePathHandleCount: %d\r\n", sfsHandleCount);
//for (index = 0; index < (int)sfsHandleCount; index++)
// AsciiPrint("dp[%d] device path: %s\r\n", index, ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
AsciiPrint("\r\nHOB:\r\n");
for (Hob.Raw = GetHobList(); !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob))
{
if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV2 || GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV || GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV3)
{
FvProtocolHandle = NULL;
FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)(UINTN)(Hob.FirmwareVolume->BaseAddress);
Status = gDS->ProcessFirmwareVolume(FirmwareVolumeHeader, Hob.FirmwareVolume2->Length, &FvProtocolHandle);
if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV3)
AsciiPrint("-FV3: Status: %d; FvProtocolHandle: %d; Extracted?:%d; AuthenStatus:%d;\r\n GUID:%g\r\n", Status, FvProtocolHandle, Hob.FirmwareVolume3->ExtractedFv, Hob.FirmwareVolume3->AuthenticationStatus, Hob.FirmwareVolume3->FvName);
else if (GET_HOB_TYPE(Hob) == EFI_HOB_TYPE_FV2)
AsciiPrint("-FV2: Status: %d; FvProtocolHandle: %d; FileName: %g; \r\n GUID:%g\r\n", Status, FvProtocolHandle, Hob.FirmwareVolume2->FileName, Hob.FirmwareVolume2->FvName);
else
AsciiPrint("-FV: Status: %d; FvProtocolHandle: %d\r\n", Status, FvProtocolHandle);
}
}
AsciiPrint("End HOB\r\n");
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiFirmwareVolume2ProtocolGuid, NULL, &fvHandleCount, &fvHandleBuffer);
AsciiPrint("\r\nfv2HandleCount: %d\r\n", fvHandleCount);
for (index = 0; index < (int) fvHandleCount; index++)
{
Status = gBS->HandleProtocol(fvHandleBuffer[index], &gEfiFirmwareVolume2ProtocolGuid, (VOID**) &fv);
AsciiPrint("-index: %d; HPfvStatus: %d; DevicePath: %s\r\n", index, Status, ConvertDevicePathToText(DevicePathFromHandle(fvbHandleBuffer[index]), TRUE, TRUE));
if (EFI_ERROR(Status))
continue;
FileType = EFI_FV_FILETYPE_ALL;
Key = AllocatePool(fv->KeySize);
ZeroMem(Key, fv->KeySize);
Status = fv->GetNextFile(fv, Key, &FileType, &fvNameGuid, &Attributes, &Size);
while (Status!= EFI_NOT_FOUND)
{
FileType = EFI_FV_FILETYPE_ALL;
counter++;
//if (counter % 15 == 0)
// AsciiPrint("Status: %d; __file_GUID:%g\r\n", Status, fvNameGuid);
Status = fv->GetNextFile(fv, Key, &FileType, &fvNameGuid, &Attributes, &Size);
}
AsciiPrint("sectionFilesCount: %d\r\n", counter);
counter = 0;
FreePool(Key);
}
NameGuid = TextToGuid(stGUID);
//AsciiPrint("\r\n%g\r\n", NameGuid);
GetSectionStatus = GetSectionFromAnyFv(&NameGuid, EFI_SECTION_ALL, 0, (VOID**)&Buffer, &Size);
AsciiPrint("GetSectionFromAnyFvStatus = %d\r\n", Status);
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &bioHandleCount, &bioHandleBuffer);
AsciiPrint("\r\nbioHandleCount: %d\r\n", bioHandleCount);
for (index = 0; index < (int)bioHandleCount; index++)
{
Status = gBS->HandleProtocol(bioHandleBuffer[index], &gEfiBlockIoProtocolGuid, &bio);
dp = DevicePathFromHandle(bioHandleBuffer[index]);
while (!IsDevicePathEnd(NextDevicePathNode(dp)))
dp = NextDevicePathNode(dp);
AsciiPrint("-HP BlockIO Status: %d; handle: %d; DevicePath: %s\r\n", Status, bioHandleBuffer[index], ConvertDevicePathToText(dp, TRUE, TRUE));
AsciiPrint("--MediaPresent: %d; RemovableMedia: %d; LogicalPartition: %d\r\n", bio->Media->MediaPresent, bio->Media->RemovableMedia, bio->Media->LogicalPartition);
}
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiBlockIo2ProtocolGuid, NULL, &bio2HandleCount, &bio2HandleBuffer);
AsciiPrint("\r\nbio2HandleCount: %d\r\n", bio2HandleCount);
for (index = 0; index < (int)bio2HandleCount; index++)
{
Status = gBS->HandleProtocol(bio2HandleBuffer[index], &gEfiBlockIo2ProtocolGuid, &bio2);
dp = DevicePathFromHandle(bio2HandleBuffer[index]);
while (!IsDevicePathEnd(NextDevicePathNode(dp)))
dp = NextDevicePathNode(dp);
AsciiPrint("-HP BlockIO2 Status: %d; handle: %d; DevicePath: %s\r\n", Status, bio2HandleBuffer[index], ConvertDevicePathToText(dp, TRUE, TRUE));
AsciiPrint("--MediaPresent: %d; RemovableMedia: %d; LogicalPartition: %d\r\n", bio2->Media->MediaPresent, bio2->Media->RemovableMedia, bio2->Media->LogicalPartition);
}
AsciiPrint("\r\n");
//save
if (!EFI_ERROR(GetSectionStatus))
{
Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &sfsHandleCount, &sfsHandleBuffer);
for (index = 0; index < (int)sfsHandleCount; index++)
{
fs = NULL;
OpenedFileHandle = NULL;
Root = NULL;
Status = gBS->HandleProtocol(sfsHandleBuffer[index], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&fs);
if (EFI_ERROR(Status))
continue;
Status = fs->OpenVolume(fs, &Root);
Status = Root->Open(Root, &OpenedFileHandle, L"EFI\\Boot", EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(Status))
continue;
Status = Root->Open(Root, &OpenedFileHandle, L"file", EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if (!EFI_ERROR(Status)) //уже существует
Root->Delete(OpenedFileHandle);
Status = Root->Open(Root, &OpenedFileHandle, L"file", EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0);
if (!EFI_ERROR(Status))
{
Status = Root->Write(OpenedFileHandle, &Size, Buffer);
AsciiPrint("WriteSt:%d; DevicePath:%s\r\n", Status, ConvertDevicePathToText(DevicePathFromHandle(sfsHandleBuffer[index]), TRUE, TRUE));
}
Status = Root->Close(OpenedFileHandle);
}
}
if (Buffer != NULL)
FreePool(Buffer);
return EFI_SUCCESS;
}
Getting all handles that support FV2 protocol;
Processing all HOBs so number of handles that support FV2 protocol may increase;
For FV2 protocol i get count of handles and then get Volume names (device path for handle that support FV2 protocol) and files count: Here i can see that not all volumes are processd;
GetSectionFromAnyFv(*) then not interresting part and last saving file using simple file system protocol.
I try to Encoding the std::string from UTF8,... to Hexadecimal. What I can't do right now is that I can't get the decimal value of each character of the input string to convert it if the input string contains special character which is from the Code Page Identifiers(windows-1258) include Vietnamese character.
At first, I will get the decimal value and then convert it to Binary and then to Hexadecimal. s is my input string. s = "Ồ".
void StringUtils::strToBinary(wstring s, string* result)
{
int n = s.length();
for (int i = 0; i < n; i++)
{
wchar_t c = s[i];
long val = long(c);
std::string bin = "";
while (val > 0)
{
(val % 2) ? bin.push_back('1') :
bin.push_back('0');
val /= 2;
}
reverse(bin.begin(), bin.end());
result->append(convertBinToHex(bin));
}
}
std::string StringUtils::convertBinToHex(std::string temp) {
long long binaryValue = atoll(temp.c_str());
long long dec_value = 0;
int base = 1;
int i = 0;
while (binaryValue) {
long long last_digit = binaryValue % 10;
binaryValue = binaryValue / 10;
dec_value += last_digit * base;
base = base * 2;
}
char hexaDeciNum[10];
while (dec_value != 0)
{
int temp = 0;
temp = dec_value % 16;
if (temp < 10)
{
hexaDeciNum[i] = temp + 48;
i++;
}
else
{
hexaDeciNum[i] = temp + 55;
i++;
}
dec_value = dec_value / 16;
}
std::string str;
for (int j = i - 1; j >= 0; j--) {
str = str + hexaDeciNum[j];
}
return str;
}
If my input only contain "Ồ" this is what my expected output
UTF8 : E1BB92
UTF16 : FEFF 1ED2
UTF16BE : 1ED2
UTF16LE : D21E
This how I do it in Java
Charset charset = Charset.forName(Enum.valueOf(Encoding.class, encodingType).toString());
ByteBuffer buffer = charset.newEncoder().encode(CharBuffer.wrap(inputString.toCharArray()));
byte[] bytes = new byte[buffer.limit()];
buffer.get(bytes, 0, buffer.limit());
result = new ByteField(bytes);
return result;
}