hcid 分析

hcid分析实际上就是蓝牙启动流程的分析。
 
先看用法:hcid [-n] [-d] [-m mtu] [-f config file]

进入main()函数:
     1.hcid的一些默认设置,例如安全方式,名字等
init_defaults();
static inline void   init_device_defaults(struct device_opts *device_opts)
{
memset(device_opts, 0, sizeof(*device_opts));
device_opts->scan = SCAN_PAGE;
device_opts->mode = MODE_CONNECTABLE;
device_opts->name = g_strdup("BlueZ");
device_opts->discovto = HCID_DEFAULT_DISCOVERABLE_TIMEOUT;
}

     2.分析命令行
while ((opt = getopt(argc, argv, "ndsm:xf:")) != EOF)

      3.运行于后台,设置权限,并设置信号
if (daemonize && daemon(0, 0)) 
umask(0077);

     4.创建并绑定hci socket
if ((hcid.sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0) {
error("Can't open HCI socket: %s (%d)",
strerror(errno), errno);
exit(1);
}
if (bind(hcid.sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
error("Can't bind HCI socket: %s (%d)",
strerror(errno), errno);
exit(1);
}
     5.设置过滤
hci_filter_clear(&flt);
hci_filter_set_ptype(HCI_EVENT_PKT, &flt);
hci_filter_set_event(EVT_STACK_INTERNAL, &flt);
if (setsockopt(hcid.sock, SOL_HCI, HCI_FILTER, &flt, sizeof(flt)) < 0) {
error("Can't set filter: %s (%d)",
strerror(errno), errno);
exit(1);
}

      6.下载main.conf
config = load_config(CONFIGDIR "/main.conf");

if (read_config(hcid.config_file) < 0)
error("Config load failed");

      7.添加IO通道
g_io_add_watch(child_io,
G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL,
child_exit, NULL);

      8.初始化适配器
init_adapters();

      9.初始化agent
agent_init();

      10.初始化dbus
if (hcid_dbus_init() < 0) {
error("Unable to get on D-Bus");
exit(1);
}

      11.开始sdp服务
start_sdp_server(mtu, hcid.deviceid, SDP_SERVER_COMPAT);

      12.初始化插件
plugin_init(config);

     13.初始化安全数据
init_security_data();

      14.初始化已连接的设备
init_all_devices(hcid.sock);

     15.恢复,清理
hcid_dbus_unregister();
plugin_cleanup();
stop_sdp_server();
free_device_opts();
agent_exit();
hcid_dbus_exit();





@Override public List<MatchGameRunnerScoreInfoVo> listByGameId(String gameId, String groupIds, Integer teamId, Integer leg) { // 获取运动员信息 List<MatchGameRunnerDo> runnerDos = selectRunnerList(gameId, groupIds, teamId, leg); if (CollectionUtil.isEmpty(runnerDos)) { return ListUtil.empty(); } List<MatchGameRunnerScoreInfoVo> list = BeanUtils.toBean(runnerDos, MatchGameRunnerScoreInfoVo.class); List<RunnerScoreQueryParam> queryParams = list.stream().map(r -> new RunnerScoreQueryParam(r.getGameId(), r.getHcId(), r.getTeamId())).collect(Collectors.toList()); List<MatchGamePunchVo> matchGamePunchVos = matchGamePunchMapper.selectRunnerPunch(queryParams); List<MatchGameRunnerScoreVo> matchGameRunnerScoreVos = matchGameSorceMapper.selectRunnerScore(queryParams); // 2. 构建(gameId+hcId)到打卡记录的Map Map<String, List<MatchGamePunchVo>> punchMap = matchGamePunchVos.stream() .collect(Collectors.groupingBy( punch -> buildCompositeKey(punch.getGameId(), punch.getHcId()), Collectors.toList() )); // 3. 设置打卡记录到成绩对象 matchGameRunnerScoreVos.forEach(scoreVo -> { String key = buildCompositeKey(scoreVo.getGameId(), scoreVo.getHcId()); scoreVo.setPunchs(punchMap.getOrDefault(key, Collections.emptyList())); }); // 4. 构建(gameId+hcId)到成绩对象的Map Map<String, MatchGameRunnerScoreVo> scoreMap = matchGameRunnerScoreVos.stream() .collect(Collectors.toMap( score -> buildCompositeKey(score.getGameId(), score.getHcId()), Function.identity() )); // 5. 设置成绩值到InfoVo list.forEach(infoVo -> { String key = buildCompositeKey(infoVo.getGameId(), infoVo.getHcId()); MatchGameRunnerScoreVo scoreVo = scoreMap.get(key); if (scoreVo != null) { setRunnerScoreValue(infoVo, scoreVo); } }); return list; }报错at java.util.stream.Collectors.lambda$throwingMerger$0(Collectors.java:133) at java.util.HashMap.merge(HashMap.java:1255) at java.util.stream.Collectors.lambda$toMap$58(Collectors.java:1320) at java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) at cn.iocoder.yudao.module.match.service.impl.MatchGameRunnerServiceImp.listByGameId(MatchGameRunnerServiceImp.java:152) at cn.iocoder.yudao.module.match.service.impl.MatchGameRunnerServiceImp$$FastClassBySpringCGLIB$$e90dd7ea.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)我需要根据这个报错修改后的完整代码
最新发布
04-03
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值