$nocompile
Sub Uart_rx():
Debug off' teraz mam na niestandardowym porcje wiec wyłczone
Reset Watchdog
Print #2 , "jestem w uart_rx"' debug mam na nie standardowym porcje
Lcount = Split(uart_command , Getcommands(1) , " ") "Porcjowanie
Debug Chr(13)
Debug "lcount= " ; Lcount
Debug "uart_command= " ; Uart_command
Debug "Getcommands(1)= " ; Getcommands(1)
Debug "Getcommands(2)= " ; Getcommands(2)
Debug "Getcommands(3)= " ; Getcommands(3)
Debug " ";
Rs485_adres_temp = Val(getcommands(1)) 'zamien tekst na numer
Select Case Rs485_adres_temp ' tymczasowy adres do porównania
Case Rs485_adres: 'komenda 1 case 1, sprawdzenie adresu
Print #2 , "odebrlem poprawnie adres "
'Tu kod jakis
Select Case Getcommands(2)
Case G2_c_1: ' jesli odebralem komende druga czyli getcommand(2)
Print #2 , "jestem w command 2, case 1"
Select Case Getcommands(3)
Case G3_c1: 'On
Porta.4 = 1
Case G3_c2: 'Off
Porta.4 = 0
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_2: '
Print #2 , "jestem w command 2, case 2 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Porta.5 = 1
Case G3_c2: 'Off
Porta.5 = 0
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_3: '
Print #2 , "jestem w command 2, case 3 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Porta.6 = 1
Case G3_c2: 'Off
Porta.6 = 0
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_4: 'High Current output 4
Print #2 , "jestem w command 2, case 4 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Porta.7 = 1
Case G3_c2: 'Off
Porta.7 = 0
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_5: 'o5 RS485 BUS power
Print #2 , "jestem w command 2, case 5 " '
Select Case Getcommands(3)
Case G3_c1:
Portb.0 = 0 'On
Case G3_c2: 'Off
Portb.0 = 1
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
Case Else: 'anything else
End Select
Case G2_c_6: ' low current output 6
Print #2 , "jestem w command 2, case 6 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Portb.1 = 0
Case G3_c2: 'Off
Portb.1 = 1
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_7: 'output 7
Print #2 , "jestem w command 2, case 7 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Portb.2 = 0
Case G3_c2: 'Off
Portb.2 = 1
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_8: 'output 8
Print #2 , "jestem w command 2, case 8 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Portb.3 = 0
Case G3_c2: 'Off
Portb.3 = 1
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_9: 'ooutput 9
Print #2 , "jestem w command 2, case 9 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Portb.4 = 0
Case G3_c2: 'Off
Portb.4 = 1
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case G2_c_10: 'all outputs off
Print #2 , "jestem w command 2, case 10 " '
Select Case Getcommands(3)
Case G3_c1: 'On
Porta.3 = 1
Porta.4 = 1
Porta.5 = 1
Porta.6 = 1
Portb.0 = 0 'RS485
Portb.1 = 0 'low current output
Portb.2 = 0 'low current output
Portb.3 = 0 'low current output
Portb.4 = 0 'low current output
Case G3_c2: 'Off
Porta.3 = 0
Porta.4 = 0
Porta.5 = 0
Porta.6 = 0
Portb.0 = 1 'RS485
Portb.1 = 1 'low current output
Portb.2 = 1 'low current output
Portb.3 = 1 'low current output
Portb.4 = 1 'low current output
Case Else: 'anything else
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Case Rs485_term_off:
Print #2 , "jestem w command 2, case RS_term off " '
Portc.5 = 0 'terminacja wylaczona
Rs485_term = 0
Rs485_term_ee = Rs485_term
Print Chr(6); 'send ACK
Case Rs485_term_on:
Print #2 , "jestem w command 2, case RS_term_on " '
Portc.5 = 1 'terminacja wlaczona
Rs485_term = 1
Rs485_term_ee = Rs485_term
Print Chr(6); 'send ACK
Case G2_c_10: ' address space number
Print #2 , "jestem w command 2, case 10 " 'ustaw adres
'Print "Input new address(1-254): "
Rs485_adres = Val(getcommands(3))
Rs485_adres_ee = Rs485_adres
Print Chr(6); 'send ACK
Case G2_c_11: 'da?
Print #2 , "jestem w command 2, case 11 " 'ustaw defaultowa antenne
Def_out = Def_out_ee ' read from EEPROM default antenna
Print "default antenna:" ; Def_out
Case G2_c_12:
Print #2 , "jestem w command 2, case 11 " 'ustaw defaultowa antenne
'Print "Input new default antenna (0-4): "
Def_out = Val(getcommands(3))
Def_out_ee = Def_out ' write to EEPROM default antenna
Print #2 , Chr(6); ' send ACK
Case Reboot:
'zrestartój system
Print #2 , "Switch:" ; Rs485_adres
Print #2 , "Device will now reboot"
'Start Watchdog
Do
Loop
Case Firmware_version:
Print #2 , "Switch:" ; Rs485_adres
Print #2 , "Version:" ; Version(2)
Case Bootloader: 'load
Debug "jestem w command 1, reboot "
Disable Interrupts
'Config Watchdog = 16
'Start Watchdog
'Stop Timer1
'Informacja dla mnie bo zapomne :)
' Ustaw fusy booltlaoder na 1024 adres &H3C00
' w oknie bootloadera dodaj adres i komende:
' 1 load {13}
Do
Loop
Case Help : '?
Print #2 , "Power distributor EI9HEB/SP9DR"
Print #2 , "EI9SP Sierra Papa DX Group"
Print #2 , "Version:" ; Version(2)
Print #2 , "RS_485 Adres:" ; Rs485_adres
Print #2 , "RS485, 120 Ohm, BUS Termination:";
If Portc.5 = 1 Then
Print #2 , "Enabled"
Else
Print #2 , "Disabled"
End If
Print #2 , "Command example:"
Print #2 , "(address)_(o)(number)_(on/off)"
Print #2 , "Default output:" ; Def_out
Print #2 , "o?------------Get active output"
Print #2 , "o1------------Output 1"
Print #2 , "o2------------Output 2"
Print #2 , "o3------------Output 3"
Print #2 , "o4------------Output 4"
Print #2 , "o5------------BUS Power"
Print #2 , "o6------------Output 6"
Print #2 , "o7------------Output 7"
Print #2 , "o8------------Output 8"
Print #2 , "o9------------Output 9"
Print #2 , "all-----------All outputs"
Print #2 , "address-(0-254)------Set new rs485 address"
Print #2 , "do?-----------Get default output"
Print #2 , "do (number)---Set default output"
Print #2 , "rs_term_on----BUS Termination Enabled"
Print #2 , "rs_term_off---BUS Termination Disabled"
Print #2 , "reboot -------System Restart"
Print #2 , "fw?-----------Get firmware version"
'Print "sn?-----------Get serial number"
'Print #2 , "load----------Firmware update"
Print #2 , "?-------------Get command list"
Case Else:
'ponizej NIE USUWAJ TO JEST WAZNE!
'jak komenda nie rozpoznana zrób to
'Print Prompt ; " " ; Uart_command ; " " ; Notincommands
'Print Prompt
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
'ponizej NIE USUWAJ TO JEST WAZNE!
'jak komenda nei rozpoznana zrób to
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
Case Broadcast: '255 broadcast do wszystkich
Debug "odebrlem poprawnie adres "
'stop timer1 ' stop timer used to blink the green led
Flag1.0 = 1
'Portd.4 = 0 ' turn off green led
Porta.3 = 1 ' ready to print
'Portd.4 = 1 ' turn on the green led
Select Case Getcommands(2)
Case Reboot:
Print #2 , "Device address:" ; Rs485_adres ; " will now reboot"
'Start Watchdog
Case Help : '?
Print #2 , "Power Distributor by EI9HEB/SP9DR"
Print #2 , "Version:" ; Version(2)
Print #2 , "RS_485 Address:" ; Rs485_adres
Print #2 , "RS485, 120 Ohm, BUS Termination:";
If Porta.3 = 1 Then
Print #2 , "Enabled"
Else
Print #2 , "Disabled"
End If
Print #2 , "RS_485 Addres:" ; Rs485_adres
Print #2 , "Default output port:" ; Def_out
Print #2 , Chr(10) ; "----Command list:---"
Print #2 , "o?------------Get active output number"
Print #2 , "o0------------All off"
Print #2 , "o1------------Output 1"
Print #2 , "o2------------Output 2"
Print #2 , "o3------------Output 3"
Print #2 , "o4------------Output 4"
Print #2 , "o5------------BUS Power"
Print #2 , "o6------------Output 6"
Print #2 , "o7------------Output 7"
Print #2 , "o8------------Output 8"
Print #2 , "o9------------Output 9"
Print #2 , "all-----------All ON!"
Print #2 , "address-(0-254)------Set new rs485 address"
Print #2 , "do?-----------Get Default antenna port"
Print #2 , "do (number)---Set Default antenna port"
Print #2 , "rs_term_on----BUS Termination Enabled"
Print #2 , "rs_term_off---BUS Termination Disabled"
Print #2 , "reboot -------System Restart"
Print #2 , "load----------Firmware update"
Print #2 , "?-------------Get command list"
Case G2_c_5: 'all off
Debug "jestem w command 2, case 5" '
Ant_flag = 0
'Case Bootloader: 'load
'Debug "jestem w command 1, reboot "
'Disable Interrupts
'Config Watchdog = 16
'Start Watchdog
'Stop Timer1
'Informacja dla mnie bo zapomne :)
' Ustaw fusy bootlaoder na 1024 adres &H3C00
' w oknie bootloadera dodaj adres i komende:
' 1 load {13}
'Do
'Loop
Case Else:
'Print Prompt ; " " ; Uart_command ; " " ; Notincommands
'Print Prompt
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
Case Else:
Print #2 , "Routing to port 1"
Print #1 , Getcommands(1) ; Chr(20) ; Getcommands(2) ; Chr(20) ; Getcommands(3) ; Chr(13);
'Case Else
'ponizej NIE USUWAJ TO JEST WAZNE!
'Debug "odebrlem zly adres "
'Print Prompt ; " " ; Uart_command ; " " ; Notincommands
'Print Prompt
'Jelsi zly adres wyczysc wszytkie komorki z odebranymi danymi
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Select
'ponizej NIE USUWAJ TO JEST WAZNE!
'jak komenda nie rozpoznana zrób to
Getcommands(1) = ""
Getcommands(2) = ""
Getcommands(3) = ""
End Sub