requested the Runtime to terminate it in an unusual way - c++

My problem is:
I built a c++ code for simulating a communication network (using OMNeT++ discrete event simulator) until there is no errors and the simulation completed, when I tried to increase the number of simulated entities, in any run at some point of time the simulation stops with a message printed in the command prompt says “This application has requested the Runtime to terminate it in an unusual way. Please contact the application’s support team for more information” and an error message displayed in a dedicated window under the title Application error says ”The exception unknown software exception (0x40000015) occurred in the application at location ....... ”
I think the problem, i.e., the simulation stops at and due to this part " ((cMessage *)msg->dup() " in the following code (but that may not be correct):
********
`void ChannelAccess::sendToChannel(AirFrame *msg)
{
const ChannelControl::ModuleList& neighbors = cc->getNeighbors(myHostRef);
coreEV << "sendToChannel: sending to gates\n";
// loop through all hosts in range
ChannelControl::ModuleList::const_iterator it;
for (it = neighbors.begin(); it != neighbors.end(); ++it)
{
cModule *mod = *it;
// we need to send to each radioIn[] gate
cGate *radioGate = mod->gate("radioIn");
if (radioGate == NULL)
error("module %s must have a gate called radioIn", mod->fullPath().c_str());
for (int i = 0; i < radioGate->size(); i++)
{
ChannelControl::HostRef h = cc->lookupHost(mod);
if (h == NULL)
error("cannot find module in channel control");
if (h->channel == msg->getChannelNumber())
{
coreEV << "sending message to host listening on the same channel\n";
// account for propagation delay, based on distance in meters
// Over 300m, dt=1us=10 bit times # 10Mbps
sendDirect((cMessage *)msg->dup(),myHostRef->pos.distance(h->pos) / LIGHT_SPEED, mod, radioGate->id() + i);
}
else
coreEV << "skipping host listening on a different channel\n";
}
}
// register transmission in ChannelControl
cc->addOngoingTransmission(myHostRef, msg);
}
`
*********
So, any help will be appreciated as I would like to run the simulation for large number of nodes.
For knowledge I use win xp SP3 and win 7, OMNet++ 3.3, Microsoft visual c++ 2005 express edition, one of the computers I ran the simulation on is i7 processor with 8G RAM.
Thank you in advance.

Related

QT -- QTLowEnergyService->discoverDetails() does not discover non standard characteristics

I am writing a QT application for BLE on windows 10. The windows application is a BLE central, while the peripheral is running on an iOS device (tablet or phone). I pretty much followed the low energy scanner example and I can find the iOS device with the UUID of interest. The problem is that when the service is discovered and after issuing the discoverDetails() to get a list of the characteristics, the QT state machine goes from DiscoveryRequired, DiscoveringServices, Invalid Service, and then it disconnects.
I know this is a QT problem because
I can connect and interact with the peripheral using other applications
https://apps.apple.com/us/app/lightblue/id557428110
https://www.microsoft.com/en-us/p/ble-scanner/9nblggh0j7m0#activetab=pivot:overviewtab
The BLE scanner app (written in C#) from Microsoft, when compiled and run on the same machine as QT, also is able to connect and interact with the iOS peripheral.
I have noticed that other people are had/have the same problem, but I don't see where/if a resolution/workaround was eventually found.
Qt - Cannot read descriptor of the characteristic - BLE
Here is my handler for the QLowEnergyService::ServiceState signal
void BleClient::serviceStateChanged(QLowEnergyService::ServiceState newState)
{
switch (newState)
{
case QLowEnergyService::DiscoveringServices) :
{
// Nothing to do here, just note that we got into this state
qDebug() << "Discovering services";
break;
}
case QLowEnergyService::ServiceDiscovered:
{
qDebug() << "Service discovered";
const QList<QLowEnergyCharacteristic> chars = m_currentService->characteristics();
for (const QLowEnergyCharacteristic& ch : chars) {
auto cInfo = new CharacteristicInfo(ch);
m_characteristics.append(cInfo);
}
if (!chars.isValid()) {
setMessage("Value for characteristic not found.");
break;
}
m_notificationDesc = chars.descriptor(QBluetoothUuid::ClientCharacteristicConfiguration);
if (m_notificationDesc.isValid()) {
m_service->writeDescriptor(m_notificationDesc, QByteArray::fromHex("0100"));
setMessage("Characteristic enabled");
m_start = QDateTime::currentDateTime();
}
break;
}
default:
qDebug() << "Unhandled state received : (" << newState << ")";
}
}
Ok, figured it out. Added more debug code and saw that a very descriptive error was being logged:
QLowEnergyService error: UnknownError
Looking further, seems like , the QLowEnergyController needs a queued connection callback for the serviceDiscovered event to work as expected. So I changed
connect(controller, &QLowEnergyController::discoveryFinished, this, &BleClient::serviceScanDone);
to
connect(controller, &QLowEnergyController::discoveryFinished, this, &BleClient::serviceScanDone, Qt::QueuedConnection);
..and lo and behold, now I see all services with all the characteristics.

