蓝牙uart透传技术摘要

蓝牙uart透传技术摘要

基于 nRF5_SDK_15.3.0_59ac345

app->mcu->uart

  1. BLE_NUS_DEF(m_nus, NRF_SDH_BLE_TOTAL_LINK_COUNT); 执行时将ble_nus_on_ble_evt,进行了注册了绑定。
  2. nrf_sdh_ble_evts_poll 执行时,通过回调,调用ble_nus_on_ble_evt。
  3. 当有蓝牙数据发送时,会触发BLE_GATTS_EVT_WRITE,调用on_write
  4. 在on_write中会调用我们在业务中注册的nus service 回调nus_data_handler,这个回调作为参数在ble_nus_init中注册。
  5. 在nus_data_handler中我们就可以将数据通过串口发送函数app_uart_put发出了

uart->mcu->app

  1. uart_event_handle回调函数到nus发送函数ble_nus_data_send
  2. sd_ble_gatts_hvx协议栈函数会将内容通过蓝牙发送给app

centos7 vsftp 虚拟用户配置

搞过好多遍了,每次都要花不少时间确认一些小问题,所以做个笔记,供以后参考
1. 安装 vsftpd

yum install vsftpd
chkconfig vsftpd on
  1. 测试端口外网可访问性,用telnet就可以测试,如果不可访问,请确认vsftp端口已经监听,并且iptable 或者firewall配置正确,同时如果用的是阿里云之类的云主机,确认云平台的安全策略是否已经开放21端口
  2. 创建用户
    useradd virtual -s /sbin/nologin
    默认的vsftpd的服务宿主用户是root,但是这不符合安全性的需要。这里建立名字为virtual的用户,用他来作为支持Vsftpd的服务宿主用户。由于该用户仅用来支持vsftpd服务用,因此没有许可他登陆系统的必要,并设定他为不能登陆系统的用户。
    这个用户跟配置文件中的guest_username字段是对应的。
  3. 修改/etc/vsftpd.conf
    修改:
anonymous_enable=NO
local_enable=YES
chroot_local_user=YES

新增:

guest_enable=YES
guest_username=virtual
virtual_use_local_privs=YES
user_config_dir=/etc/vsftpd/user_conf
reverse_lookup_enable=NO
  1. 修改 /etc/pam.d/vsftpd,删除原有内容,新增:
auth required pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required pam_userdb.so db=/etc/vsftpd/vsftpd_login
  1. 创建账号
    1)创建账号文件 login.txt:aaaa是密码,1111是密码,多个用户依次换行
aaa
111111
bbb
222

2)生成虚拟用户数据文件
db_load -T -t hash -f /etc/vsftpd/login.txt /etc/vsftpd/vsftpd_login.db
7. 创建虚拟账号
mkdir /etc/vsftpd/user_conf
vi aaaa
这里面的权限要根据需要的权限来配置,下面是一个可读写的全权限用户配置

local_root=/var/ftp/aaa
write_enable=YES
anon_umask=022
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
  1. 对相关的路径给与权限,这样才能正常上传,否则会提示553错误
mkdir -p /var/ftp/aaa

chown virtual:virtual /var/ftp/aaa

chmod 755 /var/ftp/aaa
  1. 配置完成重启服务
    systemctl restart vsftpd

Nordic SoftDevice 处理

来源:https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v14.2.0%2Fgroup__nrf__sdh.html&anchor=ga574d17fdf1c59dec6355e3f525c484ec

SoftDevice Handler

API for initializing and disabling the SoftDevice. More…

Modules

ANT support in SoftDevice Handler
This file contains the declarations of types and functions required for ANT stack support.
BLE support in SoftDevice Handler
This file contains the declarations of types and functions required for BLE stack support.
SoftDevice handler configuration
SoC support in SoftDevice Handler
This file contains the declarations of types and functions required for SoftDevice Handler SoC support.

Data Structures

struct nrf_sdh_req_observer_t
SoftDevice Handler state request observer. More…
struct nrf_sdh_state_observer_t
SoftDevice Handler state observer. More…
struct nrf_sdh_stack_observer_t
SoftDevice stack event observer. More…

Functions

ret_code_t nrf_sdh_enable_request (void)
Function for requesting to enable the SoftDevice. More…
ret_code_t nrf_sdh_disable_request (void)
Function for requesting to disable the SoftDevice. More…
ret_code_t nrf_sdh_request_continue (void)
Function for restarting the SoftDevice Enable/Disable process. More…
bool nrf_sdh_is_enabled (void)
Function for retrieving the SoftDevice state. More…
void nrf_sdh_suspend (void)
Function for stopping the incoming stack events. More…
void nrf_sdh_resume (void)
Function for resuming polling incoming events from the SoftDevice.
bool nrf_sdh_is_suspended (void)
Function for retrieving the information about the module state. More…
void nrf_sdh_evts_poll (void)
Function for polling stack events from the SoftDevice. More…

