Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Mictronics committed Oct 7, 2024
2 parents 856ab86 + 53f189f commit eb13e80
Show file tree
Hide file tree
Showing 60 changed files with 256 additions and 108 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/generate-userprefs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Generate UsersPrefs JSON manifest

on:
push:
paths:
- userPrefs.h
branches:
- master

jobs:
generate-userprefs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Clang
run: sudo apt-get install -y clang

- name: Install trunk
run: curl https://get.trunk.io -fsSL | bash

- name: Generate userPrefs.jsom
run: python3 ./bin/build-userprefs-json.py

- name: Trunk format json
run: trunk format userPrefs.json

- name: Commit userPrefs.json
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
git add userPrefs.json
git commit -m "Update userPrefs.json"
git push
6 changes: 3 additions & 3 deletions .github/workflows/update_protobufs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
- name: Download nanopb
run: |
wget https://jpa.kapsi.fi/nanopb/download/nanopb-0.4.8-linux-x86.tar.gz
tar xvzf nanopb-0.4.8-linux-x86.tar.gz
mv nanopb-0.4.8-linux-x86 nanopb-0.4.8
wget https://jpa.kapsi.fi/nanopb/download/nanopb-0.4.9-linux-x86.tar.gz
tar xvzf nanopb-0.4.9-linux-x86.tar.gz
mv nanopb-0.4.9-linux-x86 nanopb-0.4.9
- name: Re-generate protocol buffers
run: |
Expand Down
4 changes: 2 additions & 2 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lint:
- trufflehog@3.82.6
- yamllint@1.35.1
- bandit@1.7.10
- checkov@3.2.255
- checkov@3.2.256
- terrascan@1.19.1
- trivy@0.55.2
#- trufflehog@3.63.2-rc0
Expand All @@ -28,7 +28,7 @@ lint:
- shellcheck@0.10.0
- black@24.8.0
- git-diff-check
- gitleaks@8.19.3
- gitleaks@8.20.0
- clang-format@16.0.3
- prettier@3.3.3
ignore:
Expand Down
48 changes: 48 additions & 0 deletions bin/build-userprefs-json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json
import subprocess
import re

def get_macros_from_header(header_file):
# Run clang to preprocess the header file and capture the output
result = subprocess.run(['clang', '-E', '-dM', header_file], capture_output=True, text=True)
if result.returncode != 0:
raise RuntimeError(f"Clang preprocessing failed: {result.stderr}")

# Extract macros from the output
macros = {}
macro_pattern = re.compile(r'#define\s+(\w+)\s+(.*)')
for line in result.stdout.splitlines():
match = macro_pattern.match(line)
if match and 'USERPREFS_' in line and '_USERPREFS_' not in line:
macros[match.group(1)] = match.group(2)

return macros

def write_macros_to_json(macros, output_file):
with open(output_file, 'w') as f:
json.dump(macros, f, indent=4)

def main():
header_file = 'userPrefs.h'
output_file = 'userPrefs.json'
# Uncomment all macros in the header file
with open(header_file, 'r') as file:
lines = file.readlines()

uncommented_lines = []
for line in lines:
stripped_line = line.strip().replace('/*', '').replace('*/', '')
if stripped_line.startswith('//') and 'USERPREFS_' in stripped_line:
# Replace "//"
stripped_line = stripped_line.replace('//', '')
uncommented_lines.append(stripped_line + '\n')

with open(header_file, 'w') as file:
for line in uncommented_lines:
file.write(line)
macros = get_macros_from_header(header_file)
write_macros_to_json(macros, output_file)
print(f"Macros have been written to {output_file}")

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion bin/regen-protos.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cd protobufs && ..\nanopb-0.4.8\generator-bin\protoc.exe --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:..\src\mesh\generated" -I=..\protobufs\ ..\protobufs\meshtastic\*.proto
cd protobufs && ..\nanopb-0.4.9\generator-bin\protoc.exe --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:..\src\mesh\generated" -I=..\protobufs\ ..\protobufs\meshtastic\*.proto
6 changes: 3 additions & 3 deletions bin/regen-protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

set -e

