嗨对话框,
我正在尝试编写一个固件,使开发套件板(基本)是一个加密狗。
I have written a desktop software that will communicate with the board via serial port.
我希望当软件向电路板发送命令时,电路板可以相应地响应。例如扫描与对等设备连接的对等设备等。计算机中安装的固件还可以发现它连接的对等设备的服务和归属,并通过串行端口向软件报告它们。它还可以从连接的对等设备收到通知数据,然后再次报告到PC软件。
我已经阅读了DSP示例,但它发现了对等设备并通过设备名称连接到给定的设备(在代码中预先给出!!!!)。所以你会帮我一个忙,为我写一个指导线吗?谢谢!
我试图在user_sps_host.c中修改代码,user_on_adv_report_ind函数如下修改,并且我还修改了user_on_scanning_Completed函数,以便在获得的5个设备时停止扫描。
void user_on_adv_report_ind(struct gapm_adv_report_ind const * param)
{
// get device name
uint8 i=0, j=0;
uint8 len = sizeof(param-> report.data);
char dn [20] =“”;
for(i = 0; ireport.data [i]> = 0x20 && param-> report.data [i] <= 0x7e)
{
dn [j ++] = param-> report.data [i];
}
}
// get device address
len = sizeof(param-> report.addr.addr);
char add_buffer [13] =“”;
j = 0;
for(i = 0; ireport.adv_addr.addr [len - i - 1]);
add_buffer[j] = buffer[0];
add_buffer [j + 1] =缓冲器[1];
j = j + 2;
}
//获得rssi.
char rssi [3];
Sprintf(RSSI,“%D”,Param-> Report.RSSI);
// form the packet that will send to the PC via UART2
char packet [44];
j = 0;
数据包[j ++] ='*';
packet[j++] = 'D';
数据包[j ++] ='n';
数据包[j ++] =':';
for(i = 0; i <20; i ++)
{
if(dn [i]!= 0x00)
{
包[j ++] = dn [i];
}
}
packet[j++] = ',';
for(i=0; i<13; i++)
{
if(add_buffer[i] != 0x00)
{
packet[j++] = add_buffer[i];
}
}
packet[j++] = ',';
for(i=0; i<3; i++)
{
if(add_buffer[i] != 0x00)
{
packet[j++] = add_buffer[i];
}
}
数据包[j ++] ='\ r';
数据包[j ++] ='\ n';
//将数据包发送到PC
printf_string(数据包);
}
void user_on_scanning_Completed(UINT8_T状态)
{
device_count++;
if(device_count <= 5)
{
user_scan_start();
}
else
{
user_wait_for_cmd();
}
返回;
}
Here, I added a function called user_wait_for_cmd(), which is used to read the command, and is implemented as follows, and the uart2 read completed callback is used to recall the user_wait_for_cmd() . However, the program come up with an JLINK Error, that says Can not read registers ## while CPU is running. what is the problem for this implementation?
void user_wait_for_cmd(void)
{
uint8_t read_length = 25;
while(!read_success)
{
uart2_read((uint8_t *)buffer, read_length, uart2_read_completion_cb);
}
}
bool read_success ;
void UART2_READ_COMPLETION_CB(UINT8_T状态)
{
if(buffer[0]=='C' && buffer[1]=='M' && buffer[2]=='D')
{
read_success = true;
printf_string(缓冲区);
}
else
{
read_success = false;
user_wait_for_cmd();
}
}
By the way, where can I buy a dongle for DA14580?
嗨wenkangl,
As far as i know it goes along with the pro-dev kit, i dont think that is sold seperately. Some comments regarding the code you ve pasted, i can see that you are counting the devices that you ve discovered when user_on_scanning_completed() is invoked, that means that you are counting the scanning cycles of your device, every scan cycle lasts a few seconds and the user_on_scanning_complete is invoked either when you cancel the scanning procedure or when the scan operation completes. The advertising messages are comming as indications to the user_on_adv_report_ind() everytime the device gets a new advertising string. So in order to count devices scanned, what you must do is to check the bd address of the current advertising string and check the entries in your log (the place that you keep the recorded devices) and count up when you are placing a new entry in your log. Regarding the error that you are getting when applying the code for reading, i dont think that your implementation is responsible for it, check the default sleep mode of the device and make sure that the sleep mode is disabled (you cant have the sleep mode enabled and debug at the same time). Also you will have to consider the fact that the 580 when it sleeps all the peripherals are powered down including the UART, the DSPS for example uses the a flow control scheme in order to signal the external MCU when its allowed to send data or not, since if the data are sent while the 580 sleeps they will be lost.
谢谢mt_dialog.
谢谢mt,
I have more questions on this topic, since my aim is more than counting the devices nearby.
no1。在da1458x_config_basic.h中,睡眠模式已被配置为活动:
#undef cfg_mem_map_ext_sleep.
#undef CFG_MEM_MAP_DEEP_SLEEP
然后我发送扫描命令(CMD_SCAN) to the DB, and the firmware did call the user_scan_start() and run the function to the end. However, after that, the user_on_adv_report_ind is NOT triggered, and moreover, when I sent a command of connection (CMD_CONNECT), the program called user_connect_to but the user_on_scanning_completed and user_on_connection are NOT triggered... so in this situation, what is wrong with my implementation.
我已经修改了函数UART2_READ_COMPLETION_CB如下所示
Char Buffer [25];
静态UINT8_T UART2_READ_IN_POGRONGER = 0;
void UART2_READ_COMPLETION_CB(UINT8_T状态)
{
if(buffer[0]=='C' && buffer[1]=='M' && buffer[2]=='D')
{
uart2_read_in_progress = 0;
printf_string(缓冲区);
action_on_command();
}
else
{
user_wait_for_cmd();
}
}
void user_wait_for_cmd(void)
{
uint8_t read_length = 25;
uart2_read_in_progress = 1;
uart2_read((uint8_t *)buffer, read_length, uart2_read_completion_cb);
while(uart2_read_in_progress);
}
收到命令的行动如下
void action_on_command(void)
{
char cmdid [] = {buffer [4],缓冲区[5]};
uint8 cmd_id =(uint8)strtol(cmdid,null,16);
uint8 hexdata[16]={0};
uint8 i = 7;
虽然(!(缓冲区[i] ==''\\'&& buffer [i + 1] =='r'))
{
hexdata [I-7] =缓冲器[i];
I ++;
}
switch(CMD_ID)
{
case CMD_SCAN:
{
// 0x00.
user_scan_start();
休息;
}
case CMD_CONNECT:
{
// 0x01
uint8 peer_addr[6]={0x00};
for(i=0; i<6; i++)
{
char temp [] = {hexdata [2 * i],hexdata [2 * i + 1]};
uint8 part_add =(uint8)strtol(temp,null,16);
peer_addr [5-i] = part_add;
}
user_connect_to(0x00,peer_addr);
休息;
}
}
}
user_connect_to如下
void user_connect_to(uint8_t peer_addr_type,uint8_t * peer_addr)
{
app_easy_gap_start_connection_to_set(peer_addr_type,peer_addr,ms_to_doubleslots(user_con_intv));
app_easy_gap_start_connection_to();
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NO2. Then I came up with another idea. That is, even if I solved the problem described above, it still can't be satisfying. Because I hope DA14580 could handle at least two tasks asynchronously, that is, it keeps monitoring the command sent from PC ( and the DA14580 should always be monitoring the command sent by PC) and meanwhile doing something else.
例如,它监视PC的命令,同时接收连接的外围设备发送的通知数据并将数据发送到PC。
另一个例子:当DB接收到通知数据时,我向DB发送停止通知命令。DB应停止上传接收到的通知数据,并将停止通知命令发送到连接的外围设备,并且连接的外围设备将相应地进行。
为此目的,如果我想使用DSP项目,我该怎么办?PS:问题专注于中心末端(加密狗),外围端的任务已经完成。^ _ ^
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
no3。由于加密狗没有单独出售,您是否可以推荐一个适用于DA14580的人?ConnectBlue?
谢谢!
嗨wenkangl,
NO1: The definitions that you ve changed affects the memory mapping of your device and not the sleeping mode (its mentioned in the comment above "Sleep mode memory map configuration."), To change the default sleep mode you have to change the app_default_sleep_mode in the user_config.h file with ARCH_SLEEP_OFF, this is the reason for the error that JLink reports after a few seconds while you are in debug mode. Regarding the fact that the user_on_adv_report_ind is not triggered (i suppose that you are trying to catch the advertising indication by using a breakpoint), if indeed the new scanning procedure has started you wont be able to catch that advertising event via a breakpoint since your debugger is de-attached from your 580. Please check the above and if indeed you had disabled sleep and the proper functions are called when the corresponding commands are sent from UART check if the advertising device is actually advertising and can accept connections.
No3:从对话框提供的加密狗不是通用的加密狗,您可以连接到Windows机器并被识别为蓝牙模块,它只是一个580,带有Atmel微控制器,用作USB端口的桥梁,仅接受UART命令通过GTL(Propriale Protocol)。我怀疑一般的BLE模块是您想要的,虽然我无法提出建议,但我想支持支持4.0规范的任何BLE加密狗,但在我们使用的大多数应用程序(测试)中我们正在使用Android雷竞技安卓下载手机。
No2:DSP示例监视UART并服务于DSPS_TASK(发送通知并从中中心接受写入命令)。当数据在UART中可用时,发生ISR的ISR并且代码处理UART的FIFO并正确处理数据,它不会轮询UART考虑此额外任务。您可以作为示例研究此实现。
谢谢mt_dialog.
谢谢,山
至于NO2,是您提到的ISR是UART2.c中的uart2.cher(void),以及收到的数据的dsps_task是uart2_rec_data_avail_isr?如果是这样,我应该在哪里放置我定义的action_on_command()?你的意思是,我应该直接修改UART2_REC_DATA_AVAIL_ISR吗?
你能在DSPS_TASK上解释更多吗?
非常感谢!
并且当我通过代码读取时,我发现UART2_ENV.RX.Callback被分配在UART2_READ中,并且当接收时,执行UART2_REC_DATA_AVAIL_ISR()并执行定义的回调。然后在UART2_REC_DATA_AVAIL_ISR()中将清除回调指针。如果我的理解是对的吗?如果是这样,是否意味着我需要调用UART2_READ来获取收到的命令,而不是我在PC上发送命令,并调用action_on_command()?
嗨wenkangl,
DSP和实现的脱胶机制使用不同的UART(580中有两个相同的UART模块),因此每个UART都有单独的ISR处理程序。如何处理您的中断和数据,这取决于您的应用程序以及您想要实现它的方式。关于DSPS_Task(Task_sps_server更加确切)是DSPS设备的配置文件任务,您可以在UM-B-038串行端口服务应用程序文档中找到更多信息。
是的,您的理解是正确的,在UART2获取数据上的数据后,您将清除回调,您只需调用UART2_READ()即可继续执行任何您正在做的事情,并且当您在UART中获取数据时,中断将继续进行中断,当您达到您的数据的大小时,您的回调(在调用UART读取时设置的一个)将被调用并通知您所指定的数据已到达,并且将禁用UART中断。这意味着如果您的命令具有指定大小,则可以在等待它时设置每个命令的大小,或者您可以指定将读取第一个字节作为命令大小的命令格式(读取一个字节为大小)和然后根据该特定大小命令设置回调,或者您可以始终等待一个字节并等待命令的终端字符(指示命令结束),有相当少的选项如何实现这一目标但是我在上面提到的,这取决于你希望如何实现的方式。
谢谢mt_dialog.
谢谢mt,
因此要监视UART,我必须经常调用UART2_READ(),并且我的解决方案到数据包的大小是这样,我使用固定的长度分组(25如代码中所示),并且该命令将是预先的- 处理使其始终为25(在数据包的末尾添加0,因此它的长度为25)。我正试图得到中央工作。