vp-digi/Src/beacon.c

129 wiersze
3.5 KiB
C
Czysty Zwykły widok Historia

2021-09-10 09:30:51 +00:00
/*
This file is part of VP-Digi.
VP-Digi 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.
VP-Digi 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 VP-Digi. If not, see <http://www.gnu.org/licenses/>.
*/
#include "beacon.h"
#include "digipeater.h"
#include "common.h"
#include <string.h>
#include "ax25.h"
#include "terminal.h"
#include "drivers/systick.h"
2023-08-17 12:57:29 +00:00
struct Beacon beacon[8];
2021-09-10 09:30:51 +00:00
2023-08-17 12:57:29 +00:00
static uint32_t beaconDelay[8] = {0};
static uint8_t buf[150]; //frame buffer
2021-09-10 09:30:51 +00:00
/**
* @brief Send specified beacon
* @param[in] no Beacon number (0-7)
*/
2023-08-17 12:57:29 +00:00
void BeaconSend(uint8_t number)
2021-09-10 09:30:51 +00:00
{
2023-08-17 12:57:29 +00:00
if(beacon[number].enable == 0)
2021-09-10 09:30:51 +00:00
return; //beacon disabled
uint16_t idx = 0;
2023-08-17 12:57:29 +00:00
for(uint8_t i = 0; i < sizeof(GeneralConfig.dest); i++) //add destination address
buf[idx++] = GeneralConfig.dest[i];
2021-09-10 09:30:51 +00:00
2023-08-17 12:57:29 +00:00
for(uint8_t i = 0; i < sizeof(GeneralConfig.call); i++) //add source address
buf[idx++] = GeneralConfig.call[i];
2021-09-10 09:30:51 +00:00
2023-08-17 12:57:29 +00:00
buf[idx++] = ((GeneralConfig.callSsid << 1) + 0b01100000); //add source ssid
2021-09-10 09:30:51 +00:00
2023-08-17 12:57:29 +00:00
if(beacon[number].path[0] > 0) //this beacon has some path set
2021-09-10 09:30:51 +00:00
{
for(uint8_t i = 0; i < 14; i++) //loop through path
{
2023-08-17 12:57:29 +00:00
if((beacon[number].path[i] > 0) || (i == 6) || (i == 13)) //normal data, not a NULL symbol
2021-09-10 09:30:51 +00:00
{
2023-08-17 12:57:29 +00:00
buf[idx] = beacon[number].path[i]; //copy path
2021-09-10 09:30:51 +00:00
if((i == 6) || (i == 13)) //it was and ssid
{
2023-08-17 12:57:29 +00:00
buf[idx] = ((buf[idx] << 1) + 0b01100000); //add appropriate bits for ssid
2021-09-10 09:30:51 +00:00
}
idx++;
}
else //NULL in path
break; //end here
}
}
buf[idx - 1] |= 1; //add c-bit on the last element
buf[idx++] = 0x03; //control
buf[idx++] = 0xF0; //pid
2023-08-17 12:57:29 +00:00
for(uint8_t i = 0; i < strlen((char*)beacon[number].data); i++)
2021-09-10 09:30:51 +00:00
{
2023-08-17 12:57:29 +00:00
buf[idx++] = beacon[number].data[i]; //copy beacon comment
2021-09-10 09:30:51 +00:00
}
2023-08-17 12:57:29 +00:00
void *handle = NULL;
if(NULL != (handle = Ax25WriteTxFrame(buf, idx))) //try to write frame to TX buffer
2021-09-10 09:30:51 +00:00
{
2023-08-17 12:57:29 +00:00
if(GeneralConfig.kissMonitor) //monitoring mode, send own frames to KISS ports
2022-08-30 12:00:04 +00:00
{
2023-08-17 12:57:29 +00:00
TermSendToAll(MODE_KISS, buf, idx);
2022-08-30 12:00:04 +00:00
}
2022-08-29 11:00:28 +00:00
2023-08-17 12:57:29 +00:00
DigiStoreDeDupe(buf, idx); //store frame hash in duplicate protection buffer (to prevent from digipeating own packets)
2021-09-10 09:30:51 +00:00
2023-08-17 12:57:29 +00:00
TermSendToAll(MODE_MONITOR, (uint8_t*)"(AX.25) Transmitting beacon ", 0);
2021-09-10 09:30:51 +00:00
2023-08-17 12:57:29 +00:00
TermSendNumberToAll(MODE_MONITOR, number);
TermSendToAll(MODE_MONITOR, (uint8_t*)": ", 0);
SendTNC2(buf, idx);
TermSendToAll(MODE_MONITOR, (uint8_t*)"\r\n", 0);
2021-09-10 09:30:51 +00:00
}
}
/**
2023-08-17 12:57:29 +00:00
* @brief Check if any beacon should be transmitted and transmit if necessary
2021-09-10 09:30:51 +00:00
*/
2023-08-17 12:57:29 +00:00
void BeaconCheck(void)
2021-09-10 09:30:51 +00:00
{
for(uint8_t i = 0; i < 8; i++)
{
if(beacon[i].enable == 0)
continue;
2021-09-10 09:30:51 +00:00
2023-08-18 10:50:33 +00:00
if((beacon[i].interval > 0) && ((SysTickGet() >= beacon[i].next) || (beacon[i].next == 0)))
2021-09-10 09:30:51 +00:00
{
2023-08-18 10:50:33 +00:00
if(beaconDelay[i] > SysTickGet()) //check for beacon delay (only for the very first transmission)
2023-08-30 14:26:23 +00:00
continue;
2023-08-18 10:50:33 +00:00
beacon[i].next = SysTickGet() + beacon[i].interval; //save next beacon timestamp
2021-09-10 09:30:51 +00:00
beaconDelay[i] = 0;
2023-08-17 12:57:29 +00:00
BeaconSend(i);
2021-09-10 09:30:51 +00:00
}
}
}
/**
* @brief Initialize beacon module
*/
2023-08-17 12:57:29 +00:00
void BeaconInit(void)
2021-09-10 09:30:51 +00:00
{
for(uint8_t i = 0; i < 8; i++)
{
2023-08-18 10:50:33 +00:00
beaconDelay[i] = (beacon[i].delay * SYSTICK_FREQUENCY) + SysTickGet() + (30000 / SYSTICK_INTERVAL); //set delay for beacons and add constant 30 seconds of delay
2021-09-10 09:30:51 +00:00
beacon[i].next = 0;
}
}