harenber / ptc-go

A driver for SCS PACTOR modems for Pat
MIT License
8 stars 2 forks source link

Enable connect from HF #7

Open harenber opened 6 years ago

harenber commented 6 years ago

Do not require a connect to a outside station, enable "HF listen mode".

harenber commented 6 years ago

Check https://github.com/la5nta/pat/blob/master/listen.go for what needs to be implemented.

martinhpedersen commented 4 years ago

Just some thoughts/ideas to get you started..

You'll have to provide a type implementing the net.Listener interface. That's it really :)

However, the public API for ptc-go is a bit strange as it stands right now, since it does not export any functions or types. You should probably make pmodem public (exported) and provide an initializer to connect to the modem.

My advise is to rename the pmodem to Modem or TNC with three exported methods and the initializer:

// OpenModem initializes and opens a serial PTC-I or PTC-II modem 
func OpenModem(path string) (*Modem, error) {}

// DialURL dials the a node returning a net.Conn 
func (m *Modem) DialURL(url *transport.URL) (net.Conn, error) {}

// Listen prepares the modem for incoming connections and returns a net.Listener
func (m *Modem) Listen() (net.Listener, error) {}

// Close closes modem and underlying serial connection 
func (m *Modem) Close() error {}

In addition, you would need the Listener struct implementing the net.Listener interface.

Pat can register ptc.Modem as a dialer by calling transport.RegisterDialer("pactor", modem) and start the Listener go-routine after successful initialization through func OpenModem(...).

This change implies that the self-registration at pactor.go#L14 would need to be removed.

blockmurder commented 4 years ago

Changes have been made in order to support listen mode. It is still just a template though, the Listen function does not do anything for the moment.

martinhpedersen commented 4 years ago

Yes, the API is really starting to take shape now :)

I have another suggestion: Maybe you could also add a Conn struct to represent a dialed connection? If you move the net.Conn methods (Read, Write, SetDeadline..., Close...) to that struct, I believe the API would be even cleaner and more idiomatic.

type Modem
    func OpenModem(path string, baudRate int, myCall string, initScript string) (p *Modem, err error)
    func (p *Modem) DialURL(url *transport.URL) (net.Conn, error)
    func (p *Modem) Listen() (ln net.Listener, err error)
    func (p *Modem) Close() error // Closes the serial connection to the modem

type Conn
    func (c *Conn) Read(d []byte) (int, error)
    func (c *Conn) Write(d []byte) (int, error)
    func (c *Conn) Close() error // Disconnect (should also flush before disconnect)
    func (c *Conn) SetDeadline(t time.Time) error
    func (c *Conn) SetReadDeadline(t time.Time) error
    func (c *Conn) SetWriteDeadline(t time.Time) error
    func (c *Conn) LocalAddr() net.Addr
    func (c *Conn) RemoteAddr() net.Addr
    func (c *Conn) Flush() (err error)
    func (c *Conn) TxBufferLen() int

What do you think?

martinhpedersen commented 4 years ago

... and when I say you I really mean we. I can of course help out when I have the time :)

blockmurder commented 4 years ago

I'll give it a try for v2.1. Would you mind giving me a hint/example how type Conn should look like?

martinhpedersen commented 4 years ago

Sure! I'll come back to you with an example when I have time :)

harenber commented 2 years ago

https://github.com/harenber/ptc-go/commit/fdf1a4af094899159c77682f5ee98231437d015a has a first (not really tested) version of a version with listen-mode. Development will be in branch feature/listen-mode.

harenber commented 1 year ago

After a long time with no development, I spent the weekend working on this. https://github.com/harenber/ptc-go/commit/e81f76c7bc3364e91e796f5ed4ea2f79dc6255b0 has a working version now which actually does what it should do. But a lot of code cleanup is now needed.