用Dbus与android的bluz通信

DBus研究笔记(一) 一.建立连接 要使用DBus进行通信必须首先与系统建立连接, 并申请一个"域名"使得其他应用可以找到你。常用DBusConnection* dbus_bus_get(DBusBusType, DBusError*)系列函数来与bus daemon建立连接。DBusBusType为需要连接的总线类型有系统总线,会话总线,和DBUS_BUS_STARTER。系统总线顾名思义在整个系统级别都有效,而会 阅读详情

android的bluetooth架构是建立在bluez之上的,bluz通过dbus暴露了底层蓝牙设备的服务。先用android内置的命令bttest enable,开启bluedroid进程。这样bluz就可以接收dbus请求了。先来看段简单dbus代码:

 


char*
send_method_call_with_string_reply(char* objectPath,
    char* type, char* name)
{
  DBusMessage* msg;
  DBusMessage* reply;
  DBusConnection* conn;
  DBusError err;
  const char *reply_path;
  char *path;

  // initialise the error value
  dbus_error_init(&err);

  printf("get dbus connection:\n");
  conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
  if (dbus_error_is_set(&err))
    {
      fprintf(stderr, "Connection Error (%s)\n", err.message);
      dbus_error_free(&err);
    }
  if (NULL == conn)
    {
      printf("conn is null\n");
      goto done;
    }

  msg = dbus_message_new_method_call(“org.bluez”, // target for the method call
      objectPath, // object to call on
      type, // interface to call on
      name); // method name
  if (NULL == msg)
    {
      fprintf(stderr, "Message Null\n");
      goto done;
    }

  reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);

  if (!reply)
    {
      fprintf(stderr, "Can't get reply\n");
      if (dbus_error_is_set(&err))
        {
          fprintf(stderr, "%s\n", err.message);
          dbus_error_free(&err);
        }
      goto done;
    }

  if (!dbus_message_get_args(reply, &err, DBUS_TYPE_OBJECT_PATH, &reply_path,
      DBUS_TYPE_INVALID))
    {
      fprintf(stderr, "Can't get reply arguments\n");
      if (dbus_error_is_set(&err))
        {
          fprintf(stderr, "%s\n", err.message);
          dbus_error_free(&err);
        }
      goto done;
    }
  path = strdup(reply_path);

  dbus_connection_flush(conn);

  printf("method call Sent\n");

done:
  // free the message
  if(msg)
    dbus_message_unref(msg);
 if(reply)
   dbus_message_unref(reply);

  return path;
}测试程序如下

 

 


#include <dbus/dbus.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char **argv) {
  printf("----------------------test dbus start----------------------\n");

  char* ss = send_method_call_with_string_reply("/","org.bluez.Manager","DefaultAdapter");
  printf("reteun value:%s\n",ss);
  free(ss);
  printf("-----------------------test dbus end-----------------------\n");
  return 1;
}在android.mk中添加LOCAL_SHARED_LIBRARIES := libbluedroid libdbus,再加上dbus头文件就能编过。

 