echo "This script requires https://jpa.kapsi.fi/nanopb/download/ version 0.4.8 to be located in the"
echo "This script requires https://jpa.kapsi.fi/nanopb/download/ version 0.4.9 to be located in the"
echo "firmware root directory if the following step fails, you should download the correct"
echo "prebuilt binaries for your computer into nanopb-0.4.8"
echo "prebuilt binaries for your computer into nanopb-0.4.9"

# the nanopb tool seems to require that the .options file be in the current directory!
cd protobufs
../nanopb-0.4.8/generator-bin/protoc --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:../src/mesh/generated/" -I=../protobufs meshtastic/*.proto
../nanopb-0.4.9/generator-bin/protoc --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:../src/mesh/generated/" -I=../protobufs meshtastic/*.proto
2 changes: 1 addition & 1 deletion protobufs
4 changes: 2 additions & 2 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2485,7 +2485,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
#endif
} else {
#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \
defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \
defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \
!defined(DISPLAY_FORCE_SMALL_FONTS)
display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8,
imgSFL1);
Expand Down Expand Up @@ -2817,4 +2817,4 @@ int Screen::handleAdminMessage(const meshtastic_AdminMessage *arg)
} // namespace graphics
#else
graphics::Screen::Screen(ScanI2C::DeviceAddress, meshtastic_Config_DisplayConfig_OledType, OLEDDISPLAY_GEOMETRY) {}
#endif // HAS_SCREEN
#endif // HAS_SCREEN
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ void setup()
setenv("TZ", "GMT0", 1);
} else {
setenv("TZ", (const char *)slipstreamTZString, 1);
strcpy(config.device.tzdef, (const char *)slipstreamTZString);
}
}
tzset();
Expand Down
6 changes: 3 additions & 3 deletions src/mesh/MeshModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ std::vector<MeshModule *> MeshModule::GetMeshModulesWithUIFrames()
for (auto i = modules->begin(); i != modules->end(); ++i) {
auto &pi = **i;
if (pi.wantUIFrame()) {
LOG_DEBUG("Module wants a UI Frame\n");
LOG_DEBUG("%s wants a UI Frame\n", pi.name);
modulesWithUIFrames.push_back(&pi);
}
}
Expand All @@ -255,7 +255,7 @@ void MeshModule::observeUIEvents(Observer<const UIFrameEvent *> *observer)
auto &pi = **i;
Observable<const UIFrameEvent *> *observable = pi.getUIFrameObservable();
if (observable != NULL) {
LOG_DEBUG("Module wants a UI Frame\n");
LOG_DEBUG("%s wants a UI Frame\n", pi.name);
observer->observe(observable);
}
}
Expand Down Expand Up @@ -296,4 +296,4 @@ bool MeshModule::isRequestingFocus()
} else
return false;
}
#endif
#endif
14 changes: 13 additions & 1 deletion src/mesh/MeshService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,16 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus)
bool MeshService::isToPhoneQueueEmpty()
{
return toPhoneQueue.isEmpty();
}
}

uint32_t MeshService::GetTimeSinceMeshPacket(const meshtastic_MeshPacket *mp)
{
uint32_t now = getTime();

uint32_t last_seen = mp->rx_time;
int delta = (int)(now - last_seen);
if (delta < 0) // our clock must be slightly off still - not set from GPS yet
delta = 0;

return delta;
}
4 changes: 3 additions & 1 deletion src/mesh/MeshService.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class MeshService

ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id);

uint32_t GetTimeSinceMeshPacket(const meshtastic_MeshPacket *mp);

private:
#if HAS_GPS
/// Called when our gps position has changed - updates nodedb and sends Location message out into the mesh
Expand All @@ -163,4 +165,4 @@ class MeshService
friend class RoutingModule;
};

extern MeshService *service;
extern MeshService *service;
2 changes: 2 additions & 0 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ void NodeDB::installDefaultDeviceState()
// devicestate.node_db_lite_count = 0;
devicestate.version = DEVICESTATE_CUR_VER;
devicestate.receive_queue_count = 0; // Not yet implemented FIXME
devicestate.has_rx_waypoint = false;
devicestate.has_rx_text_message = false;

generatePacketId(); // FIXME - ugly way to init current_packet_id;

