still wip

This commit is contained in:
2025-12-22 23:02:29 +01:00
parent 627acef32c
commit a48ef9d5e0
60 changed files with 6993 additions and 4939 deletions

View File

@@ -16,6 +16,10 @@
*/
#include "FreeRTOS.h"
#include "meshcore/meshframing.h"
#include "meshcore/packets/advert.h"
#include "meshcore/packets/encrypted.h"
#include "meshcore/packets/group.h"
#include "task.h"
#include "meshcore/packetstructs.h"
@@ -23,9 +27,9 @@
#include "util/log.h"
#include "string.h"
#include "meshcore/meshcore.h"
#include "lib/base64.h"
#include "lib/config.h"
#include "lib/rtc/rtc.h"
#include "lib/ed25519/ed_25519.h"
#define TAG "MeshCore"
@@ -33,9 +37,6 @@
#define TASK1_TASK_PRIO 5
#define TASK1_STK_SIZE 2048
uint8_t publKey[32] = {0x73, 0x78, 0x46, 0x76, 0x87, 0x3c, 0x9f, 0xeb, 0x00, 0x95, 0x05, 0xba, 0xdd, 0x3a, 0x4b, 0x33, 0xc8, 0xf5, 0x88, 0xa3, 0x8f, 0xaa, 0x30, 0x85, 0x3b, 0x91, 0xe6, 0xde, 0x97, 0x8c, 0xf1, 0xb2};
uint8_t privKey[32] = {0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x04, 0x22, 0x04, 0x20, 0x8a, 0x27, 0xca, 0x33, 0x85, 0xa5, 0x3b, 0x7d, 0x88, 0xce, 0x92, 0x23, 0xc4, 0x40, 0xc3, 0xac};
/* Global Variable */
TaskHandle_t Task1Task_Handler;
TaskHandle_t Task2Task_Handler;
@@ -54,29 +55,68 @@ uint8_t bufIn[256];
void task2_task (void *pvParameters) {
RTC_Init();
//ed25519_create_keypair (persistent.pubkey, persistent.privkey, "vFt0FRugSOeqnkshImMCVfgHM5vBxz4");
ed25519_create_keypair (persistent.pubkey, persistent.privkey, "vFt0FRugSOeqnkshImMCVfgHM5vBxz3");
// persistent.nodeType = NODE_TYPE_CHAT_NODE;
persistent.nodeType = NODE_TYPE_REPEATER;
memset (persistent.password, 0, sizeof (persistent.password));
strcpy (persistent.password, "hesielko");
strcpy (persistent.nodeName, "BRN RiscVpeater");
const uint8_t aesKeysDefault[AESKeyCount][17] = {
{0x11, 0x8b, 0x33, 0x87, 0xe9, 0xc5,
0xcd, 0xea, 0x6a, 0xc9, 0xe5, 0xed,
0xba, 0xa1, 0x15, 0xcd, 0x72},
{0x0a, 0x44, 0x81, 0xda, 0x0e, 0x4e,
0x03, 0xc4, 0x9e, 0x84, 0x77, 0x25,
0xd8, 0x3a, 0x93, 0xbf, 0x80}
};
memcpy (persistent.aesKeys, aesKeysDefault, sizeof (persistent.aesKeys));
sendAdvert();
char x;
while (1) {
// char tempBuf[180];
// vTaskDelay (pdMS_TO_TICKS (10000));
// snprintf (tempBuf, 180, "BRN RISCV: SySTick is %d", xTaskGetTickCount());
// makeSendGroupMessage (tempBuf, 1);
vTaskDelay (pdMS_TO_TICKS (10000));
memcpy (persistent.privkey, privKey, 32);
memcpy (persistent.pubkey, publKey, 32);
strcpy (persistent.nodeName, "BRN RiscV");
sendAdvert();
vTaskDelay (pdMS_TO_TICKS (20000));
if (USART_GetFlagStatus (USART1, USART_FLAG_RXNE) == SET) {
x = USART_ReceiveData (USART1);
if (x == 'M') {
printf ("Sending message\n");
char tempBuf[180];
snprintf (tempBuf, 180, "SySTick is %d", xTaskGetTickCount());
makeSendGroupMessage (tempBuf, 1);
}
if (x == 'A') {
printf ("Sending advert\n");
sendAdvert();
}
if (x == 'N') {
printNodeDB();
}
if (x == 'D') {
PlainTextMessagePayload plainTextMessage;
plainTextMessage.timestamp = RTC_GetCounter();
plainTextMessage.textType = 0;
plainTextMessage.attempt = 0;
snprintf(plainTextMessage.message, sizeof(plainTextMessage.message), "Sending message at SySTick is %d", xTaskGetTickCount());
printf ("Sending a direct message to the first node\n");
sendEncryptedTextMessage(&(persistent.contacts[0]), &plainTextMessage);
}
}
vTaskDelay (pdMS_TO_TICKS (2000));
}
}
void task1_task (void *pvParameters) {
//loadConfig();
// loadConfig();
const int64_t interval_ms = 10; // 10 ms
int64_t start_time, end_time, elapsed;
ESP_LOGW (TAG, "LoraInit");
LoRaInit();
int8_t txPowerInDbm = 20;
uint32_t frequencyInHz = 869618000;
uint32_t frequencyInHz = 869554000;
ESP_LOGW (TAG, "Enable TCXO");
float tcxoVoltage = 2.2; // ebyte
@@ -114,59 +154,9 @@ void task1_task (void *pvParameters) {
int8_t rssi, snr;
GetPacketStatus (&rssi, &snr);
ESP_LOGI (TAG, "rssi=%d[dBm] snr=%d[dB]", rssi, snr);
FrameStruct frame = decodeFrame (bufIn, rxLen);
printFrameHeader (frame);
unsigned char checkSumBuf[10];
AdvertisementPayload advert;
GroupTextMessage msg;
switch (frame.header & PAYLOAD_TYPE_MASK) {
case PAYLOAD_TYPE_REQ:
break;
case PAYLOAD_TYPE_RESPONSE:
break;
case PAYLOAD_TYPE_TXT_MSG:
break;
case PAYLOAD_TYPE_ACK:
memset (checkSumBuf, 0, sizeof (checkSumBuf));
base64_encode (frame.payload, 4, checkSumBuf);
printf ("Checksum: %s\n", checkSumBuf);
break;
case PAYLOAD_TYPE_ADVERT:
advert = decodeAdvertisement (frame);
printAdvertisement (advert);
break;
case PAYLOAD_TYPE_GRP_TXT:
msg = decodeGroupMessage (frame);
printGroupMessage (msg);
break;
case PAYLOAD_TYPE_GRP_DATA:
break;
case PAYLOAD_TYPE_ANON_REQ:
break;
case PAYLOAD_TYPE_PATH:
break;
case PAYLOAD_TYPE_TRACE:
break;
case PAYLOAD_TYPE_MULTIPART:
break;
case PAYLOAD_TYPE_RAW_CUSTOM:
break;
}
FrameStruct frame;
frame = decodeFrame (bufIn, rxLen);
processFrame (frame);
}
int lost = GetPacketLost();
@@ -200,7 +190,33 @@ int main (void) {
NVIC_PriorityGroupConfig (NVIC_PriorityGroup_2);
SystemCoreClockUpdate();
Delay_Init();
USART_Printf_Init (115200);
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd (RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init (GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init (USART1, &USART_InitStructure);
USART_Cmd (USART1, ENABLE);
printf ("SystemClk:%d\r\n", SystemCoreClock);
printf ("ChipID:%08x\r\n", DBGMCU_GetCHIPID());
@@ -213,12 +229,12 @@ int main (void) {
(UBaseType_t)TASK1_TASK_PRIO,
(TaskHandle_t *)&Task1Task_Handler);
xTaskCreate ((TaskFunction_t)task2_task,
(const char *)"task2",
(uint16_t)1024,
(void *)NULL,
(UBaseType_t)TASK1_TASK_PRIO,
(TaskHandle_t *)&Task2Task_Handler);
xTaskCreate ((TaskFunction_t)task2_task,
(const char *)"task2",
(uint16_t)1024,
(void *)NULL,
(UBaseType_t)TASK1_TASK_PRIO,
(TaskHandle_t *)&Task2Task_Handler);
vTaskStartScheduler();