mirror of
https://github.com/tjboldt/Apple2-IO-RPi.git
synced 2024-05-28 09:41:30 +00:00
Add input to commands
This commit is contained in:
parent
a26b374ea5
commit
8d6cbd2043
Binary file not shown.
|
@ -27,6 +27,9 @@ MenuCommand = $08
|
||||||
|
|
||||||
InputString = $fd67
|
InputString = $fd67
|
||||||
PrintChar = $fded
|
PrintChar = $fded
|
||||||
|
Keyboard = $c000
|
||||||
|
ClearKeyboard = $c010
|
||||||
|
Wait = $fca8
|
||||||
|
|
||||||
.org SLOT*$100 + $C000
|
.org SLOT*$100 + $C000
|
||||||
;ID bytes for booting and drive detection
|
;ID bytes for booting and drive detection
|
||||||
|
@ -79,6 +82,7 @@ GetCommand:
|
||||||
bcc GetCommand
|
bcc GetCommand
|
||||||
|
|
||||||
SendCommand:
|
SendCommand:
|
||||||
|
bit ClearKeyboard
|
||||||
lda #$05 ;send command 5 = exec
|
lda #$05 ;send command 5 = exec
|
||||||
jsr SendByte
|
jsr SendByte
|
||||||
ldy #$00
|
ldy #$00
|
||||||
|
@ -98,6 +102,12 @@ DumpOutput:
|
||||||
cmp #$00
|
cmp #$00
|
||||||
beq endOutput
|
beq endOutput
|
||||||
jsr PrintChar
|
jsr PrintChar
|
||||||
|
bit Keyboard ;check for keypress
|
||||||
|
bpl DumpOutput ;keep dumping output if no keypress
|
||||||
|
lda Keyboard ;send keypress to RPi
|
||||||
|
and #$7f
|
||||||
|
jsr SendByte
|
||||||
|
bit ClearKeyboard
|
||||||
clc
|
clc
|
||||||
bcc DumpOutput
|
bcc DumpOutput
|
||||||
endOutput:
|
endOutput:
|
||||||
|
@ -132,7 +142,14 @@ GetByte:
|
||||||
waitRead:
|
waitRead:
|
||||||
lda InputFlags
|
lda InputFlags
|
||||||
rol
|
rol
|
||||||
bcs waitRead
|
bcc readByte
|
||||||
|
bit Keyboard ;keypress will abort waiting to read
|
||||||
|
bpl waitRead
|
||||||
|
lda #$1f ;set all flags high and exit
|
||||||
|
sta OutputFlags
|
||||||
|
lda #$ff
|
||||||
|
rts
|
||||||
|
readByte:
|
||||||
lda InputByte
|
lda InputByte
|
||||||
pha
|
pha
|
||||||
lda #$1f ;set all flags high
|
lda #$1f ;set all flags high
|
||||||
|
|
|
@ -31,6 +31,9 @@ Current file: CommandFirmware.asm
|
||||||
000000r 1
|
000000r 1
|
||||||
000000r 1 InputString = $fd67
|
000000r 1 InputString = $fd67
|
||||||
000000r 1 PrintChar = $fded
|
000000r 1 PrintChar = $fded
|
||||||
|
000000r 1 Keyboard = $c000
|
||||||
|
000000r 1 ClearKeyboard = $c010
|
||||||
|
000000r 1 Wait = $fca8
|
||||||
000000r 1
|
000000r 1
|
||||||
000000r 1 .org SLOT*$100 + $C000
|
000000r 1 .org SLOT*$100 + $C000
|
||||||
00C700 1 ;ID bytes for booting and drive detection
|
00C700 1 ;ID bytes for booting and drive detection
|
||||||
|
@ -56,18 +59,18 @@ Current file: CommandFirmware.asm
|
||||||
00C719 1 Start:
|
00C719 1 Start:
|
||||||
00C719 1 20 00 C3 jsr $c300 ;enable 80 columns
|
00C719 1 20 00 C3 jsr $c300 ;enable 80 columns
|
||||||
00C71C 1 A9 05 lda #$05 ;execute command
|
00C71C 1 A9 05 lda #$05 ;execute command
|
||||||
00C71E 1 20 7D C7 jsr SendByte
|
00C71E 1 20 90 C7 jsr SendByte
|
||||||
00C721 1 A0 00 ldy #$00
|
00C721 1 A0 00 ldy #$00
|
||||||
00C723 1 sendHelp:
|
00C723 1 sendHelp:
|
||||||
00C723 1 B9 76 C7 lda HelpCommand,y
|
00C723 1 B9 89 C7 lda HelpCommand,y
|
||||||
00C726 1 F0 06 beq endSendHelp
|
00C726 1 F0 06 beq endSendHelp
|
||||||
00C728 1 20 7D C7 jsr SendByte
|
00C728 1 20 90 C7 jsr SendByte
|
||||||
00C72B 1 C8 iny
|
00C72B 1 C8 iny
|
||||||
00C72C 1 D0 F5 bne sendHelp
|
00C72C 1 D0 F5 bne sendHelp
|
||||||
00C72E 1 endSendHelp:
|
00C72E 1 endSendHelp:
|
||||||
00C72E 1 A9 00 lda #$00
|
00C72E 1 A9 00 lda #$00
|
||||||
00C730 1 20 7D C7 jsr SendByte
|
00C730 1 20 90 C7 jsr SendByte
|
||||||
00C733 1 20 68 C7 jsr DumpOutput
|
00C733 1 20 6B C7 jsr DumpOutput
|
||||||
00C736 1
|
00C736 1
|
||||||
00C736 1 A5 33 lda $33
|
00C736 1 A5 33 lda $33
|
||||||
00C738 1 48 pha
|
00C738 1 48 pha
|
||||||
|
@ -83,82 +86,88 @@ Current file: CommandFirmware.asm
|
||||||
00C74B 1 90 F0 bcc GetCommand
|
00C74B 1 90 F0 bcc GetCommand
|
||||||
00C74D 1
|
00C74D 1
|
||||||
00C74D 1 SendCommand:
|
00C74D 1 SendCommand:
|
||||||
00C74D 1 A9 05 lda #$05 ;send command 5 = exec
|
00C74D 1 2C 10 C0 bit ClearKeyboard
|
||||||
00C74F 1 20 7D C7 jsr SendByte
|
00C750 1 A9 05 lda #$05 ;send command 5 = exec
|
||||||
00C752 1 A0 00 ldy #$00
|
00C752 1 20 90 C7 jsr SendByte
|
||||||
00C754 1 getInput:
|
00C755 1 A0 00 ldy #$00
|
||||||
00C754 1 B9 00 02 lda $0200,y
|
00C757 1 getInput:
|
||||||
00C757 1 C9 8D cmp #$8d
|
00C757 1 B9 00 02 lda $0200,y
|
||||||
00C759 1 F0 08 beq sendNullTerminator
|
00C75A 1 C9 8D cmp #$8d
|
||||||
00C75B 1 29 7F and #$7f
|
00C75C 1 F0 08 beq sendNullTerminator
|
||||||
00C75D 1 20 7D C7 jsr SendByte
|
00C75E 1 29 7F and #$7f
|
||||||
00C760 1 C8 iny
|
00C760 1 20 90 C7 jsr SendByte
|
||||||
00C761 1 D0 F1 bne getInput
|
00C763 1 C8 iny
|
||||||
00C763 1 sendNullTerminator:
|
00C764 1 D0 F1 bne getInput
|
||||||
00C763 1 A9 00 lda #$00
|
00C766 1 sendNullTerminator:
|
||||||
00C765 1 20 7D C7 jsr SendByte
|
00C766 1 A9 00 lda #$00
|
||||||
00C768 1 DumpOutput:
|
00C768 1 20 90 C7 jsr SendByte
|
||||||
00C768 1 20 9B C7 jsr GetByte
|
00C76B 1 DumpOutput:
|
||||||
00C76B 1 C9 00 cmp #$00
|
00C76B 1 20 AE C7 jsr GetByte
|
||||||
00C76D 1 F0 06 beq endOutput
|
00C76E 1 C9 00 cmp #$00
|
||||||
00C76F 1 20 ED FD jsr PrintChar
|
00C770 1 F0 16 beq endOutput
|
||||||
00C772 1 18 clc
|
00C772 1 20 ED FD jsr PrintChar
|
||||||
00C773 1 90 F3 bcc DumpOutput
|
00C775 1 2C 00 C0 bit Keyboard ;check for keypress
|
||||||
00C775 1 endOutput:
|
00C778 1 10 F1 bpl DumpOutput ;keep dumping output if no keypress
|
||||||
00C775 1 60 rts
|
00C77A 1 AD 00 C0 lda Keyboard ;send keypress to RPi
|
||||||
00C776 1
|
00C77D 1 29 7F and #$7f
|
||||||
00C776 1 HelpCommand:
|
00C77F 1 20 90 C7 jsr SendByte
|
||||||
00C776 1 61 32 68 65 .byte "a2help",$00
|
00C782 1 2C 10 C0 bit ClearKeyboard
|
||||||
00C77A 1 6C 70 00
|
00C785 1 18 clc
|
||||||
00C77D 1
|
00C786 1 90 E3 bcc DumpOutput
|
||||||
00C77D 1 SendByte:
|
00C788 1 endOutput:
|
||||||
00C77D 1 48 pha
|
00C788 1 60 rts
|
||||||
00C77E 1 waitWrite:
|
00C789 1
|
||||||
00C77E 1 AD FB C0 lda InputFlags
|
00C789 1 HelpCommand:
|
||||||
00C781 1 2A rol
|
00C789 1 61 32 68 65 .byte "a2help",$00
|
||||||
00C782 1 2A rol
|
00C78D 1 6C 70 00
|
||||||
00C783 1 B0 F9 bcs waitWrite
|
00C790 1
|
||||||
00C785 1 68 pla
|
00C790 1 SendByte:
|
||||||
00C786 1 8D FD C0 sta OutputByte
|
00C790 1 48 pha
|
||||||
00C789 1 A9 1E lda #$1e ; set bit 0 low to indicate write started
|
00C791 1 waitWrite:
|
||||||
00C78B 1 8D F7 C0 sta OutputFlags
|
00C791 1 AD FB C0 lda InputFlags
|
||||||
00C78E 1 finishWrite:
|
00C794 1 2A rol
|
||||||
00C78E 1 AD FB C0 lda InputFlags
|
00C795 1 2A rol
|
||||||
00C791 1 2A rol
|
00C796 1 B0 F9 bcs waitWrite
|
||||||
00C792 1 2A rol
|
00C798 1 68 pla
|
||||||
00C793 1 90 F9 bcc finishWrite
|
00C799 1 8D FD C0 sta OutputByte
|
||||||
00C795 1 A9 1F lda #$1f
|
00C79C 1 A9 1E lda #$1e ; set bit 0 low to indicate write started
|
||||||
00C797 1 8D F7 C0 sta OutputFlags
|
00C79E 1 8D F7 C0 sta OutputFlags
|
||||||
00C79A 1 60 rts
|
00C7A1 1 finishWrite:
|
||||||
00C79B 1
|
00C7A1 1 AD FB C0 lda InputFlags
|
||||||
00C79B 1 GetByte:
|
00C7A4 1 2A rol
|
||||||
00C79B 1 A9 1D lda #$1d ;set read flag low
|
00C7A5 1 2A rol
|
||||||
00C79D 1 8D F7 C0 sta OutputFlags
|
00C7A6 1 90 F9 bcc finishWrite
|
||||||
00C7A0 1 waitRead:
|
00C7A8 1 A9 1F lda #$1f
|
||||||
00C7A0 1 AD FB C0 lda InputFlags
|
00C7AA 1 8D F7 C0 sta OutputFlags
|
||||||
00C7A3 1 2A rol
|
00C7AD 1 60 rts
|
||||||
00C7A4 1 B0 FA bcs waitRead
|
00C7AE 1
|
||||||
00C7A6 1 AD FE C0 lda InputByte
|
00C7AE 1 GetByte:
|
||||||
00C7A9 1 48 pha
|
00C7AE 1 A9 1D lda #$1d ;set read flag low
|
||||||
00C7AA 1 A9 1F lda #$1f ;set all flags high
|
00C7B0 1 8D F7 C0 sta OutputFlags
|
||||||
00C7AC 1 8D F7 C0 sta OutputFlags
|
00C7B3 1 waitRead:
|
||||||
00C7AF 1 finishRead:
|
00C7B3 1 AD FB C0 lda InputFlags
|
||||||
00C7AF 1 AD FB C0 lda InputFlags
|
00C7B6 1 2A rol
|
||||||
00C7B2 1 2A rol
|
00C7B7 1 90 0D bcc readByte
|
||||||
00C7B3 1 90 FA bcc finishRead
|
00C7B9 1 2C 00 C0 bit Keyboard ;keypress will abort waiting to read
|
||||||
00C7B5 1 68 pla
|
00C7BC 1 10 F5 bpl waitRead
|
||||||
00C7B6 1 end:
|
00C7BE 1 A9 1F lda #$1f ;set all flags high and exit
|
||||||
00C7B6 1 60 rts
|
00C7C0 1 8D F7 C0 sta OutputFlags
|
||||||
00C7B7 1
|
00C7C3 1 A9 FF lda #$ff
|
||||||
00C7B7 1 00 00 00 00 .repeat 251-<end
|
00C7C5 1 60 rts
|
||||||
00C7BB 1 00 00 00 00
|
00C7C6 1 readByte:
|
||||||
00C7BF 1 00 00 00 00
|
00C7C6 1 AD FE C0 lda InputByte
|
||||||
00C7C3 1 00 00 00 00
|
00C7C9 1 48 pha
|
||||||
00C7C7 1 00 00 00 00
|
00C7CA 1 A9 1F lda #$1f ;set all flags high
|
||||||
00C7CB 1 00 00 00 00
|
00C7CC 1 8D F7 C0 sta OutputFlags
|
||||||
00C7CF 1 00 00 00 00
|
00C7CF 1 finishRead:
|
||||||
00C7D3 1 00 00 00 00
|
00C7CF 1 AD FB C0 lda InputFlags
|
||||||
00C7D7 1 00 00 00 00
|
00C7D2 1 2A rol
|
||||||
|
00C7D3 1 90 FA bcc finishRead
|
||||||
|
00C7D5 1 68 pla
|
||||||
|
00C7D6 1 end:
|
||||||
|
00C7D6 1 60 rts
|
||||||
|
00C7D7 1
|
||||||
|
00C7D7 1 00 00 00 00 .repeat 251-<end
|
||||||
00C7DB 1 00 00 00 00
|
00C7DB 1 00 00 00 00
|
||||||
00C7DF 1 00 00 00 00
|
00C7DF 1 00 00 00 00
|
||||||
00C7E3 1 00 00 00 00
|
00C7E3 1 00 00 00 00
|
||||||
|
|
Binary file not shown.
|
@ -81,7 +81,7 @@ func InitGpio() {
|
||||||
out_bit1.Out(gpio.Low)
|
out_bit1.Out(gpio.Low)
|
||||||
out_bit0.Out(gpio.Low)
|
out_bit0.Out(gpio.Low)
|
||||||
|
|
||||||
edgeTimeout = time.Second * 5
|
edgeTimeout = time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadString() (string, error) {
|
func ReadString() (string, error) {
|
||||||
|
@ -176,9 +176,16 @@ func ReadByte() (byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteByte(data byte) error {
|
func WriteByte(data byte) error {
|
||||||
|
// check if the Apple II wants to send a byte to us first
|
||||||
|
if in_write.Read() == gpio.Low {
|
||||||
|
out_write.Out(gpio.High)
|
||||||
|
return errors.New("Can't write byte while byte is incoming")
|
||||||
|
}
|
||||||
|
|
||||||
// wait for the Apple II to be ready to read
|
// wait for the Apple II to be ready to read
|
||||||
for in_read.Read() == gpio.High {
|
for in_read.Read() == gpio.High {
|
||||||
if !in_read.WaitForEdge(edgeTimeout) {
|
if !in_read.WaitForEdge(edgeTimeout) {
|
||||||
|
out_write.Out(gpio.High)
|
||||||
return errors.New("Timed out writing byte -- read stuck high")
|
return errors.New("Timed out writing byte -- read stuck high")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"bufio"
|
|
||||||
|
|
||||||
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
"github.com/tjboldt/Apple2-IO-RPi/RaspberryPi/apple2driver/a2io"
|
||||||
)
|
)
|
||||||
|
@ -36,53 +37,34 @@ func ExecCommand() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if linuxCommand == "a2help" {
|
if linuxCommand == "a2help" {
|
||||||
a2io.WriteString("\r" +
|
a2help()
|
||||||
"This is a pseudo shell. Each command is executed as a process. The cd command\r" +
|
|
||||||
"is intercepted and sets the working directory for the next command. Running\r" +
|
|
||||||
"commands that do not exit on their own will not be able to be cancelled\r" +
|
|
||||||
"without resetting the Apple II. For example, do not use ping without a way to\r" +
|
|
||||||
"limit output like -c 1.\r" +
|
|
||||||
"\r" +
|
|
||||||
"Built-in commands:\r" +
|
|
||||||
"a2help - display this message\r" +
|
|
||||||
"a2wifi - set up wifi\r" +
|
|
||||||
"A2LOWER - force lowercase for II+\r" +
|
|
||||||
"\r")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if linuxCommand == "A2LOWER" {
|
if linuxCommand == "A2LOWER" {
|
||||||
forceLowercase = true
|
a2lower()
|
||||||
a2io.WriteString("All commands will be converted to lowercase\r")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if linuxCommand == "a2wifi" {
|
if linuxCommand == "a2wifi" {
|
||||||
a2io.WriteString("\r" +
|
a2wifi()
|
||||||
"Usage: a2wifi list\r" +
|
|
||||||
" a2wifi select SSID PASSWORD\r" +
|
|
||||||
"\r")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if linuxCommand == "a2wifi list" {
|
if linuxCommand == "a2wifi list" {
|
||||||
linuxCommand = "sudo iwlist wlan0 scanning | grep ESSID | sed s/.*ESSID://g | sed s/\\\"//g"
|
linuxCommand = a2wifiList()
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(linuxCommand, "a2wifi select") {
|
if strings.HasPrefix(linuxCommand, "a2wifi select") {
|
||||||
params := strings.Fields(linuxCommand)
|
linuxCommand, err = a2wifiSelect(linuxCommand)
|
||||||
if len(params) != 4 {
|
|
||||||
a2io.WriteString("\rIncorrect number of parameters. Usage: a2wifi select SSID PASSWORD\r\r")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ssid := params[2]
|
|
||||||
psk := params[3]
|
|
||||||
linuxCommand = "printf \"country=ca\\nupdate_config=1\\nctrl_interface=/var/run/wpa_supplicant\\n\\nnetwork={\\n scan_ssid=1\\n ssid=\\\"%s\\\"\n psk=\\\"%s\\\"\\n}\\n\" " +
|
|
||||||
ssid + " " +
|
|
||||||
psk + " " +
|
|
||||||
" > /tmp/wpa_supplicant.conf; " +
|
|
||||||
"sudo mv /tmp/wpa_supplicant.conf /etc/wpa_supplicant/; " +
|
|
||||||
"sudo wpa_cli -i wlan0 reconfigure"
|
|
||||||
}
|
}
|
||||||
|
if err == nil {
|
||||||
|
execCommand(linuxCommand, workingDirectory)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func execCommand(linuxCommand string, workingDirectory string) {
|
||||||
cmd := exec.Command("bash", "-c", linuxCommand)
|
cmd := exec.Command("bash", "-c", linuxCommand)
|
||||||
cmd.Dir = workingDirectory
|
cmd.Dir = workingDirectory
|
||||||
stdout, err := cmd.StdoutPipe()
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
stdin, err := cmd.StdinPipe()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to set stdout\n")
|
fmt.Printf("Failed to set stdout\n")
|
||||||
a2io.WriteString("Failed to set stdout\r")
|
a2io.WriteString("Failed to set stdout\r")
|
||||||
|
@ -96,26 +78,127 @@ func ExecCommand() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := bufio.NewReader(stdout)
|
outputComplete := make(chan bool)
|
||||||
|
inputComplete := make(chan bool)
|
||||||
|
userCancelled := make(chan bool)
|
||||||
|
|
||||||
for err == nil {
|
if linuxCommand == "openssl" {
|
||||||
var b byte
|
fmt.Printf("\nSending help command...\n")
|
||||||
b, err = reader.ReadByte()
|
io.WriteString(stdin, "help\n")
|
||||||
if err == nil {
|
}
|
||||||
|
|
||||||
|
go getStdin(stdin, outputComplete, inputComplete, userCancelled)
|
||||||
|
go getStdout(stdout, outputComplete, userCancelled)
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-outputComplete:
|
||||||
|
outputComplete <- true
|
||||||
|
case <-userCancelled:
|
||||||
|
a2io.WriteString("^C\r")
|
||||||
|
cmd.Process.Kill()
|
||||||
|
return
|
||||||
|
case <-inputComplete:
|
||||||
|
cmd.Wait()
|
||||||
|
a2io.WriteByte(0)
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getStdout(stdout io.ReadCloser, done chan bool, userCancelled chan bool) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-userCancelled:
|
||||||
|
stdout.Close()
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
bb := make([]byte, 1)
|
||||||
|
n, err := stdout.Read(bb)
|
||||||
|
if err != nil || n == 0 {
|
||||||
|
stdout.Close()
|
||||||
|
done <- true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b := bb[0]
|
||||||
fmt.Print(string(b))
|
fmt.Print(string(b))
|
||||||
if b == 10 { // convert LF to CR for Apple II compatiblity
|
if b == 10 { // convert LF to CR for Apple II compatiblity
|
||||||
b = 13
|
b = 13
|
||||||
}
|
}
|
||||||
b |= 128
|
b |= 128
|
||||||
err = a2io.WriteByte(b)
|
a2io.WriteByte(b)
|
||||||
if err != nil {
|
}
|
||||||
fmt.Printf("\nFailed to write byte\n")
|
}
|
||||||
cmd.Process.Kill()
|
}
|
||||||
return
|
|
||||||
|
func getStdin(stdin io.WriteCloser, done chan bool, inputComplete chan bool, userCancelled chan bool) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
stdin.Close()
|
||||||
|
inputComplete <- true
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
b, err := a2io.ReadByte()
|
||||||
|
if err == nil {
|
||||||
|
if b == 3 {
|
||||||
|
stdin.Close()
|
||||||
|
userCancelled <- true
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
if b == 13 {
|
||||||
|
b = 10
|
||||||
|
}
|
||||||
|
fmt.Printf("%c", b)
|
||||||
|
io.WriteString(stdin, string(b))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
cmd.Wait()
|
|
||||||
a2io.WriteByte(0)
|
func a2help() {
|
||||||
|
a2io.WriteString("\r" +
|
||||||
|
"This is a pseudo shell. Each command is executed as a process. The cd command\r" +
|
||||||
|
"is intercepted and sets the working directory for the next command.\r" +
|
||||||
|
"\r" +
|
||||||
|
"Built-in commands:\r" +
|
||||||
|
"a2help - display this message\r" +
|
||||||
|
"a2wifi - set up wifi\r" +
|
||||||
|
"A2LOWER - force lowercase for II+\r" +
|
||||||
|
"\r")
|
||||||
|
}
|
||||||
|
|
||||||
|
func a2lower() {
|
||||||
|
forceLowercase = true
|
||||||
|
a2io.WriteString("All commands will be converted to lowercase\r")
|
||||||
|
}
|
||||||
|
|
||||||
|
func a2wifi() {
|
||||||
|
a2io.WriteString("\r" +
|
||||||
|
"Usage: a2wifi list\r" +
|
||||||
|
" a2wifi select SSID PASSWORD\r" +
|
||||||
|
"\r")
|
||||||
|
}
|
||||||
|
|
||||||
|
func a2wifiList() string {
|
||||||
|
return "sudo iwlist wlan0 scanning | grep ESSID | sed s/.*ESSID://g | sed s/\\\"//g"
|
||||||
|
}
|
||||||
|
|
||||||
|
func a2wifiSelect(linuxCommand string) (string, error) {
|
||||||
|
params := strings.Fields(linuxCommand)
|
||||||
|
if len(params) != 4 {
|
||||||
|
a2io.WriteString("\rIncorrect number of parameters. Usage: a2wifi select SSID PASSWORD\r\r")
|
||||||
|
return "", errors.New("Incorrect number of parameters. Usage: a2wifi select SSID PASSWORD")
|
||||||
|
}
|
||||||
|
ssid := params[2]
|
||||||
|
psk := params[3]
|
||||||
|
linuxCommand = "printf \"country=ca\\nupdate_config=1\\nctrl_interface=/var/run/wpa_supplicant\\n\\nnetwork={\\n scan_ssid=1\\n ssid=\\\"%s\\\"\n psk=\\\"%s\\\"\\n}\\n\" " +
|
||||||
|
ssid + " " +
|
||||||
|
psk + " " +
|
||||||
|
" > /tmp/wpa_supplicant.conf; " +
|
||||||
|
"sudo mv /tmp/wpa_supplicant.conf /etc/wpa_supplicant/; " +
|
||||||
|
"sudo wpa_cli -i wlan0 reconfigure"
|
||||||
|
return linuxCommand, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user