Android系统启动流程4---init进程的工作流程 概况: 启动init进程 运行init.rc 启动zygote服务 Zygote fork的第一个进程——SystemServer SystemServer启动系统服务 1. linux启动第一个应用程序init kernel\init\main.c static int __ref kernel_init(void *unused) { int ret; kernel_init_freeable(); /* need to finish all async __init code before 阅读详情

相关推荐

Linux驱动学习--dbus通讯分析(结合源码分析)

目录 一、引言 二、dbus介绍 ------> 1、DBUS应用场景 三、dbus的实现 ------> 1、实现原理 ------> 2、连接到总线 ------------>2.1、总线类型 ------> 3、进程注册到总线上的流程 ------> 4、信号发送 ------> 5、信号接收 ------> 6、发送函数调用的消息类型 ------> 7、接收函数调用的消息类型 一、引言 今天来整理下dbus,linux中经常用到的多进程通讯机制

文艺小少年的博客 1691

【蓝牙】BLE 数据收发实战指南(手机 App ↔ 嵌入式 Linux/BlueZ)

BLE 数据收发实践指南 本文详细介绍了在手机 App(Android/iOS)与嵌入式 Linux(BlueZ)之间实现 BLE 数据交互的完整流程。主要内容包括: 基础概念:解析 Central 与 Peripheral 角色差异,说明 GATT/ATT 数据通道机制,重点介绍 CCCD 配置方法。 BlueZ 接口:详细说明 D-Bus 信号格式,强调特征值的单层 variant 封装规范,避免常见的双层封装问题。 典型场景: 手机作为中心设备连接 Linux 外设 手机向 Linux 写入命令并接收

love131452098的博客 1930

android dbus应用

android dbus应用

android移植dbus

Android dbus开源代码移植

wangjicong_215的博客 775

bluez-dbus:使用DBus和bluez的linux操作系统的蓝牙库(http

蓝巴士 使用和linux操作系统的蓝牙库。 该项目的灵感来自 ,但是它不需要任何包装库,因为它基于使用jnr-unixsocket的dbus-java的较新版本。 该库已经过Ubuntu 16.04.4(AMD64)和bluez库5.54的测试。 从该库的0.1.0版本开始,需要Java 8(以前的版本使用Java 7)。 如果要使用通过任何bluez方法传递的filedescriptor,则必须将库添加到您的项目中: <dependency> <groupId>com.rm5248</groupId> <artifactId>dbus-java-nativefd</artifactId> <version>1.0</version> </dependency> 要为Ubuntu构建更新的bluez库(16.04的版本早于5.50): 从下载新的bl

Linux下扫描蓝牙获取RSSI

Linux下使用C语言,扫描附近蓝牙并获取蓝牙RSSI。。。。。。。。。。。。。。。。。。。。

Android 自己开发的消息事件小项目DBus

优快云地址:http://blog.youkuaiyun.com/fesdgasdgasdg/article/details/79121783 GitHub地址:https://github.com/mengzhinan/DBus DBus一个简易、高效的消息框架。没看过EventBus的源码,但是个人感觉此项目够简洁高效、易懂易用! DBus项目突出的特点: 1、注册消息事件的类可以是

阿杜 1万+

从XSA到Linux应用:Petalinux与Vitis的嵌入式开发全流程解析

本文详细解析了从XSA文件到Linux应用的嵌入式开发全流程,重点介绍了Petalinux与Vitis工具链的使用技巧和实战经验。通过XSA硬件描述、Petalinux工程搭建、系统镜像优化及Vitis开发配置等关键步骤,帮助开发者高效完成ZYNQ平台开发,解决常见问题并提升开发效率。

weixin_29195217的博客 192

dbus调试方法

近期研究了android bluetooth,发现bluez消息都是通过dbus进行传输,但是在java层和bluez通信的过程中,有些会被block住,这样就需要dbus进行调试,下面讲述dbus进行调试的方法。     dbus提供2个tool,一个是dbus-send, 一个是dbus-monitor。dbus-send可以像调用API那样进行消息传递,而dbus-moni

Luohsh1的专栏 2186

【小白教程】本地部署VLM-R1模型(使用Docker)

通过Docker本地部署VLM-R1大模型,详细教程。

m0_69855053的博客 2938

从单机到多机:用llama.cpp的RPC模式榨干你闲置的GPU(附性能调优参数)

本文详细介绍了如何利用llama.cpp的RPC模式实现多机部署,将闲置GPU资源整合为高效推理集群。通过实战案例展示了性能调优参数设置、端口分配策略以及常见问题排查技巧,帮助中小团队最大化利用异构GPU设备,提升文本摘要等任务的推理效率。

weixin_27240351的博客 589

android bluez 编译,Android Framework architecture -- bluez(1)

转载请附加本文链接。android一词的本义指“机器人”,和robot不同的是它是有AI的,那么同时google也接android这个单词,于2007年11月5日宣布推出基于Linux平台的开源手机操作系统,该平台由操作系统、中间件、用户界面和应用软件组成,号称是首个为移动终端打造的真正开放和完整的移动软件。对于一个软件+,硬件-的我来说,android无疑是黑暗了很久的一束阳光。有兴趣的博友们可...

weixin_30832021的博客 312

AI驱动的CNC闭环加工系统:边缘实时控制与IIoT反馈实践

闭环控制是工业自动化的核心概念,指通过实时反馈调节系统输出以逼近目标值;其技术原理在于构建短于被控对象时间常数的确定性反馈链路,从而保障动态响应精度与稳定性。在智能制造落地中,AI正从离线分析工具演进为嵌入式实时决策单元,其核心价值在于将工艺知识模型化、控制指令轻量化、执行路径边缘化。典型应用场景包括CNC加工过程中的振动自适应调参、刀具磨损在线补偿及多机协同优化。本实践聚焦FANUC 0i-MF平台,基于Modbus TCP硬实时通信与轻量LSTM+CNN融合模型,实现217毫秒级AI推理与PMC寄存器直

weixin_29704001的博客 323

BT传统蓝牙和BLE低功耗蓝牙的区别

【代码】传统蓝牙和Bluz低功耗蓝牙的区别。

Android系统攻城狮 6084

OpenHarmony-AI调研

基于OpenHarmony-5.0.0版本以及laval社区等网络资料调研当前OH上的AI发展情况。

qqq1112345的博客 1369

某教育平台线上用户流失分析

本项目基于某教育平台的用户登录信息、用户个人信息以及用户课程学习记录三信息表,挖掘了平台流量以及用户流失等信息。使用python对数据进行预处理,使用tableau进行数据可视化分析。该教育平台正值窗口期,平台流量没有良好的留存水平,但有良好的发展趋势,需要深入分析用户留存率低,做好招新促活营销。该教育平台的基本盘在广东、湖北、河南、贵州等省份,线上教育的潜在用户可能更多分布在线下教育资源不充足、受疫情影响更为严重的地区。

fhy12的博客 1300

Android BlueDroid(一):BlueDroid概述

转自:http://blog.youkuaiyun.com/xubin341719/article/details/40378205 一、名词解释:(有用信息增加中……) BTI F: Bluetooth Interface BTU : Bluetooth Upper Layer BTM: Bluetooth Manager  BTE  :Bluetooth embedded system

Android系统攻城狮 1414

从零到英雄:如何用FPGA和AD9288打造你的第一台便携式示波器

本文详细介绍了如何利用FPGA和AD9288 ADC芯片从零开始打造一台高性能便携式示波器。通过硬件架构设计、高速数据采集系统实现及信号处理与显示系统的开发,读者可以掌握400Msps采样率的实现方法,并了解关键器件选型与系统优化技巧。

jjj34的博客 277

DBUS和Binder对比

http://blog.sina.com.cn/s/blog_5377f4930100pe01.html 最近看了android上的两种进程间通信的方式,做了个对比: DBUS实现了一种进程间以及进程与内核间的通信的模型。Bus Daemon从源进城接收消息并且转发到目标进城;目标进城可以通过匹配机制只监听感兴趣的消息。简单调研后,目前认为DBUS是一种有中心的结构,即所有的消息都要集

浩海天空 5519

【3天快速入门WPF】8-数据绑定基础

以下是一个简单的 WPF 数据绑定示例,使用两个TextBox控件分别表示Name和Age来进行进行数据绑定试验。运行程序后,你会看到初始界面中TextBox 中显示初始名字 “张三”,TextBox 中显示初始年龄 “25”。在 XAML 中创建一个简单的界面,包含一个 TextBox 用于输入名字,一个 TextBox 用于显示年龄。当你在 TextBox 中修改名字时,Person 对象的 Name 属性会被自动更新,反之亦然。它的主要作用是为控件及其子控件提供一个默认的数据源,用于数据绑定。

Zy100Papa的博客 969

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

从D-Bus(DBus)的使用看Android设计策略中安全的优先级

http://hi.baidu.com/xalanz/blog/item/689cc2b1ebba4d5f09230293.html 从D-Bus(DBus)的使用看Android设计策略中安全的优先级 2009-12-15 08:59 Android使用了一种特殊的进程间通讯系统D-bus .而我们知道进程间通讯机制已经存在好多种,Corba,DCOP,COM,SOAP, ...

271

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Dbus简介

Linux下基本的通信方式有如下8种: 1. 管道pipe: 进程需要共同祖先 2. 命名管道named pipe, 也就是fifo:  文件系统中有对应文件名 3. mapped memory:把一个共享的文件映射到自己的进程地址空间 4. 消息队列:信息量大,格式灵活 5. 共享内存:速度最快 6. 信号量:同步手段 7. socket:最灵活 8. signal:比较复杂,携

tinyle的专栏 2119

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Android培训班(38)

<br /> <!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } --> <br />在init.rc文件里,可以看到加载下面的服务:<br />service dbus /system/bin/dbus-daemon --system --nofork <br />socket dbus stream 660 bluetooth bluetooth <br />user bluetooth <br

大坡3D软件开发 3439
上一篇: Android怎样添加AT命令
下一篇: dbus 例程
huber
博客等级 码龄15年 79粉丝 24原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值