USB read failure with xboxdrv 0.8.7

I am using xboxdrv in version 0.8.7 and a XBox 360 Wireless controller on raspberrypi 3 (4.9.13-v7+).
It works sometimes a day, sometimes some minutes. But I get always:
[ERROR] USBController::on_read_data(): USB read failure: 32:
LIBUSB_TRANSFER_ERROR
The common suggestions in the forum didn't help me and I think there are still some people struggling with that.
I tried to contact the author but didn't get answer so far.
The software runs under GPL-3.0, so I had a look in the source code.
Project on GitHub:
https://github.com/xboxdrv/xboxdrv
I identified where it crashs (src/usb_controller.cpp, line 277 and below). That's the last else-section in the code below. Starting with log_error("USB read failure:
void
USBController::on_read_data(libusb_transfer* transfer)
{
assert(transfer);
if (transfer->status == LIBUSB_TRANSFER_COMPLETED)
{
// process data
XboxGenericMsg msg;
if (parse(transfer->buffer, transfer->actual_length, &msg))
{
submit_msg(msg);
}
int ret;
ret = libusb_submit_transfer(transfer);
if (ret != LIBUSB_SUCCESS) // could also check for LIBUSB_ERROR_NO_DEVICE
{
log_error("failed to resubmit USB transfer: " << usb_strerror(ret));
m_transfers.erase(transfer);
libusb_free_transfer(transfer);
send_disconnect();
}
}
else if (transfer->status == LIBUSB_TRANSFER_CANCELLED)
{
m_transfers.erase(transfer);
libusb_free_transfer(transfer);
}
else if (transfer->status == LIBUSB_TRANSFER_NO_DEVICE)
{
m_transfers.erase(transfer);
libusb_free_transfer(transfer);
send_disconnect();
}
else
{
log_error("USB read failure: " << transfer->length << ": " << usb_transfer_strerror(transfer->status));
m_transfers.erase(transfer);
libusb_free_transfer(transfer);
}
}
My C++ knowledge is bad, further I haven't experience with libusb. Could you make a suggestion how I could fix that for me.
The problem is, as soon as the mentioned error occurs, xboxdrv is stopping and it will handle no more input from the XBOX 360 Wireless Controller.
It should just kind of ignore that wrong package and wait for a new one. But just don't stop working.
Thank you

I2C error when using the Windows Monitor Configuration Functions