Softdevice Handler dispatch models

#define NRF_SDH_DISPATCH_MODEL_INTERRUPT   0
SoftDevice events are passed to the application from the interrupt context.
#define NRF_SDH_DISPATCH_MODEL_APPSH   1
SoftDevice events are passed to the application using SchedulerMore…
#define NRF_SDH_DISPATCH_MODEL_POLLING   2
SoftDevice events are polled manually using nrf_sdh_evts_poll()More…

SoftDevice Handler state change requests

enum nrf_sdh_req_evt_t { 
  NRF_SDH_EVT_ENABLE_REQUEST
  NRF_SDH_EVT_DISABLE_REQUEST 
}
SoftDevice Handler state requests. More…
typedef bool(* nrf_sdh_req_evt_handler_t )(nrf_sdh_req_evt_t request, void *p_context)
SoftDevice Handler state request handler. More…
#define NRF_SDH_REQUEST_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice state change request observer. More…

SoftDevice Handler state events

enum nrf_sdh_state_evt_t { 
  NRF_SDH_EVT_STATE_ENABLE_PREPARE
  NRF_SDH_EVT_STATE_ENABLED
  NRF_SDH_EVT_STATE_DISABLE_PREPARE
  NRF_SDH_EVT_STATE_DISABLED 
}
SoftDevice Handler state events. More…
typedef void(* nrf_sdh_state_evt_handler_t )(nrf_sdh_state_evt_t state, void *p_context)
SoftDevice Handler state event handler.
#define NRF_SDH_STATE_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice state observer. More…

SoftDevice stack events

typedef void(* nrf_sdh_stack_evt_handler_t )(void *p_evt)
SoftDevice stack event handler.
#define NRF_SDH_STACK_OBSERVER(_observer, _prio)
Macro for registering a SoftDevice stack events observer. More…

Detailed Description

API for initializing and disabling the SoftDevice.

Macro Definition Documentation

#define NRF_SDH_DISPATCH_MODEL_APPSH   1

SoftDevice events are passed to the application using Scheduler.

Note
Scheduler must be initialized before enabling the SoftDevice handler.

#define NRF_SDH_DISPATCH_MODEL_POLLING   2

SoftDevice events are polled manually using nrf_sdh_evts_poll().

Note
In this mode, a user application can also implement SD_EVT_IRQHandler() to receive a notification about incoming events.

#define NRF_SDH_REQUEST_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice state change request observer.

An observer of SoftDevice state change requests receives requests to change the state of the SoftDevice from enabled to disabled and vice versa. These requests may or may not be acknowledged by the observer, depending on the value returned by its request handler function. Thus, a request observer has the capability to defer the change of state of the SoftDevice. If it does so, it has the responsibility to call nrf_sdh_request_continue when it is ready to let the SoftDevice change its state. If such capability is not necessary and you only need to be informed about changes of the SoftDevice state, use the NRF_SDH_STATE_OBSERVER macro instead.

Note
This macro places the observer in a section named “sdh_req_observers”.
Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

#define NRF_SDH_STACK_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice stack events observer.

A SoftDevice stack event observer receives all events from the SoftDevice. These events can be either BLE, ANT, or SoC events. If you need to receive BLE, ANT, or SoC events separately, use the NRF_SDH_BLE_OBSERVERNRF_SDH_ANT_OBSERVER, or NRF_SDH_SOC_OBSERVER macros respectively.

Note
This macro places the observer in a section named “sdh_stack_observers”.
Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

#define NRF_SDH_STATE_OBSERVER ( _observer,
_prio
)

Macro for registering a SoftDevice state observer.

A SoftDevice state observer receives events when the SoftDevice state has changed or is about to change. These events are only meant to inform the state observer, which, contrary to a state change request observer, does not have the capability to defer the change of state. If such capability is required, use the NRF_SDH_REQUEST_OBSERVER macro instead.

This macro places the observer in a section named “sdh_state_observers”.

Parameters
[in] _observer Name of the observer.
[in] _prio Priority of the observer’s event handler. The smaller the number, the higher the priority.

Typedef Documentation

typedef bool(* nrf_sdh_req_evt_handler_t)(nrf_sdh_req_evt_t request, void *p_context)

SoftDevice Handler state request handler.

Return values
true If ready for the SoftDevice to change state.
false If not ready for the SoftDevice to change state. If false is returned, the state change is aborted.

Enumeration Type Documentation

SoftDevice Handler state requests.

