cwc

package
v0.0.0-...-f26e4ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2019 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Copyright (C) 2019 Graeme Sutherland, Nodestone Limited

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Copyright (C) 2019 Andrew Amos Copyright (C) 2019 Graeme Sutherland, Nodestone Limited

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

------------------------------------------------------------------------ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. ------------------------------------------------------------------------

07 July 2019, Andrew Amos M0VVA, modified original c code to fit go syntax

and leveraged CWC protocol for sending rather than GPIO pins

Adapted from https://github.com/n1gp/iambic-keyer/blob/master/iambic.c

Copywrite (C) Phil Harman VK6PH May 2014 ---------------------------------------------------------------------------------

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	CHECK       int = 0
	PREDOT      int = 1
	PREDASH     int = 2
	SENDDOT     int = 3
	SENDDASH    int = 4
	DOTDELAY    int = 5
	DASHDELAY   int = 6
	DOTHELD     int = 7
	DASHHELD    int = 8
	LETTERSPACE int = 9
	EXITLOOP    int = 10
)
View Source
const BreakinTime = time.Duration(100 * Ms)
View Source
const DefaultTickTime = time.Duration(5 * Ms)
View Source
const HWKeyRing = 27
View Source
const HWKeyTip = 17
View Source
const HWLEDSignal = 23
View Source
const HWLEDStatus = 22
View Source
const KeyerTickTime = time.Duration(1 * Ms)
View Source
const Keyin = "keyin"

Config consts

View Source
const Keyout = "keyout"
View Source
const LocalMulticast = "224.0.0.73:%d"
View Source
const MaxEvents = 100
View Source
const MaxSendTimespan = time.Duration(1000 * Ms)
View Source
const Ms = int64(1e6)
View Source
const OnDutyCycle = uint32(1)

PWM settings

View Source
const PWMCycleLength = uint32(32)
View Source
const Pcmout = "pcmout"
View Source
const Sidetonefreq = "sidetonefreq"
View Source
const Us = int64(1000)

Variables

View Source
var LastBit bool = false
View Source
var RxMutex = sync.Mutex{}
View Source
var SendWait = MaxSendTimespan
View Source
var TickTime = DefaultTickTime
View Source
var TxMutex = sync.Mutex{}

Lock for the Morse Transmit Queue

View Source
var TxQueue = make([]Event, 100)

Morse Transmit Queue

Functions

func BuildPayload

func BuildPayload(events []Event) bitoip.CarrierEventPayload

Build a payload (CarrierEventPayload) of on and off events. Called from Flush() to make a packet ready to send.

func CarrierKey

func CarrierKey() bitoip.CarrierKeyType

func ChannelId

func ChannelId() bitoip.ChannelIdType

func QueueForTransmit

func QueueForTransmit(carrierEvents *bitoip.CarrierEventPayload)

Queue this stuff for sending to hardware -- LED or relay or PWM by adding to queue that will be sent out based on the tick timing

func RunMorseRx

func RunMorseRx(ctx context.Context, morseIO IO, toSend chan bitoip.CarrierEventPayload, echo bool,
	channel bitoip.ChannelIdType, mode int, speed int, weight int, keyer bool, sidetone bool)

func Sample

func Sample(t time.Time, toSend chan bitoip.CarrierEventPayload, morseIO IO, sidetone bool)

Sample the input pin for the morse key. This is called (currently) every 5ms to look for a change in input pin.

TODO should have some sort of back-off if not used recently for power saving

func SampleKeyer

func SampleKeyer(t time.Time, toSend chan bitoip.CarrierEventPayload, morseIO IO)

func SetCarrierKey

func SetCarrierKey(ck bitoip.CarrierKeyType)

func SetChannelId

func SetChannelId(cId bitoip.ChannelIdType)

func SetKeyMode

func SetKeyMode(m int)

func SetKeyerOut

func SetKeyerOut(state int, t time.Time, toSend chan bitoip.CarrierEventPayload, morseIO IO)

func SetKeyerSpacing

func SetKeyerSpacing(s bool)

func SetRoundTrip

func SetRoundTrip(t int64)

func SetSendWait

func SetSendWait(sw time.Duration)

func SetTickTime

func SetTickTime(tt time.Duration)

func SetTimeOffset

func SetTimeOffset(t int64)

func Startup

func Startup(morseIO IO)

func StationClient

func StationClient(ctx context.Context, config *Config, morseIO IO)

General station client Can be in local mode, in which case all is local muticast on the local network Else the client of a reflector

func Stop

func Stop(morseIO IO)

func TransmitToHardware

func TransmitToHardware(t time.Time, morseIO IO)

When woken up (same timer as checking for an incoming bit change) check to see if an output state change is needed and do it.

Types

type Config

