github.com/la5nta/wl2k-go@v0.11.8/transport/ax25/tnc.go (about) 1 // Copyright 2015 Martin Hebnes Pedersen (LA5NTA). All rights reserved. 2 // Use of this source code is governed by the MIT-license that can be 3 // found in the LICENSE file. 4 5 package ax25 6 7 import ( 8 "strings" 9 "time" 10 ) 11 12 const ( 13 B9600 HBaud = 9600 14 B1200 = 1200 15 ) 16 17 const ( 18 _CONFIG_TXDELAY_UNIT = time.Millisecond * 10 19 _CONFIG_SLOT_TIME_UNIT = time.Millisecond * 10 20 _CONFIG_FRACK_UNIT = time.Second 21 _CONFIG_RESPONSE_TIME_UNIT = time.Millisecond * 100 22 ) 23 24 type tncAddr struct { 25 address Address 26 digis []Address 27 } 28 29 func (a tncAddr) Digis() []Address { return a.digis } 30 func (a tncAddr) Address() Address { return a.address } 31 32 type HBaud int 33 34 type Config struct { 35 HBaud HBaud // Baudrate for packet channel [1200/9600]. 36 SerialBaud int // Baudrate for the serial port. 37 TXDelay time.Duration // Time delay between PTT ON and start of transmission [(0 - 120) * 10ms]. 38 PacketLength uint8 // Maximum length of the data portion of a packet [0 - 255 bytes]. 39 Persist uint8 // Parameter to calculate probability for the PERSIST/SLOTTIME method [0-255]. 40 SlotTime time.Duration // Period of random number generation intervals for the PERSIST/SLOTTIME method [0-255 * 10ms]. 41 MaxFrame uint8 // Maximum number of packets to be transmitted at one time. 42 FRACK time.Duration // Interval from one transmission until retry of transmission [0-250 * 1s]. 43 ResponseTime time.Duration // ACK-packet transmission delay [0-255 * 100ms]. 44 } 45 46 func NewConfig(hbaud HBaud, serialBaud int) Config { 47 switch hbaud { 48 case B1200: 49 return Config{ 50 HBaud: B1200, 51 SerialBaud: serialBaud, 52 TXDelay: 120 * time.Millisecond, 53 PacketLength: 128, 54 Persist: 128, 55 SlotTime: 50 * time.Millisecond, 56 MaxFrame: 6, 57 FRACK: 5 * time.Second, 58 ResponseTime: 100 * time.Millisecond, 59 } 60 case B9600: 61 return Config{ 62 HBaud: B9600, 63 SerialBaud: serialBaud, 64 TXDelay: 100 * time.Millisecond, 65 PacketLength: 255, 66 Persist: 190, 67 SlotTime: 50 * time.Millisecond, 68 MaxFrame: 6, // Everything but 1 is outside range on TH-D72 69 FRACK: 5 * time.Second, 70 ResponseTime: 0 * time.Millisecond, 71 } 72 } 73 return Config{} 74 } 75 76 // TODO:review and improve 77 func tncAddrFromString(str string) tncAddr { 78 parts := strings.Split(str, " ") 79 addr := tncAddr{ 80 address: AddressFromString(parts[0]), 81 digis: make([]Address, 0), 82 } 83 if len(parts) < 3 || !(parts[1] == "via" || parts[1] == "v") { 84 return addr 85 } 86 parts = parts[2:] 87 88 // Parse digis 89 for _, dpart := range parts { 90 addr.digis = append(addr.digis, AddressFromString(dpart)) 91 } 92 return addr 93 }