Enumerator
NRF_SDH_EVT_ENABLE_REQUEST Request to enable the SoftDevice.
NRF_SDH_EVT_DISABLE_REQUEST Request to disable the SoftDevice.

SoftDevice Handler state events.

Enumerator
NRF_SDH_EVT_STATE_ENABLE_PREPARE SoftDevice is going to be enabled.
NRF_SDH_EVT_STATE_ENABLED SoftDevice is enabled.
NRF_SDH_EVT_STATE_DISABLE_PREPARE SoftDevice is going to be disabled.
NRF_SDH_EVT_STATE_DISABLED SoftDevice is disabled.

Function Documentation

ret_code_t nrf_sdh_disable_request ( void )

Function for requesting to disable the SoftDevice.

This function issues a NRF_SDH_EVT_DISABLE_REQUEST request to all observers that were registered using the NRF_SDH_REQUEST_OBSERVER macro. The observers may or may not acknowledge the request. If all observers acknowledge the request, the SoftDevice will be disabled. Otherwise, the process will be stopped and the observers that did not acknowledge have the responsibility to restart it by calling nrf_sdh_request_continue when they are ready for the SoftDevice to change state.

Return values
NRF_SUCCESS The process is started.
NRF_ERROR_INVALID_STATE The SoftDevice is already disabled.

ret_code_t nrf_sdh_enable_request ( void )

Function for requesting to enable the SoftDevice.

This function issues a NRF_SDH_EVT_ENABLE_REQUEST request to all observers that were registered using the NRF_SDH_REQUEST_OBSERVER macro. The observers may or may not acknowledge the request. If all observers acknowledge the request, the SoftDevice will be enabled. Otherwise, the process will be stopped and the observers that did not acknowledge have the responsibility to restart it by calling nrf_sdh_request_continue when they are ready for the SoftDevice to change state.

Return values
NRF_SUCCESS The process is started.
NRF_ERROR_INVALID_STATE The SoftDevice is already enabled.

void nrf_sdh_evts_poll ( void )

Function for polling stack events from the SoftDevice.

The events are passed to the application using the registered event handlers.

Note
NRF_SDH_DISPATCH_MODEL_POLLING must be selected to use this function.

bool nrf_sdh_is_enabled ( void )

Function for retrieving the SoftDevice state.

Return values
true If the SoftDevice is enabled.
false If the SoftDevice is disabled.

bool nrf_sdh_is_suspended ( void )

Function for retrieving the information about the module state.

Return values
true The SoftDevice handler is paused, and it will not fetch events from the stack.
false The SoftDevice handler is running, and it will fetch and dispatch events from the stack to the registered stack observers.

ret_code_t nrf_sdh_request_continue ( void )

Function for restarting the SoftDevice Enable/Disable process.

Modules which did not acknowledge a NRF_SDH_EVT_ENABLE_REQUEST or NRF_SDH_EVT_DISABLE_REQUEST request must call this function to restart the SoftDevice state change process.

Return values
NRF_SUCCESS The process is restarted.
NRF_ERROR_INVALID_STATE No state change request was pending.

void nrf_sdh_suspend ( void )

Function for stopping the incoming stack events.

This function disables the SoftDevice interrupt. To resume polling for events, call nrf_sdh_resume.


Documentation feedback | Developer Zone | Subscribe | Updated 2017-11-24


mtk编译环境和git环境sh.exe的冲突问题

如前面的文章mtk编译时的ole.pm相关问题 提到的问题,当时为了先把mtk的编译搞定,临时的方案就是git路径下的sh.exe重命名。
但是git也是高频使用的工具,重命名肯定不是长久方案。所以还是要从根本上解决这个问题。
分析mtk的编译环境,要串接window下的相关编译工具MSYS等,还是通过系统环境变量完成的。我们搜索系统环境的Path路径,确实发现了Git的 /usr/bin 的相关路径。
删除这个路径,将重命名的sh.exe恢复,发现mtk编译正常。
再回到git工作环境,发现再删除环境路径的情况下,也工作正常,git是会支持搜索本地递归路径的吧。

至此,这个sh.exe影响的问题算是彻底解决了。

MTK GSM方案模拟器相关问题