type Config struct {
	NetworkMode       string
	ReflectorAddress  string
	LocalPort         int
	HardwareType      string // GPIO or Serial or None
	SerialDevice      string // unix device or COM port
	KeyType           string // straight or paddle or bug -- only straight curently supported
	SidetoneEnable    bool
	SidetoneFrequency int
	RemoteEcho        bool
	Channel           bitoip.ChannelIdType
	Callsign          string
	GPIOPins          GPIOPins
	SerialPins        SerialPins
	KeyerSpeed        int
	KeyerWeight       int
	KeyerMode         int
}

func ReadConfig

func ReadConfig(filename string) *Config

type ConfigMap

type ConfigMap map[string]string

type Event

type Event struct {
	// contains filtered or unexported fields
}

func Flush

func Flush(events []Event, toSend chan bitoip.CarrierEventPayload) []Event

Flush events and place in the toSend channel to wake up the UDP sender to transmit the packet.

type GPIOPins

type GPIOPins struct {
	KeyLeft   int
	KeyRight  int
	PWMA      int
	PWMB      int
	KeyOut    int
	StatusLED int
	SignalLED int
}

type IO

type IO interface {
	Open() error
	Bit() bool
	Dot() bool
	Dash() bool
	SetBit(bool)
	SetToneOut(bool)
	SetStatusLED(bool)
	Close()
}

type Keyer

type Keyer struct {
	// contains filtered or unexported fields
}

func NewKeyer

func NewKeyer(config *Config) *Keyer

func (*Keyer) Bit

func (g *Keyer) Bit() bool

func (*Keyer) Close

func (g *Keyer) Close()

Close the interface

func (*Keyer) Dash

func (g *Keyer) Dash() bool

ready Morse In hardware

func (*Keyer) Dot

func (g *Keyer) Dot() bool

ready Morse In hardware

func (*Keyer) Open

func (g *Keyer) Open() error

Set up inputs and outputs

func (*Keyer) SetBit

func (g *Keyer) SetBit(bit0 bool)

Set Morse Out hardware

func (*Keyer) SetStatusLED

func (g *Keyer) SetStatusLED(s bool)

func (*Keyer) SetToneOut

func (g *Keyer) SetToneOut(v bool)

Set PWM on/off

type NullIO

type NullIO struct {
	// contains filtered or unexported fields
}

func NewNullIO

func NewNullIO(config *Config) *NullIO

func (*NullIO) Bit

func (n *NullIO) Bit() bool

func (*NullIO) Close

func (*NullIO) Close()

func (*NullIO) Config

func (n *NullIO) Config() *Config

func (*NullIO) Dash

func (n *NullIO) Dash() bool

func (*NullIO) Dot

func (n *NullIO) Dot() bool

func (*NullIO) Open

func (n *NullIO) Open() error

func (*NullIO) SetBit

func (n *NullIO) SetBit(b bool)

func (*NullIO) SetState

func (n *NullIO) SetState(state State)

func (*NullIO) SetStatusLED

func (n *NullIO) SetStatusLED(s bool)

func (*NullIO) SetToneOut

func (n *NullIO) SetToneOut(b bool)

func (*NullIO) State

func (n *NullIO) State() State

type PiGPIO

type PiGPIO struct {
	// contains filtered or unexported fields
}

func NewPiGPIO

func NewPiGPIO(config *Config) *PiGPIO

func (*PiGPIO) Bit

func (g *PiGPIO) Bit() bool

ready Morse In hardware

func (*PiGPIO) Close

func (g *PiGPIO) Close()

Close the interface

func (*PiGPIO) Dash

func (g *PiGPIO) Dash() bool

func (*PiGPIO) Dot

func (g *PiGPIO) Dot() bool

func (*PiGPIO) Open

func (g *PiGPIO) Open() error

Set up inputs and outputs

func (*PiGPIO) SetBit

func (g *PiGPIO) SetBit(bit0 bool)

Set Morse Out hardware

func (*PiGPIO) SetStatusLED

func (g *PiGPIO) SetStatusLED(s bool)

func (*PiGPIO) SetToneOut

func (g *PiGPIO) SetToneOut(v bool)

Set PWM on/off

type SerialIO

type SerialIO struct {
	// contains filtered or unexported fields
}

func NewSerialIO

func NewSerialIO(config *Config) *SerialIO

Create this hardare device

func (*SerialIO) Bit

func (s *SerialIO) Bit() bool

Read a morse input bit

func (*SerialIO) Close

func (s *SerialIO) Close()

func (*SerialIO) Dash

func (s *SerialIO) Dash() bool

func (*SerialIO) Dot

func (s *SerialIO) Dot() bool

func (*SerialIO) Open

func (s *SerialIO) Open() error

Open the port and set bit behaviours

func (*SerialIO) SetBit

func (s *SerialIO) SetBit(bit bool)

Send a morse output bit

func (*SerialIO) SetStatusLED

func (s *SerialIO) SetStatusLED(_ bool)

func (*SerialIO) SetToneOut

func (s *SerialIO) SetToneOut(_ bool)

No tone sending supported, so this does nothing

type SerialPins

type SerialPins struct {
	KeyIn  string
	KeyOut string
}

type State

type State struct {
	Bitin   bool
	Bitout  bool
	Toneout bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL