我正在尝试编写一些代码来使用DBUS与wpa_supplicant进行通信.当我在嵌入式系统(ARM)中工作时,我想避免使用Python或GLib.我想知道我是不是很愚蠢,因为我真的觉得没有关于D-Bus的清晰文档.即使使用官方文档,我发现文档的级别太高,或者显示的示例都使用了Glib!我看过的文档:http://www.freedesktop.org/wiki/Software/dbus
我发现了一篇关于在C中使用D-Bus的好文章:http://www.matthew.ath.cx/articles/dbus
但是,这篇文章已经很老了,还不够完整!我也找到了c ++ - dbus API,但在这里,我找不到任何文档!我一直在深入研究wpa_supplicant和NetworkManager源代码,但这真是一场噩梦!我一直在研究"低级D-Bus API",但这并没有告诉我如何从D-Bus消息中提取字符串参数!http://dbus.freedesktop.org/doc/api/html/index.html
下面是我编写的一些代码来测试,但我真的很难提取字符串值.很抱歉有很长的源代码,但如果有人想尝试...我的D-Bus配置似乎很好,因为它"已经"从wpa_supplicant捕获"StateChanged"信号,但无法打印状态:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <dbus/dbus.h>
//#include "wpa_supp_dbus.h"
/* Content of wpa_supp_dbus.h */
#define WPAS_DBUS_SERVICE "fi.epitest.hostap.WPASupplicant"
#define WPAS_DBUS_PATH "/fi/epitest/hostap/WPASupplicant"
#define WPAS_DBUS_INTERFACE "fi.epitest.hostap.WPASupplicant"
#define WPAS_DBUS_PATH_INTERFACES WPAS_DBUS_PATH "/Interfaces"
#define WPAS_DBUS_IFACE_INTERFACE WPAS_DBUS_INTERFACE ".Interface"
#define WPAS_DBUS_NETWORKS_PART "Networks"
#define WPAS_DBUS_IFACE_NETWORK WPAS_DBUS_INTERFACE ".Network"
#define WPAS_DBUS_BSSIDS_PART "BSSIDs"
#define WPAS_DBUS_IFACE_BSSID WPAS_DBUS_INTERFACE ".BSSID"
int running = 1;
void stopLoop(int sig)
{
running = 0;
}
void sendScan() …Run Code Online (Sandbox Code Playgroud) 我很担心,因为我写了一个小应用程序,如果我相信valgrind(我实际上做了什么),似乎存在内存泄漏:
==9321== 251 bytes in 7 blocks are definitely lost in loss record 1 of 1
==9321== at 0x402569A: operator new(unsigned int) (vg_replace_malloc.c:255)
==9321== by 0x40D3D05: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.13)
==9321== by 0x40D4977: std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned int) (in /usr/lib/libstdc++.so.6.0.13)
==9321== by 0x40D57AC: std::string::reserve(unsigned int) (in /usr/lib/libstdc++.so.6.0.13)
==9321== by 0x40D5EE6: std::string::operator+=(char) (in /usr/lib/libstdc++.so.6.0.13)
==9321== by 0x804E113: xl2::TextParser::getNextLfLine() (TextParser.cpp:162)
==9321== by 0x804BFD5: xl2::UsbTree::parseStringInfo(xl2::TextParser&, std::string&, std::string&) (UsbTree.cpp:362)
==9321== by 0x804B881: xl2::UsbTree::parseDevicesFile(std::string) (UsbTree.cpp:204)
==9321== by 0x804B34E: xl2::UsbTree::updateTree() (UsbTree.cpp:70)
==9321== by …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已经被问到了,但我发现的解决方案没有给我带来帮助!我有一个程序,其输出如下:
COUNT|293|1|lps
Run Code Online (Sandbox Code Playgroud)
我对第二个字段感兴趣但是这些尝试中没有一个有效:
./spawn 1 | cut -d '|' -f2
./spawn 1 | cut -d \| -f2
./spawn 1 | awk -F "|" '{print $2}'
./spawn 1 | awk 'BEGIN{FS="|"} {print $2}'
./spawn 1 | sed 's/|/;/g'
./spawn 1 | sed 's/\|/;/g'
Run Code Online (Sandbox Code Playgroud)
但输出总是一样的:
COUNT|293|1|lps
Run Code Online (Sandbox Code Playgroud)
bash中某处有错误吗?我会感到惊讶,我的Linux主机和使用busybox灰的嵌入式设备上的结果是一样的!任何指针都非常感谢!
编辑 我的错,输出是stderr ... ._.
./spawn 1 2>&1 | cut -d '|' -f2
4615
Run Code Online (Sandbox Code Playgroud)
抱歉让人心烦!
我下载了一个软件(info-beamer),我想使用 GPU 加速来解码 H.264 视频。我知道我的平台能够使用 GPU 解码 H.264 视频。我使用以下命令对 gstreamer 进行了一些测试,视频播放流畅,没有太多 CPU 使用率:
gst-launch-1.0 filesrc location=./Sintel.mp4 ! qtdemux ! vaapidecode ! vaapisink
Run Code Online (Sandbox Code Playgroud)
但是当我使用 info-beamer 播放相同的视频时,100% 的 CPU 都被使用了。我认为 libavcodec 会自动使用 VAAPI(如果可用)...我应该使用另一个库吗?我究竟做错了什么?
我的平台运行的是配备 intel HD 的 Atom E3826,并安装了 Ubuntu 14.04。
编辑:
我想我安装了所有必需的库:
nap@nap:~$ dpkg -l | grep libva
ii libva-dev:amd64 1.3.0-2 amd64 Video Acceleration (VA) API for Linux -- development files
ii libva-drm1:amd64 1.3.0-2 amd64 Video Acceleration (VA) API for Linux -- DRM runtime
ii libva-egl1:amd64 1.3.0-2 amd64 Video …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pppd和AT命令建立PPP连接.这通常适用于我当地提供商的SIM卡.然而,我收到了一位住在德国的朋友的卡片,我想从瑞士试一试,但我有一种非常奇怪的行为.
首先我无法激活错误消息(AT + CMEE),我总是收到错误消息"ERROR",尽管我之前已经激活了完整的详细信息(AT + CMEE = 2).此命令适用于我的本地提供商SIM卡...
然后,如果我检查网络状态:
AT+CGREG?
+CGREG: 1,3
Run Code Online (Sandbox Code Playgroud)
相信"3",这意味着"注册被拒绝".
当我尝试连接或分离时,我总是有一个错误而没有更多的解释(尽管AT + CMEE = 2):
AT+CGATT=0
ERROR
AT+CGATT=1
ERROR
AT+CGATT?
+CGATT: 0
OK
Run Code Online (Sandbox Code Playgroud)
我可以用AT命令发送短信!将SIM卡放入手机,我无法拨打任何电话!
那么是否可以发送短信而无需注册到网络?是否可能在SIM卡上停用错误消息报告?我想知道这是配置问题,SIM卡问题还是提供商问题......
编辑
如果这可以帮助某人.当我使用我工作的SIM卡从网络中分离时,我尝试发送短信,它有效!相信这个网站我想我的朋友没有支付账单或我的本地网络提供商拒绝我使用其网络...
我在运行ARM的嵌入式Linux下无法创建计时器。我正在使用自制的C ++库来管理计时器。我自己没有编写代码,尽管可以访问源代码,但我对实现并不十分了解。它工作了一段时间,然后出现错误“ EAGAIN”。
我使用strace注意到,当它不起作用时,计时器ID会偏高!
timer_create(CLOCK_MONOTONIC, {0, SIGRT_3, SIGEV_SIGNAL, {...}}, 0xbed50af4) = -1 EAGAIN (Resource temporarily unavailable)
Run Code Online (Sandbox Code Playgroud)
工作时,请查看计时器ID较低:
timer_create(CLOCK_MONOTONIC, {0x3, SIGRT_3, SIGEV_SIGNAL, {...}}, {0x3d}) = 0
Run Code Online (Sandbox Code Playgroud)
我以为计时器的数量是无限的!其实并不是?一旦完成,是否应该销毁计时器?我还使用了“ timer_stats”内核实用程序,但这对我没有多大帮助。在内核或其他任何工具中,是否还有其他用于计时器的调试实用程序?
谢谢你的帮助!
我的嵌入式设备遇到了一些性能问题:
# uptime
14:59:39 up 5:37, load average: 1.60, 1.50, 1.53
Run Code Online (Sandbox Code Playgroud)
单声道系统非常糟糕...... :-p!但是,如果我查看顶级实用程序,我的空闲时间总是在80%左右!
Mem: 49020K used, 75960K free, 0K shrd, 0K buff, 21476K cached
CPU: 12.5% usr 4.8% sys 0.0% nic 81.7% idle 0.0% io 0.9% irq 0.0% sirq
Load average: 1.30 1.42 1.51 1/80 18696
Run Code Online (Sandbox Code Playgroud)
阅读一些文章后,我最好相信正常运行命令.但为什么这个差异?我的CPU真的无所事事吗?
我有一个"对象",其中不同的属性存储为键/值.键是一个字符串,值可以是任何基本类型.我的第一个想法是使用模板类:
template <class T>
class Attribute {
public:
Attribute<T>(const std::string& key, T value) :
m_key(key),
m_value(value)
{
}
~Attribute(){}
T getValue() const
{
return m_value;
}
std::string getKey() const
{
return m_key;
}
private:
std::string m_key;
T m_value;
};
Run Code Online (Sandbox Code Playgroud)
但现在问题是在我的对象类中,我必须为每个可能的属性类型声明字段和重载函数:
class MyObject {
public:
MyObject(int value) :
m_value(value)
{
}
~MyObject()
{
}
int getValue() const
{
return m_value;
}
void addAttribute(Attribute<int> attribute)
{
m_intAttributes.push_back(attribute);
}
void addAttribute(Attribute<double> attribute)
{
m_doubleAttributes.push_back(attribute);
}
const std::list<Attribute<int> >& getIntAttributes() const
{
return m_intAttributes; …Run Code Online (Sandbox Code Playgroud) 我编写了一个接受不同远程客户端的应用程序,并基于select()将作业分发给不同的处理程序.我注意到在一个运行ARM926EJ-S和内核2.6.33-rc4的平台上,应用程序使用了大量的CPU!通过使用strace -c运行我的应用程序30秒,我可以看到以下内容:
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
98.47 3.680000 204444 18 select
...
Run Code Online (Sandbox Code Playgroud)
但是,如果我从远程客户端连续向应用程序发送数据,则选择使用更少的CPU!
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
44.69 0.340278 175 1945 gettimeofday
40.71 0.310000 25833 12 select
3.94 0.030000 30000 1 fsync
...
Run Code Online (Sandbox Code Playgroud)
我想知道是否select()实施繁忙的等待.但是,在较旧的平台上,运行MIPS处理器和2.6.30.10 Linux内核时,这个问题没有出现,尽管我应该交叉编译strace来确认......!由于数据"很少"发送,我大多数情况下最糟糕!
我想知道问题可能来自哪里!C图书馆?Linux内核?另一方面,我不确定写多线程应用程序是否会因为pthread关键部分而导致更好的性能......?
我在互联网上阅读了两篇有趣的文章:
不幸的是它们已经很老了(从'98/'99)我想知道是否有其他人遇到过那种问题,或者你是否有其他建议来提高性能或指出真正的问题?
编辑:
我注意到更多的客户端连接更多我的应用程序使用CPU,这尽管客户端不发送任何数据!由于大部分时间花在选择上,我虽然选择本身消耗更多的CPU!我可以在ARM下使用哪些其他免费工具来分析我的应用程序并指出问题?Valgrind在ARM9上还没有工作......
我正在写一个应用程序,我不得不做一些指针算术.但是这个应用程序将在不同的架构上运行!我不确定这是否会有问题,但在阅读本文之后,我认为我必须改变它.
这是我原来的代码,我不太喜欢:
class Frame{
/* ... */
protected:
const u_char* const m_pLayerHeader; // Where header of this layer starts
int m_iHeaderLength; // Length of the header of this layer
int m_iFrameLength; // Header + payloads length
};
/**
* Get the pointer to the payload of the current layer
* @return A pointer to the payload of the current layer
*/
const u_char* Frame::getPayload() const
{
// FIXME : Pointer arithmetic, portability!
return m_pLayerHeader + m_iHeaderLength;
}
Run Code Online (Sandbox Code Playgroud)
很糟糕不是吗!向指针添加 …
我拿起了这段代码,我将其复制到我的程序中.这似乎是我通过char**迭代的一种新方式:
char** vArray; // The array containing values
// Go throught properties
if(szKey == "KeyMgmt")
{
vArray = (char**)g_value_get_boxed((GValue*)value);
for( ; vArray && *vArray ; vArray++) // Why does this work ?!
pWpaKey->addKeyMgmt(std::string(*vArray));
}
else if(szKey == "Pairwise")
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
它看起来像一个魅力,但我不明白为什么!假设vArray包含一个地址吗?并且*vArray"字符串"值.那么,为什么当我"和"一个有价值的地址时,这给了我一个平等的呢?
c++ ×5
embedded ×3
linux ×3
c ×2
pointers ×2
arm ×1
arrays ×1
ash ×1
at-command ×1
awk ×1
bash ×1
dbus ×1
glib ×1
gprs ×1
gpu ×1
gstreamer ×1
h.264 ×1
libavcodec ×1
load ×1
memory-leaks ×1
performance ×1
pipe ×1
ppp ×1
sed ×1
sim-card ×1
stl ×1
strace ×1
string ×1
templates ×1
timer ×1
uptime ×1
valgrind ×1