acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
AX25_Frames.ino (5229B)
1 /* 2 RadioLib AX.25 Frame Example 3 4 This example shows how to send various 5 AX.25 frames using SX1278's FSK modem. 6 7 Other modules that can be used for AX.25: 8 - SX127x/RFM9x 9 - RF69 10 - SX1231 11 - CC1101 12 - SX126x 13 - nRF24 14 - Si443x/RFM2x 15 16 Using raw AX.25 frames requires some 17 knowledge of the protocol, refer to 18 AX25_Transmit for basic operation. 19 Frames shown in this example are not 20 exhaustive; all possible AX.25 frames 21 should be supported. 22 23 For default module settings, see the wiki page 24 https://github.com/jgromes/RadioLib/wiki/Default-configuration 25 26 For full API reference, see the GitHub Pages 27 https://jgromes.github.io/RadioLib/ 28 */ 29 30 // include the library 31 #include <RadioLib.h> 32 33 // SX1278 has the following connections: 34 // NSS pin: 10 35 // DIO0 pin: 2 36 // RESET pin: 9 37 // DIO1 pin: 3 38 SX1278 radio = new Module(10, 2, 9, 3); 39 40 // or using RadioShield 41 // https://github.com/jgromes/RadioShield 42 //SX1278 radio = RadioShield.ModuleA; 43 44 // create AX.25 client instance using the FSK module 45 AX25Client ax25(&radio); 46 47 void setup() { 48 Serial.begin(9600); 49 50 // initialize SX1278 51 Serial.print(F("[SX1278] Initializing ... ")); 52 // carrier frequency: 434.0 MHz 53 // bit rate: 1.2 kbps (1200 baud 2-FSK AX.25) 54 // frequency deviation: 0.5 kHz (1200 baud 2-FSK AX.25) 55 int state = radio.beginFSK(434.0, 1.2, 0.5); 56 57 // when using one of the non-LoRa modules for AX.25 58 // (RF69, CC1101, Si4432 etc.), use the basic begin() method 59 // int state = radio.begin(); 60 61 if(state == RADIOLIB_ERR_NONE) { 62 Serial.println(F("success!")); 63 } else { 64 Serial.print(F("failed, code ")); 65 Serial.println(state); 66 while(true); 67 } 68 69 // initialize AX.25 client 70 Serial.print(F("[AX.25] Initializing ... ")); 71 // source station callsign: "N7LEM" 72 // source station SSID: 0 73 // preamble length: 8 bytes 74 state = ax25.begin("N7LEM"); 75 if(state == RADIOLIB_ERR_NONE) { 76 Serial.println(F("success!")); 77 } else { 78 Serial.print(F("failed, code ")); 79 Serial.println(state); 80 while(true); 81 } 82 } 83 84 void loop() { 85 // create AX.25 Unnumbered Information frame 86 // destination station callsign: "NJ7P" 87 // destination station SSID: 0 88 // source station callsign: "N7LEM" 89 // source station SSID: 0 90 // control field: UI, P/F not used, unnumbered frame 91 // protocol identifier: no layer 3 protocol implemented 92 // information field: "Hello World!" 93 AX25Frame frameUI("NJ7P", 0, "N7LEM", 0, RADIOLIB_AX25_CONTROL_U_UNNUMBERED_INFORMATION | 94 RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME, 95 RADIOLIB_AX25_PID_NO_LAYER_3, "Hello World (unnumbered)!"); 96 97 // send the frame 98 Serial.print(F("[AX.25] Sending UI frame ... ")); 99 int state = ax25.sendFrame(&frameUI); 100 if (state == RADIOLIB_ERR_NONE) { 101 // the packet was successfully transmitted 102 Serial.println(F("success!")); 103 104 } else { 105 // some error occurred 106 Serial.print(F("failed, code ")); 107 Serial.println(state); 108 109 } 110 111 delay(1000); 112 113 // create AX.25 Receive Ready frame 114 // destination station callsign: "NJ7P" 115 // destination station SSID: 0 116 // source station callsign: "N7LEM" 117 // source station SSID: 0 118 // control field: RR, P/F not used, supervisory frame 119 AX25Frame frameRR("NJ7P", 0, "N7LEM", 0, RADIOLIB_AX25_CONTROL_S_RECEIVE_READY | 120 RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_SUPERVISORY_FRAME); 121 122 // set receive sequence number (0 - 7) 123 frameRR.setRecvSequence(0); 124 125 // send the frame 126 Serial.print(F("[AX.25] Sending RR frame ... ")); 127 state = ax25.sendFrame(&frameRR); 128 if (state == RADIOLIB_ERR_NONE) { 129 // the packet was successfully transmitted 130 Serial.println(F("success!")); 131 132 } else { 133 // some error occurred 134 Serial.print(F("failed, code ")); 135 Serial.println(state); 136 137 } 138 139 delay(1000); 140 141 // create AX.25 Information frame 142 // destination station callsign: "NJ7P" 143 // destination station SSID: 0 144 // source station callsign: "N7LEM" 145 // source station SSID: 0 146 // control field: P/F not used, information frame 147 // protocol identifier: no layer 3 protocol implemented 148 // information field: "Hello World (numbered)!" 149 AX25Frame frameI("NJ7P", 0, "N7LEM", 0, RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | 150 RADIOLIB_AX25_CONTROL_INFORMATION_FRAME, RADIOLIB_AX25_PID_NO_LAYER_3, 151 "Hello World (numbered)!"); 152 153 // set receive sequence number (0 - 7) 154 frameI.setRecvSequence(0); 155 156 // set send sequence number (0 - 7) 157 frameI.setSendSequence(0); 158 159 // send the frame 160 Serial.print(F("[AX.25] Sending I frame ... ")); 161 state = ax25.sendFrame(&frameI); 162 if (state == RADIOLIB_ERR_NONE) { 163 // the packet was successfully transmitted 164 Serial.println(F("success!")); 165 166 } else { 167 // some error occurred 168 Serial.print(F("failed, code ")); 169 Serial.println(state); 170 171 } 172 173 delay(1000); 174 }