fixed sd_logger
This commit is contained in:
@@ -32,3 +32,8 @@ jobs:
|
|||||||
path: |
|
path: |
|
||||||
build/*.hex
|
build/*.hex
|
||||||
build/*.bin
|
build/*.bin
|
||||||
|
|
||||||
|
- name: Upload Firmware
|
||||||
|
env:
|
||||||
|
SERVER_KEY: ${{ secrets.SERVER_KEY }}
|
||||||
|
run: python3 tools/upload_firmware.py $SERVER_KEY
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "cmsis_os2.h"
|
#include "cmsis_os2.h"
|
||||||
#include "BSP_GPIO.h"
|
#include "BSP_GPIO.h"
|
||||||
#include "BSP_ADC.h"
|
#include "BSP_ADC.h"
|
||||||
|
#include "BSP_SDLogger.h"
|
||||||
#define LPTIM_CLK 500 // Hz
|
#define LPTIM_CLK 500 // Hz
|
||||||
#define SLEEP_TICK_TIME 1 // seconds to wait
|
#define SLEEP_TICK_TIME 1 // seconds to wait
|
||||||
#define STAY_AWAKE_TIME 60 // seconds to stay awake without K15
|
#define STAY_AWAKE_TIME 60 // seconds to stay awake without K15
|
||||||
@@ -52,6 +52,8 @@ void BSP_POWER_WakeUp() {
|
|||||||
*/
|
*/
|
||||||
void BSP_POWER_EnterStandby() {
|
void BSP_POWER_EnterStandby() {
|
||||||
|
|
||||||
|
BSP_SDLogger_Flush();
|
||||||
|
|
||||||
// stop the sytem interrupts
|
// stop the sytem interrupts
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
uint8_t block_buffer[512] = {0};
|
uint8_t block_buffer[2048] = {0};
|
||||||
size_t block_buffer_index = 0;
|
size_t block_buffer_index = 0;
|
||||||
char file_name[20];
|
char file_name[20];
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ void BSP_SDLogger_Flush() {
|
|||||||
|
|
||||||
// open the file
|
// open the file
|
||||||
FIL file;
|
FIL file;
|
||||||
FRESULT res = f_open(&file, file_name, FA_WRITE);
|
FRESULT res = f_open(&file, file_name, FA_OPEN_APPEND | FA_WRITE );
|
||||||
if (res != FR_OK) {
|
if (res != FR_OK) {
|
||||||
ULOG_ERROR("Failed to open file %s", file_name);
|
ULOG_ERROR("Failed to open file %s", file_name);
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,7 @@ void BSP_SDLogger_Write(char *data, size_t length) {
|
|||||||
if (length > remaining_size) {
|
if (length > remaining_size) {
|
||||||
// write the remaining space to the buffer
|
// write the remaining space to the buffer
|
||||||
memcpy(&block_buffer[block_buffer_index], data, remaining_size);
|
memcpy(&block_buffer[block_buffer_index], data, remaining_size);
|
||||||
|
block_buffer_index += remaining_size;
|
||||||
// write the buffer to the file
|
// write the buffer to the file
|
||||||
BSP_SDLogger_Flush();
|
BSP_SDLogger_Flush();
|
||||||
// write the remaining data to the buffer
|
// write the remaining data to the buffer
|
||||||
|
|||||||
@@ -10,3 +10,5 @@ void BSP_SDLogger_Init(int log_number);
|
|||||||
|
|
||||||
|
|
||||||
void BSP_SDLogger_Write(char *data, size_t length);
|
void BSP_SDLogger_Write(char *data, size_t length);
|
||||||
|
|
||||||
|
void BSP_SDLogger_Flush();
|
||||||
@@ -187,7 +187,7 @@ void StartDefaultTask(void *argument)
|
|||||||
ULOG_INFO(output);
|
ULOG_INFO(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BSP_SDLogger_Init(counter);
|
||||||
|
|
||||||
char INA_LOG[72];
|
char INA_LOG[72];
|
||||||
|
|
||||||
|
|||||||
71
tools/upload_firmware.py
Normal file
71
tools/upload_firmware.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import hmac
|
||||||
|
import hashlib
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
import requests
|
||||||
|
import subprocess
|
||||||
|
import base64
|
||||||
|
|
||||||
|
def load_secret_key(keyb64: str):
|
||||||
|
# Decode the base64 encoded key
|
||||||
|
decoded_key = base64.b64decode(keyb64)
|
||||||
|
|
||||||
|
return decoded_key
|
||||||
|
|
||||||
|
def compute_hmac(file_path, secret_key):
|
||||||
|
"""Compute the HMAC of a file using HMAC-SHA256."""
|
||||||
|
hmac_obj = hmac.new(secret_key, digestmod=hashlib.sha256)
|
||||||
|
with open(file_path, 'rb') as f:
|
||||||
|
while chunk := f.read(4096):
|
||||||
|
hmac_obj.update(chunk)
|
||||||
|
return hmac_obj.hexdigest()
|
||||||
|
|
||||||
|
def upload_file(url, file_path, secret_key):
|
||||||
|
"""Upload a file to the server with an HMAC signature."""
|
||||||
|
# Compute HMAC of the file
|
||||||
|
signature = compute_hmac(file_path, secret_key)
|
||||||
|
print(signature)
|
||||||
|
# Prepare headers
|
||||||
|
headers = {'X-Signature': signature}
|
||||||
|
|
||||||
|
# Read file and prepare files dictionary for request
|
||||||
|
with open(file_path, 'rb') as f:
|
||||||
|
files = {'file': (Path(file_path).name, f)}
|
||||||
|
response = requests.post(url, files=files, headers=headers)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def get_short_git_commit_hash():
|
||||||
|
try:
|
||||||
|
# Run the Git command to get the short commit hash
|
||||||
|
result = subprocess.run(['git', 'rev-parse', '--short', 'HEAD'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, check=True)
|
||||||
|
# Extract and return the commit hash
|
||||||
|
return result.stdout.strip()
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error getting Git commit hash: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
url = "https://fw.revwal.de/master/upload" # Adjust this to your server's URL
|
||||||
|
|
||||||
|
|
||||||
|
fw_path = "build/CLS_Master.bin" # Path to the file you want to upload
|
||||||
|
|
||||||
|
# Get the Git commit hash
|
||||||
|
commit_hash = get_short_git_commit_hash()
|
||||||
|
if commit_hash is None:
|
||||||
|
print("Error: Could not get Git commit hash")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# replace the file name with the commit hash
|
||||||
|
file_path = fw_path.replace("CLS_Master", commit_hash)
|
||||||
|
|
||||||
|
# copy the file to the new name
|
||||||
|
subprocess.run(['cp', fw_path, file_path])
|
||||||
|
|
||||||
|
|
||||||
|
secret_key = load_secret_key(sys.argv[1])
|
||||||
|
|
||||||
|
response = upload_file(url, file_path, secret_key)
|
||||||
|
print(f"Server response: {response.text}")
|
||||||
Reference in New Issue
Block a user