ESP8266 for HDLC decoding, AX.25, APRS
tags:Arduinoalgorithm
/**************************************************************Function name: aprs_wait_begin() Parameters: None Return value: bool true = get legal pulse, false = not get Explanation: Wait for the first 833us high pulse, the judgment range is 730-930, others are ignored***************************************************************/bool aprs_wait_begin(){static unsigned long lastTime = micros();static unsigned char lastLevel = digitalRead(APRS_DATA_IO);unsigned char nowLevle = digitalRead(APRS_DATA_IO);//Rising edge, set the pulse start timeif(nowLevle && !lastLevel){lastLevel = nowLevle;lastTime = micros();}//Falling edge, judge the pulse widthelse if(!nowLevle && lastLevel){long pulseTime = micros()-lastTime;lastLevel=nowLevle;//Legal pulse is judged at 833us plus or minus 100us, it can be smallerif(pulseTime>730 && pulseTime<930){return true;}}return false;} //end aprs_wait_begin()/************************************************************** Function name: aprs_rx_data() Parameters: None Return value: None Explanation: This function is in blocking mode and will not exit before the reception is completed or timeout 1200bps, 1200 bits per second, 833us per bit width Level flip = logic 0, level remains unchanged = logic 1 After getting the first legal pulse, start to receive data in bytes, and save it once every 8 bits At this time, you will also receive Flag:0x7E, that is: 6 consecutive "1"s Check the value of sameBit when the level is flipped 6 consecutive "1" bytes are the first byte of data And mark isData=1; Received again 6 consecutive "1"s have been received In any case, receiving 7 consecutive "1" judgment data is invalid Set the sameBit to 0 after each level flip, the last time increases the current time +450us, Ensure that every 833us backward sampling point is stuck in the middle of each bit***************************************************************/void aprs_rx_data(){unsigned char bitBuf=0x00; //bit buffer receives the low bit firstunsigned char bitCount=0; //bit counter, once every 8 bits are written to the bufferunsigned char sameBit=0; //Continuous 1 counterunsigned char isData=0; //Whether the data segmentunsigned char lastLevel = digitalRead(APRS_DATA_IO);unsigned char nowLevle;unsigned long lastTime;unsigned long nowTime;//The previous program caught the first legal pulse, so it received a level flip that is "0", and the bit counter is now 1bitCount = 1; lastTime = micros() + 450;while(1){ESP.wdtFeed(); //Feed the dog, I don’t know why ESP8266 triggers the watchdog in the while.//delayMicroseconds(10);nowLevle = digitalRead(APRS_DATA_IO);nowTime = micros();//Level flipif(nowLevle != lastLevel){lastLevel = nowLevle;lastTime = nowTime+450;//According to the HDLC protocol, we regard Flag 0x7E as 6 consecutive "1"s, and insert 5 consecutive "1"s into the data to avoid 6 "1"s.//Here when less than 5, set to 0if(sameBit<5){sameBit=0;}//6 consecutive "1"s appeared, which means the end when receiving dataif(sameBit==6 && isData){toCodeFlag=1;return;}//5 consecutive "1"s, delete 0, ignore this bit and continue will bring the program back to the starting point of whileif(sameBit==5){sameBit=0; continue;}//The number of bits reaches 8, and the full 1 byte is processed accordinglyif(++bitCount==8){//Received bytes that are not 6 consecutive "1"s in the non-data segment, indicating the beginning of the dataif(!isData && sameBit != 6){isData=1;}if(!isData){continue;}//isData = 0;if(aprsCount == APRS_DATA_BUF_MAX){aprsCount=0;}aprsData[aprsCount++]=bitBuf;bitCount=0;bitBuf=0x00;}continue;}//When the level is maintained at 833us, logic 1 is obtainedif(nowTime>lastTime && (nowTime - lastTime) > 833){lastTime = nowTime;//During the data transmission process, any 7 consecutive "1"s that appear before the Flag are judged to be abnormal, and no decoding is performedif(++sameBit==7){toCodeFlag=0;return;}//Fill "1" to the specified positionbitBuf |= 0x01 << bitCount;//Collect 1 byteif(++bitCount==8){if(aprsCount == APRS_DATA_BUF_MAX){aprsCount=0;}aprsData[aprsCount++] = bitBuf;bitCount=0;bitBuf=0x00;}continue;}}// end while}//end aprs_rx_data()
Copyright ComplaintSpam Report
Intelligent Recommendation
Data Link Layer: HDLC
A. Protocol Machine The sender and receiver, while the finite state machine the protocol is formulated as a four-tuple (S, M, I, T), where you S that the process and the channel may enter the set, M i...
HDLC&PPP
Huawei: HDLC configuration: R1<Huawei>system-view [Huawei]sysname AR1 [AR1]interface Serial 1/0/0 [AR1-Serial1/0/0]link-protocol hdlc —— (Enable HDLC) Warning: The encapsulatio...
MGRE, PPP, HDLC experiment
table of Contents Topology design Topology construction Configuration &...
Configure HDLC under ensp
Advanced Data Link Control HDLC PPP point-to-point protocol HDLC interface address borrowing Without an IP address, an interface cannot generate a route and cannot forward packets. IP address borrowin...
HDLC frame format
The DLMS communication link frame basically adopts the HDLC frame format. HDLC except for a few special fields, the other fields are all hexadecimal data, This chapter I mainly share what is HDLC fram...
More Recommendation
PPP protocol and HDLC protocol
PPP protocol and HDLC protocol 1. WAN 2. Features of PPP protocol 3. Requirements that the PPP protocol should meet 4. Requirements that the PPP protocol does not need to meet 5. The three components ...
HDLC and PPP verification
1. Brief introduction 1. The high-level data link control (HDLC) protocol is based on a data link layer protocol, which promotes the data transmitted to the next layer to be accurately received...
Application of HDLC and PPP
HDLC and PPP Serial links are often used in wide area networks to provide long-distance data transmission. HDLC (High-Level Data Link Control) and Point to Point Protocol (PPP) are two typical serial ...
Principle and configuration of HDLC and PPP
Introduction: Serial links are often used in wide area networks to provide long-distance data transmission. HDLC (High-Level Data Link Control) and Point to Point Protocol (PPP) are two typicalSerial ...
Router's WAN HDLC encapsulation
HDLC calls advanced data link control Turn off the power first, then add W1C-1T module to the router, and finally turn on the power Add DCE serial line RA is the same as RB, before 255 is changed to 2...
- Related Posts
- Create an APRS meteorological station using ESP8266
- ESP8266 APRS board modifies to submit data to the T2 server method
- 25. Wide area network, PPP protocol and HDLC protocol
- HDLC of WAN
- HDLC configuration
- HDLC foundation
- Transceiver of APRS signal
- ESP8266 soft serial port decoding infrared remote control
- Introduction to HDLC Technology
- WAN technology - two (HDLC)
- Popular Posts
- Activity of the four major components of Android
- Chapter 4 --- The maximum-subarray problem (INTRODUCTION TO ALGORITHMS THIRD EDITION)
- LUA Learning --__ Index and __newindex
- Mybatis learning (5) - MyBatis cache
- @ Select statement learning notes
- HDFS upload and download files, create a directory delete, query file operations
- Detailed IO model
- Toggle control and @Binding attribute decorator based on SwiftUI (including code demo)
- MySQL DATE_FORMAT() function formatted date
- Ubuntu 16 Install Torch7, graphics card driver, CUDA, CUDNN
- Recommended Posts
- ES starts 08----Generator function started by ES6
- OpenCV4.5.1 Getting started for the first week
- Implement vlc player in Java
- The method of efficiently remove the linear table of the plurality of elements
- Micro Service-Spring Cloud Integrate Consul Implementation Service Registration and Health Inspection
- Bit order, endian, type order
- ioi2000 palindrome
- Scope of arrow functions
- Python is used to read the file, take CSV as an example
- Vue Element Component Image-Viewer Note
- Related Tags hardwarearduinoAmateur radiolinuxcomputer networknetworkserverNetwork protocolWanHDLC