|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <time.h> |
|
|
|
|
#include "pico/stdlib.h" |
|
|
|
|
#include "pico/binary_info.h" |
|
|
|
|
#include "LoRa-RP2040.h" |
|
|
|
@ -12,14 +13,24 @@ void getPacketData(int packetLength); |
|
|
|
|
int compare_strings(uint8_t a[], uint8_t b[]); |
|
|
|
|
bool is_message_for_me (uint8_t data[], uint8_t mycall[]); |
|
|
|
|
|
|
|
|
|
/* declaration for receive functions */ |
|
|
|
|
uint16_t decode_packet (); |
|
|
|
|
void ComposeAprsFrame(uint8_t payload[]); |
|
|
|
|
|
|
|
|
|
/* declaration for transmit functions */ |
|
|
|
|
void ComposeAprsFrame(uint8_t payload[]); |
|
|
|
|
bool TransmitRequest = false; |
|
|
|
|
void transmit(); |
|
|
|
|
|
|
|
|
|
const uint PowerSupply24VControl = 6; |
|
|
|
|
const uint PowerSupply12VControl = 5; |
|
|
|
|
const uint PowerSupply5VControl = 4; |
|
|
|
|
const uint RelayOffControl = 2; |
|
|
|
|
const uint RelayOnControl = 3; |
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
|
|
|
|
|
|
uint16_t ServerCommand = 0; |
|
|
|
|
uint16_t TxDelay = 0; |
|
|
|
|
|
|
|
|
|
/* Among others, this initializes the USB-serial port at 115200bps 8N1 */ |
|
|
|
|
stdio_init_all(); |
|
|
|
@ -28,6 +39,31 @@ int main() { |
|
|
|
|
memset(rxBuffer, 0, sizeof(rxBuffer)); |
|
|
|
|
memset(txBuffer, 0, sizeof(txBuffer)); |
|
|
|
|
|
|
|
|
|
gpio_init(PowerSupply24VControl); |
|
|
|
|
gpio_init(PowerSupply12VControl); |
|
|
|
|
gpio_init(PowerSupply5VControl); |
|
|
|
|
gpio_init(RelayOffControl); |
|
|
|
|
gpio_init(RelayOnControl); |
|
|
|
|
|
|
|
|
|
gpio_set_dir(PowerSupply24VControl, GPIO_OUT); |
|
|
|
|
gpio_set_dir(PowerSupply12VControl, GPIO_OUT); |
|
|
|
|
gpio_set_dir(PowerSupply5VControl, GPIO_OUT); |
|
|
|
|
gpio_set_dir(RelayOffControl, GPIO_OUT); |
|
|
|
|
gpio_set_dir(RelayOnControl, GPIO_OUT); |
|
|
|
|
|
|
|
|
|
gpio_put(PowerSupply24VControl, 0); |
|
|
|
|
Status.PowerSupply24V = OFF; |
|
|
|
|
gpio_put(PowerSupply12VControl, 0); |
|
|
|
|
Status.PowerSupply12V = OFF; |
|
|
|
|
gpio_put(PowerSupply5VControl, 1); |
|
|
|
|
Status.PowerSupply5V = OFF; |
|
|
|
|
|
|
|
|
|
gpio_put(RelayOffControl, 1); |
|
|
|
|
sleep_ms(250); |
|
|
|
|
gpio_put(RelayOffControl, 0); |
|
|
|
|
gpio_put(RelayOnControl, 0); |
|
|
|
|
Status.ControlRelay = OFF; |
|
|
|
|
|
|
|
|
|
sleep_ms(5000); |
|
|
|
|
|
|
|
|
|
LoadSettings(); |
|
|
|
@ -58,20 +94,101 @@ int main() { |
|
|
|
|
|
|
|
|
|
if (ServerCommand) { |
|
|
|
|
|
|
|
|
|
if (ServerCommand == 1) { |
|
|
|
|
ComposeAprsFrame(AprsSettings.FirmwareVersion); |
|
|
|
|
// Wait for 100ms before responding
|
|
|
|
|
sleep_ms(5000); |
|
|
|
|
transmit(); |
|
|
|
|
sleep_ms(5000); |
|
|
|
|
transmit(); |
|
|
|
|
sleep_ms(5000); |
|
|
|
|
transmit(); |
|
|
|
|
sleep_ms(5000); |
|
|
|
|
transmit(); |
|
|
|
|
switch(ServerCommand) { |
|
|
|
|
|
|
|
|
|
case 1 : |
|
|
|
|
ComposeAprsFrame(AprsSettings.FirmwareVersion); |
|
|
|
|
break; |
|
|
|
|
// Send status of output pins
|
|
|
|
|
case 6 : |
|
|
|
|
if (Status.PowerSupply24V == ON) |
|
|
|
|
Status.StatusString[3] = '1'; |
|
|
|
|
else |
|
|
|
|
Status.StatusString[3] = '0'; |
|
|
|
|
|
|
|
|
|
if (Status.PowerSupply12V == ON) |
|
|
|
|
Status.StatusString[2] = '1'; |
|
|
|
|
else |
|
|
|
|
Status.StatusString[2] = '0'; |
|
|
|
|
|
|
|
|
|
if (Status.PowerSupply5V == ON) |
|
|
|
|
Status.StatusString[1] = '1'; |
|
|
|
|
else |
|
|
|
|
Status.StatusString[1] = '0'; |
|
|
|
|
|
|
|
|
|
if (Status.ControlRelay == ON) |
|
|
|
|
Status.StatusString[0] = '1'; |
|
|
|
|
else |
|
|
|
|
Status.StatusString[0] = '0'; |
|
|
|
|
|
|
|
|
|
ComposeAprsFrame(Status.StatusString); |
|
|
|
|
|
|
|
|
|
// Switch off 24V power supply
|
|
|
|
|
case 30 : |
|
|
|
|
gpio_put(PowerSupply24VControl, 0); |
|
|
|
|
Status.PowerSupply24V = OFF; |
|
|
|
|
break; |
|
|
|
|
// Switch on 24V power supply
|
|
|
|
|
case 31 : |
|
|
|
|
gpio_put(PowerSupply24VControl, 1); |
|
|
|
|
Status.PowerSupply24V = ON; |
|
|
|
|
break; |
|
|
|
|
// Switch off 12V power supply
|
|
|
|
|
case 32 : |
|
|
|
|
gpio_put(PowerSupply12VControl, 0); |
|
|
|
|
Status.PowerSupply12V = OFF; |
|
|
|
|
break; |
|
|
|
|
// Switch on 12V power supply
|
|
|
|
|
case 33 : |
|
|
|
|
gpio_put(PowerSupply12VControl, 1); |
|
|
|
|
Status.PowerSupply12V = ON; |
|
|
|
|
break; |
|
|
|
|
// Switch off 5V power supply
|
|
|
|
|
case 34 : |
|
|
|
|
gpio_put(PowerSupply5VControl, 1); |
|
|
|
|
Status.PowerSupply5V = OFF; |
|
|
|
|
break; |
|
|
|
|
// Switch on 5V power supply
|
|
|
|
|
case 35 : |
|
|
|
|
gpio_put(PowerSupply5VControl, 0); |
|
|
|
|
Status.PowerSupply5V = ON; |
|
|
|
|
break; |
|
|
|
|
// Switch off relay
|
|
|
|
|
case 36 : |
|
|
|
|
gpio_put(RelayOffControl, 1); |
|
|
|
|
sleep_ms(250); |
|
|
|
|
gpio_put(RelayOffControl, 0); |
|
|
|
|
Status.ControlRelay = OFF; |
|
|
|
|
break; |
|
|
|
|
// Switch on 24V relay
|
|
|
|
|
case 37 : |
|
|
|
|
gpio_put(RelayOnControl, 1); |
|
|
|
|
sleep_ms(250); |
|
|
|
|
gpio_put(RelayOnControl, 0); |
|
|
|
|
Status.ControlRelay = ON; |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
default : |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ServerCommand = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* A message is ready to be send */ |
|
|
|
|
if (TransmitRequest) { |
|
|
|
|
|
|
|
|
|
if ( TxDelay == 0 ) { |
|
|
|
|
// Generate pseudo random value between 0-1024
|
|
|
|
|
TxDelay = time_us_32()&0x3FF; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* If TxDelay times out: send message */ |
|
|
|
|
if ( TxDelay-- == 1 ) { |
|
|
|
|
transmit(); |
|
|
|
|
TransmitRequest = false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
@ -290,9 +407,6 @@ uint16_t decode_packet () |
|
|
|
|
printf("Message from server: %s (command %u)\n", aprs_message, aprs_server_command); |
|
|
|
|
if (aprs_acknowledge_request) { |
|
|
|
|
ComposeAprsFrame(aprs_acknowledge_number); |
|
|
|
|
// Wait for 100ms before responding with acknowledge
|
|
|
|
|
sleep_ms(100); |
|
|
|
|
transmit(); |
|
|
|
|
printf("Acknowledge request: %s\n", aprs_acknowledge_number); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -364,6 +478,8 @@ void ComposeAprsFrame(uint8_t payload[]) |
|
|
|
|
uint16_t BufferPosition = 0; |
|
|
|
|
uint16_t cnt = 0; |
|
|
|
|
|
|
|
|
|
memset(txBuffer, 0, sizeof(txBuffer)); |
|
|
|
|
|
|
|
|
|
// APRS header
|
|
|
|
|
txBuffer[BufferPosition++] = '<'; |
|
|
|
|
txBuffer[BufferPosition++] = 0xff; |
|
|
|
@ -411,6 +527,9 @@ void ComposeAprsFrame(uint8_t payload[]) |
|
|
|
|
txBuffer[BufferPosition++] = payload[cnt]; |
|
|
|
|
cnt++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set variable to indicate a send request
|
|
|
|
|
TransmitRequest = true; |
|
|
|
|
printf("%s\n", txBuffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|