对于开发mtk方案来说,模拟器至关重要,是提升开发效率的利器。
除了硬件驱动相关的数据接口模拟器不能调试外,tcp,wifi 等数据通讯和业务逻辑等,大多都能在模拟器中完成,所以开发mtk一定要把模拟器用好。
拿到2503的代码后,发现了一些小问题,记录之。
1. cl.exe错误
在安装vs2008后,本地已经有了cl.exe,但是模拟器代码跑起来后报cl的相关错误,很显然是环境变量确实,导致脚本调用失败。
2. 头文件错误
fatal error C1083: 无法打开包括文件:“stdarg.h”: No such file or directory
本地搜索,文件是存在的。所以还是调用问题,经确认,make\modisConfig.mak 中有对vs的路径做设定,默认是按照c盘指定的,但是本人是安装到d盘,所以该项c盘相关的路径就可以了
3. 其他函数编译错误
拿到代码后,发现之前的开发并没有使用过modis,所以硬件配置是可以编译通过的,但是modis编译不行,主要是WIN32相关的宏生命周期范围有误,还有些是对应的新增文件没有生成进modis生成的vs工程中,导致编译时调用符号缺失,根据对应函数的名称,将相关的实现文件添加到vs的工程中就可以编译了。
4. 运行崩溃问题
因为工程可能并没有在modis下面验证过,所以即使编译通过,也可能运行时崩溃。崩溃的地方主要在模拟器和硬件的逻辑差异部分,自己确认逻辑,加上合适的WIN32,基本就能问题结局。
5. 硬件数据问题
因为模拟器不能真正的使用硬件,所以在使用模拟器的时候,我们要最大可能的尽量通过软件宏逻辑来模拟硬件的数据,保证模拟器的流程跟真实硬件相同。主要的工作包括数据模拟,定时器模拟等。

mtk编译时的ole.pm相关问题

编译2503代码时发现如下的问题:

Can't locate Win32/OLE.pm in @INC (you may need to install the Win32::OLE module
) (@INC contains: /usr/lib/perl5/site_perl /usr/share/perl5/site_perl /usr/lib/p
erl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5/core_perl /usr/shar
e/perl5/core_perl .) at make2.pl line 37.
BEGIN failed--compilation aborted at make2.pl line 37.

ole.pm这个文件本身是perl安装时就有的,提示找不到,肯定是路径问题。

解决需要关注两点:
1. 添加perl路径的环境变量 : PERL5LIB ,设置成perl安装后的实际lib路径
2. 因为编译脚本中有调用MSYS 下的sh.exe, 如果你本地安装过git,需要重命名或者去掉git下的sh.exe的可访问性,这样mtk的编译脚本就不会发生路径错误了。

ios xib布局使用

xib由于里面使用的数字都是参考父对象,实际上就是绝对布局。
1. 设置空间对象的长宽,设置上下左右的某一参考方向的边距
2. 设置对齐的方式,上下左右,水平或者垂直对齐。
3. 关联控件和头文件定义的对象变量,通过拖拽连线完成。

对于一些简单的页面,xib就足够好用了

关于ameba系列处理器OTA包首地址的说明

目前的代码,可以看到ota镜像的首地址是写死的:

#if WRITE_OTA_ADDR
  uint32_t ota_addr = 0x80000;
#endif

也就是ota包的首地址从512k开始。

那么,如果首地址不是写死的,那么这个地址是怎么设置的?
走读代码,发现的线索,uart_ymodem.c的567行:

flash_write_word(&ptr->flash, OFFSET_DATA, ptr->image_address);
}

其中ptf是ymodem数据对象,image_address应该就是下载工具界面中设置的值,具体细节需要在ymodem实际交互中才能确认。

电信iTV设置

封装类型:PPPoE
业务类型:其他
连接模式:桥接
IP模式:IPV4
MTU:
1500
启用VLAN: 启用
VlanID:
45
802.1p:
启用DHCP:不选
组播上行通道: 关闭
LAN端口绑定: iTV
SSID 端口绑定: 不选

需要注意的是,经过反复验证:
1. VlanID只能是45,换了别的无法正常收看,具体原因不详,可能跟每个人的光纤接入设备有关吧。
2. LAN端口绑定必须是iTV

各链接状态如下所示:

esp32 ubuntu开发环境搭建

  1. 工具链准备
    gcc及python环境准备
sudo apt-get install gcc git wget make libncurses-dev flex bison gperf python python-pip python-setuptools python-serial python-pyparsing
  1. 查看系统版本,安装相应的工具链包
cat /proc/version

64位下载:

wget https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz

解压
设置环境变量,目前发现docker中,只有.bashrc 中生效

export PATH="$HOME/esp/xtensa-esp32-elf/bin:$PATH"
  1. esp-idf 安装
git clone --recursive https://github.com/espressif/esp-idf.git

设置环境变量,目前发现docker中,只有.bashrc 中生效

export IDF_PATH=~/esp/esp-idf
  1. 安装依赖的 Python 软件包
python -m pip install --user -r $IDF_PATH/requirements.txt

git tips

  1. 强制放弃修改
    git reset –hard origin/master
    这个master是你当前本地仓库的分支,要根据实际情况来修改
  2. clone指定的分支
    git clone -b aaa http://bbb
    aaa是远程的分支名,bbb是仓库路径