I'm attempting to get/set the brightness level of the monitor through the Windows API. I've tried both the Low-Level Monitor Configuration Functions and the High-Level Monitor Configuration Functions, but they both seem to be breaking in the same place. In both cases I have no problem getting the HMONITOR handle and getting the physical monitor handle from the HMONITOR, but once I try to query the DDC/CI capabilities, I get an error saying "An error occurred while transmitting data to the device on the I2C bus."
The particular functions that cause this error are GetMonitorCapabilities for the high-level functions and GetCapabilitiesStringLength for the low-level functions. They both cause the same error.
This leads me to believe that maybe my monitor doesn't support DDC/CI, but I know my laptop's monitor brightness can be changed through the control panel, so it must be controlled through software somehow. Also I can successfully use the WMI classes in a PowerShell script to get/set the brightness as described on this page. Most things I've read suggest that most modern laptop screens do support DDC/CI.
Is there any way to find out what is causing this error or to get more information about it? I'm currently working in C++ in Visual Studio 2013 on Windows 7. I could probably use WMI in my C++ program if I can't get this current method working, but I thought I would ask here first.
Here's the code I currently have:
#include "stdafx.h"
#include <windows.h>
#include <highlevelmonitorconfigurationapi.h>
#include <lowlevelmonitorconfigurationapi.h>
#include <physicalmonitorenumerationapi.h>
#include <iostream>
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
DWORD minBrightness, curBrightness, maxBrightness;
HWND curWin = GetConsoleWindow();
if (curWin == NULL) {
std::cout << "Problem getting a handle to the window." << std::endl;
return 1;
}
// Call MonitorFromWindow to get the HMONITOR handle
HMONITOR curMon = MonitorFromWindow(curWin, MONITOR_DEFAULTTONULL);
if (curMon == NULL) {
std::cout << "Problem getting the display monitor" << std::endl;
return 1;
}
// Call GetNumberOfPhysicalMonitorsFromHMONITOR to get the needed array size
DWORD monitorCount;
if (!GetNumberOfPhysicalMonitorsFromHMONITOR(curMon, &monitorCount)) {
std::cout << "Problem getting the number of physical monitors" << std::endl;
return 1;
}
// Call GetPhysicalMonitorsFromHMONITOR to get a handle to the physical monitor
LPPHYSICAL_MONITOR physicalMonitors = (LPPHYSICAL_MONITOR)malloc(monitorCount*sizeof(PHYSICAL_MONITOR));
if (physicalMonitors == NULL) {
std::cout << "Unable to malloc the physical monitor array." << std::endl;
return 1;
}
if (!GetPhysicalMonitorsFromHMONITOR(curMon, monitorCount, physicalMonitors)) {
std::cout << "Problem getting the physical monitors." << std::endl;
return 1;
}
std::cout << "Num Monitors: " << monitorCount << std::endl; // This prints '1' as expected.
wprintf(L"%s\n", physicalMonitors[0].szPhysicalMonitorDescription); // This prints "Generic PnP Monitor" as expected
// Call GetMonitorCapabilities to find out which functions it supports
DWORD monCaps;
DWORD monColorTemps;
// The following function call fails with the error "An error occurred while transmitting data to the device on the I2C bus."
if (!GetMonitorCapabilities(physicalMonitors[0].hPhysicalMonitor, &monCaps, &monColorTemps)) {
std::cout << "Problem getting the monitor's capabilities." << std::endl;
DWORD errNum = GetLastError();
DWORD flags = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
LPVOID buffer;
FormatMessage(flags, NULL, errNum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&buffer, 0, NULL);
wprintf(L"%s\n", buffer);
return 1;
}
// Same error when I use GetCapabilitiesStringLength(...) here.
// More code that is currently never reached...
return 0;
}
Edit: Also I should note that physicalMonitors[0].hPhysicalMonitor is 0, even though the monitor count and text description are valid and the GetPhysicalMonitorsFromHMONITOR function returns successfully. Any thoughts on why this might be?
This is a "wonky hardware" problem, the I2C bus it talks about is the logical interconnect between the video adapter and the display monitor. Primarily useful for plug & play. Underlying error code is 0xC01E0582, STATUS_GRAPHICS_I2C_ERROR_TRANSMITTING_DATA. It is generated by a the DxgkDdiI2CTransmitDataToDisplay() helper function in the video miniport driver. It is the vendor's video driver job to configure it, providing the functions that tickle the bus and to implement the IOCTL underlying GetMonitorCapabilities().
Clearly you are device driver land here, there isn't anything you can do about this failure in your C++ program. You can randomly spin the wheel of fortune by looking for a driver update from the video adapter manufacturer. But non-zero odds that the monitor is at fault here. Try another one first.
I know its bad time to reply but i thought you should know.
The problem you are facing is because of the DDC/CI disabled on your monitor so you should go to the monitor settings and check if DDC/CI is disabled and if it is, then you have to enable it and run your code again. It would work. If you were not able to find DDC/CI option ( some of the monitor have a separate button for enabling/disabling the DDC/CI like the Benq's T71W monitor has a separate down arrow button to enable/disable DDC/CI ) then you should refer to your monitor's manual or contact the manufacturer.
Hope that helps. and sorry for late reply.
Best of luck. :)
As I read the original question, the poster wanted to control a laptop display using DDC/CI. Laptop displays do not support DDC/CI. They provide a stripped down I2C bus sufficient to read the EDID at slave address x50, but that's it.

QT USB hardware ID detection Mac OS 10.8.x and Mac Book (Pro)