Expand Down
13 changes: 12 additions & 1 deletion src/mesh/RadioInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ const RegionInfo regions[] = {
*/
RDEF(SG_923, 917.0f, 925.0f, 100, 0, 20, true, false, false),

/*
Philippines
433 - 434.7 MHz <10 mW erp, NTC approved device required
868 - 869.4 MHz <25 mW erp, NTC approved device required
915 - 918 MHz <250 mW EIRP, no external antennna allowed
https://github.com/meshtastic/firmware/issues/4948#issuecomment-2394926135
*/

RDEF(PH_433, 433.0f, 434.7f, 100, 0, 10, true, false, false), RDEF(PH_868, 868.0f, 869.4f, 100, 0, 14, true, false, false),
RDEF(PH_915, 915.0f, 918.0f, 100, 0, 24, true, false, false),

/*
2.4 GHZ WLAN Band equivalent. Only for SX128x chips.
*/
Expand Down Expand Up @@ -614,4 +625,4 @@ size_t RadioInterface::beginSending(meshtastic_MeshPacket *p)

sendingPacket = p;
return p->encrypted.size + sizeof(PacketHeader);
}
}
4 changes: 3 additions & 1 deletion src/mesh/generated/meshtastic/admin.pb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#include "meshtastic/admin.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
Expand All @@ -18,3 +18,5 @@ PB_BIND(meshtastic_NodeRemoteHardwarePinsResponse, meshtastic_NodeRemoteHardware





2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/admin.pb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#ifndef PB_MESHTASTIC_MESHTASTIC_ADMIN_PB_H_INCLUDED
#define PB_MESHTASTIC_MESHTASTIC_ADMIN_PB_H_INCLUDED
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/apponly.pb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#include "meshtastic/apponly.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/apponly.pb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#ifndef PB_MESHTASTIC_MESHTASTIC_APPONLY_PB_H_INCLUDED
#define PB_MESHTASTIC_MESHTASTIC_APPONLY_PB_H_INCLUDED
Expand Down
4 changes: 3 additions & 1 deletion src/mesh/generated/meshtastic/atak.pb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#include "meshtastic/atak.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
Expand Down Expand Up @@ -27,3 +27,5 @@ PB_BIND(meshtastic_PLI, meshtastic_PLI, AUTO)





2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/atak.pb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#ifndef PB_MESHTASTIC_MESHTASTIC_ATAK_PB_H_INCLUDED
#define PB_MESHTASTIC_MESHTASTIC_ATAK_PB_H_INCLUDED
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/cannedmessages.pb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#include "meshtastic/cannedmessages.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/cannedmessages.pb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#ifndef PB_MESHTASTIC_MESHTASTIC_CANNEDMESSAGES_PB_H_INCLUDED
#define PB_MESHTASTIC_MESHTASTIC_CANNEDMESSAGES_PB_H_INCLUDED
Expand Down
3 changes: 2 additions & 1 deletion src/mesh/generated/meshtastic/channel.pb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#include "meshtastic/channel.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
Expand All @@ -17,3 +17,4 @@ PB_BIND(meshtastic_Channel, meshtastic_Channel, AUTO)




2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/channel.pb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#ifndef PB_MESHTASTIC_MESHTASTIC_CHANNEL_PB_H_INCLUDED
#define PB_MESHTASTIC_MESHTASTIC_CHANNEL_PB_H_INCLUDED
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/clientonly.pb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#include "meshtastic/clientonly.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/generated/meshtastic/clientonly.pb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#ifndef PB_MESHTASTIC_MESHTASTIC_CLIENTONLY_PB_H_INCLUDED
#define PB_MESHTASTIC_MESHTASTIC_CLIENTONLY_PB_H_INCLUDED
Expand Down
15 changes: 14 additions & 1 deletion src/mesh/generated/meshtastic/config.pb.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.4.8 */
/* Generated by nanopb-0.4.9 */

#include "meshtastic/config.pb.h"
#if PB_PROTO_HEADER_VERSION != 40
Expand Down Expand Up @@ -46,6 +46,19 @@ PB_BIND(meshtastic_Config_SessionkeyConfig, meshtastic_Config_SessionkeyConfig,



















Expand Down
Loading

0 comments on commit eb13e80

Please sign in to comment.