Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RocketControlUnitGUI/src/lib/hooks/useInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,4 @@ export const useInteraction = (pocketbaseHook: PocketbaseHook) => {
instantStateChange,
resumeConfirmRemoveWeight,
};
};
};
36 changes: 25 additions & 11 deletions RocketControlUnitGUI/src/lib/hooks/usePocketbase.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import PocketBase from 'pocketbase';
import type { Timestamps } from '../timestamps';
import type { Stores } from '../stores';
import { currentState } from '../stores';
import { currentState, type Stores } from '../stores';
import { fetchUsbMessage, decryptMessage } from '../message';

export type PocketbaseHook = ReturnType<typeof usePocketbase>;

export const usePocketbase = (timestamps: Timestamps, stores: Stores) => {
const pocketbase = new PocketBase('http://192.168.0.69:8090');
const pocketbase = new PocketBase('http://localhost:8090');

const usbMessagePromise = fetchUsbMessage();

const authenticate = async () => {
const email = import.meta.env.VITE_EMAIL;
const password = import.meta.env.VITE_PASSWORD;
const usbMessage = await usbMessagePromise;

if (usbMessage) {
const { email, password } = usbMessage;

const decryptedEmail = decryptMessage(email);
const decryptedPassword = decryptMessage(password);

if (email && password) {
pocketbase.authStore.clear();
await pocketbase.admins.authWithPassword(email, password);
await pocketbase.admins.authWithPassword(decryptedEmail, decryptedPassword);

return true;
}
Expand All @@ -29,10 +35,18 @@ export const usePocketbase = (timestamps: Timestamps, stores: Stores) => {
};

const writeStateChange = async (state: string) => {
await pocketbase.collection('CommandMessage').create({
target: 'NODE_DMB',
command: state
});
const usbMessage = await usbMessagePromise;

if (!usbMessage) {
return;
}

if (decryptMessage(usbMessage.permission) == 'MasterKey') {
await pocketbase.collection('CommandMessage').create({
target: 'NODE_DMB',
command: state
});
}
};

const writeCommandMessage = async (target: string, command: string) => {
Expand Down
41 changes: 41 additions & 0 deletions RocketControlUnitGUI/src/lib/message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export function decryptMessage(messageString: string) {
let decryptedText = '';
let shift = 3;

if (messageString == 'usb drive not found') {
return messageString;
}

for (let char of messageString) {
if (/[a-zA-Z]/.test(char)) {
const shiftBase = char === char.toUpperCase() ? 'A'.charCodeAt(0) : 'a'.charCodeAt(0);
const decryptedChar = String.fromCharCode(
((char.charCodeAt(0) - shiftBase - shift + 26) % 26) + shiftBase
);
decryptedText += decryptedChar;
} else {
decryptedText += char;
}
}

return decryptedText;
}

export interface UsbData {
permission: string;
email: string;
password: string;
}

export async function fetchUsbMessage(): Promise<UsbData | undefined> {
try {
const response = await fetch('http://127.0.0.1:5000/message');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json() as UsbData;
return data;
} catch (error) {
console.error('Error:', error);
}
}
4 changes: 3 additions & 1 deletion RocketControlUnitGUI/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
timer_remaining
} = stores;


onMount(() => {
let heartbeatInterval: NodeJS.Timeout;

Expand Down Expand Up @@ -137,6 +138,7 @@

window.removeEventListener('resize', handleResize);
};

});

$: ac1_display = $ac1_open === undefined ? 'N/A' : $ac1_open ? 'ON' : 'OFF';
Expand Down Expand Up @@ -604,7 +606,7 @@
</div>

<!-- Render different buttons based on the current state -->
{#if $currentState == "RS_PRELAUNCH"}
{#if $currentState == "RS_PRELAUNCH" }
<button
class="btn variant-filled-secondary next-state-btn"
style="top: calc(var(--container-width) * 0.5);"
Expand Down
213 changes: 0 additions & 213 deletions backend/test/dumpy.py

This file was deleted.

10 changes: 5 additions & 5 deletions backend/test/dumpy_reborn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import concurrent.futures

endpoint = "http://localhost:8090"
admin_email = "test@test.test"
admin_password = "123456789a"
admin_email = "test@test.com"
admin_password = "0123456789"

# Initialize PocketBase
pb = PocketBase(endpoint)

# Authenticate
admin_data = pb.admins.auth_with_password(admin_email, admin_password)

if not admin_data.is_valid:
print("Authentication failed")
exit()
# if not admin_data.is_valid:
# print("Authentication failed")
# exit()

battery_data = ["INVALID", "GROUND", "ROCKET"]

Expand Down
20 changes: 20 additions & 0 deletions database/pb_migrations/1732397549_updated_Baro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="../pb_data/types.d.ts" />
migrate((db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("2j2bfgv8i8le9vo")

collection.createRule = ""
collection.updateRule = ""
collection.deleteRule = ""

return dao.saveCollection(collection)
}, (db) => {
const dao = new Dao(db)
const collection = dao.findCollectionByNameOrId("2j2bfgv8i8le9vo")

collection.createRule = null
collection.updateRule = null
collection.deleteRule = null

return dao.saveCollection(collection)
})
Loading