Background:
We have an application which is written using the QT framework. One key requirement is that we can correctly detect the hardware serial number of the USB flash drive used (not an external hard drive). This function has been working correctly for 4 years and worked on Windows XP, Windows Vista, Windows 2007 and on all Mac versions.
To our surprise we got clients complaining that the USB hardware ID was not being read and shown completely. After testing extensively it turns out that ONLY the combination of Mac OS mountain Lion + Mac Book (Pro) does NOT detect the hardware ID.
Mountain Lion on an iMac, on a Mini Mac, works fine. Leopard, Snow Leopard and Lion work fine on all Macs, including the Mac Book Pro.
We have been looking for a fix for nearly 1 one month but without results. Can anyone provide a small piece of code that works or give information what causes this issue (and really only on this combination) and how to fix it.
Note
Several resources can be found on the internet of other USB hardware that has issues with mountain lion but nowhere an answer was given to the solution to exactly the problem as described above.
Additional info:
We use the following code at the moment which works correctly on all Macs except those that have a USB3.0 port.
matchingDict = IOServiceMatching(kIOUSBDeviceClassName);
if (matchingDict == NULL)
{
return uret; // fail
}
/* Now we have a dictionary, get an iterator.*/
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS)
{
return uret;
}
/* iterate */
/* scan all USB device in Mac machine*/
while ((device = IOIteratorNext(iter)))
{
int vendorId;
int productId;
getVidAndPid(device, &vendorId, &productId);
/*Get USB serial number by CFTypeRef*/
CFTypeRef serialNoRef = IORegistryEntryCreateCFProperty(device, CFSTR("USB Serial Number"), 0, 0);
/*Get USB bsd name by CFStringRef */
CFStringRef bsdNameRef = (CFStringRef)IORegistryEntrySearchCFProperty(device, kIOServicePlane,CFSTR(kIOBSDNameKey),kCFAllocatorDefault, kIORegistryIterateRecursively );
char* bsdName = cfStringRefToCString(bsdNameRef) ;
qDebug() << "bsd Name " << bsdName ;
if (bsdName != NULL)
{
char* serialNo = cfTypeToCString(serialNoRef);
qDebug() << "serialNo " << serialNo ;
/*Get USB manufacturerRef by CFTypeRef */
CFTypeRef manufacturerRef =IORegistryEntrySearchCFProperty(device, kIOServicePlane, CFSTR(kUSBVendorString), kCFAllocatorDefault, 0);
char* manufacrurer = cfTypeToCString(manufacturerRef);
qDebug() << "manufacrurer " << manufacrurer ;
}
IOObjectRelease(device);
}
/* Done, release the iterator */
IOObjectRelease(iter);

How do I read the pressure value from a graphics tablet stylus in Linux?

I am trying to add pressure sensitivity support to Synergy on Linux. I
believe the first step should be to detect the pressure value on the
server side. The stylus movement comes in as a MotionNotify event when
XNextEvent is called. However, this line does not output a pressure
value when the stylus is used:
case MotionNotify:
XDeviceMotionEvent* motionEvent = reinterpret_cast<XDeviceMotionEvent*>(xevent);
LOG((CLOG_INFO "tablet event: pressure=%d", motionEvent->axis_data[2]));
To solve this, I guessed that I might not be "subscribed" to such
info, so following some examples I found on the web, I have attempted
to open the Wacom device:
void
CXWindowsScreen::openWacom()
{
// init tablet (e.g. wacom)
int deviceCount;
XDeviceInfo* deviceInfo = XListInputDevices(m_display, &deviceCount);
for (int i = 0; i < deviceCount; ++i) {
if (CString(deviceInfo[i].name).find("stylus") != CString::npos) {
LOG((CLOG_INFO "tablet device: name='%s', id=%d",
deviceInfo[i].name, deviceInfo[i].id));
XDevice* tabletStylusDevice = XOpenDevice(m_display, deviceInfo[i].id);
if (tabletStylusDevice == NULL) {
LOG((CLOG_ERR "failed to open tablet device"));
return;
}
XEventClass eventClass;
DeviceMotionNotify(tabletStylusDevice, m_tabletMotionEvent, eventClass);
XSelectExtensionEvent(m_display, m_window, &eventClass, 1);
LOG((CLOG_INFO "tablet motion event=%d class=%d",
m_tabletMotionEvent, eventClass));
}
}
XFreeDeviceList(deviceInfo);
}
This does indeed detect a Wacom device...
2012-01-30T11:15:59 INFO: tablet device: name='Wacom Intuos4 6x9 stylus', id=8
/home/nick/Projects/synergy/1.4/src/lib/platform/CXWindowsScreen.cpp,1144
2012-01-30T11:15:59 INFO: tablet motion event=105 class=2153
/home/nick/Projects/synergy/1.4/src/lib/platform/CXWindowsScreen.cpp,1157
But I have so far never received the stylus event 105
(m_tabletMotionEvent) from XNextEvent...
if (xevent->type == m_tabletMotionEvent) {
XDeviceMotionEvent* motionEvent = reinterpret_cast<XDeviceMotionEvent*>(xevent);
LOG((CLOG_INFO "tablet event: pressure=%d", motionEvent->axis_data[2]));
return;
}
In other words, the above if never evaluates to true.
I hope someone can help me with this, I've been trying to solve it for weeks.
The next challenge will be to fake the pressure level on the Synergy
client so that programs like GIMP will receive it (and I'm not even sure where to
start with that).