Serialapp-ZigBee serial port application instance

Source: Internet
Author: User
Serialapp-ZigBee serial port application instance this example application Z-stack version ZStack-1.4.3-1.2.1
The serial application of serialapp in Z-stack is used to connect two cc2430eb boards to the computer through serial port, and data is transmitted to each other. The working process is: The cc2430 antenna receives data (OTA data), triggers sys_event_msg in serialapp_task, judges the small event af_incoming_msg_cmd in sys_event_msg, and CALLS serialwsn_processmsgcmd (
Afincomingmsgpacket_t * Pkt) judge the type of the Cluster. serialwsn_clusterid1 indicates that the data block is accepted (
Serial_app_port, Pkt-> cmd. Data + 1, (Pkt-> cmd. DataLength-1 ))
To the serial port, serialwsn_clusterid2 indicates that the response is successfully sent. If not, the automatic resend is canceled.

The cc2430 serial port receives data, the Buf overflows, And the rxcb function is automatically called. The osal_set_event (
Serialwsn_taskid, serialwsn_msg_send_evt
) To trigger data transmission. Then, the serialwsn_taskid detects the serialwsn_msg_send_evt time and calls serialwsn_senddata (
Otabuf, otalen) transmits data from the serial port through the air.

Welcome to the Nils Forum http://nireus.uueasy.com/

If the serial port works properly, call haluartinit first.
() And haluartopen (uint8 port, haluart1__t * config) two functions uint16 haluartwrite (
Uint8 port, uint8 * pbuffer, uint16 Length
); The port and cc2430 have two uarts, one of which is hal_uart_port0 at The P0 port, and the other is hal_uart_port1 at the P1 port.

The other is haluartcfg_t (serial port configuration structure). Let's take a look at its prototype.
Typedef struct
{
 
Bool configured;
Uint8 baudrate; // baud rate
The Protocol Stack has only two baud rates: 38400 and 115200.
Bool
Flowcontrol; // The control bit. If it is 1, it indicates that it is 4-line mode. 0 indicates 2-line mode. The default value is 4-line mode.
Uint16
Flowcontrolthreshold;
Uint8 idletimeout;
 
Haluartbufcontrol_t RX;
Haluartbufcontrol_t TX;
 
Bool intenable;
Uint32 rxchrvdtime;

Haluartcback_t callbackfunc;
} Haluart+_t; in the original example template, the default value can be used elsewhere. If your Board adopts the 2-wire mode, you must use the serialwsn_init (
Uint8 task_id) Change uartconfig. flowcontrol = ture to false.
To add your own applications based on this template, you only need to modify rxcb and serialwsn_processmsgcmd.

During the data stream process, each sent data is preceded by a serialwsn_seqtx. Each time a data packet is sent, serialwsn_seqtx increases by 1, so the serialwsn_seqtx of each data packet is different. Then, the target node will return a response after receiving the data. If the value of serialwsn_seqtx in the received response is the same as that of the current serialwsn_seqtx, it indicates that the sending is successful and otabuf is cleared.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.