clangformat everything
This commit is contained in:
@@ -49,20 +49,18 @@ static void udp_broadcast_set_owner_details_mac(void) {
|
||||
* @see UDP_BROADCAST_LCD_NAME_PRE_TEXT in front of it
|
||||
*/
|
||||
|
||||
static void udp_broadcast_name_to_lcd(void){
|
||||
static void udp_broadcast_name_to_lcd(void) {
|
||||
char text[UDP_BROADCAST_LCD_TEXT_SIZE];
|
||||
|
||||
memset(text,' ',UDP_BROADCAST_LCD_TEXT_SIZE); // Fill with spaces
|
||||
text[UDP_BROADCAST_LCD_TEXT_SIZE - 1] = '\0'; // Make the last a NULL byte
|
||||
memset(text, ' ', UDP_BROADCAST_LCD_TEXT_SIZE); // Fill with spaces
|
||||
text[UDP_BROADCAST_LCD_TEXT_SIZE - 1] = '\0'; // Make the last a NULL byte
|
||||
lcd_display_text(text, owner_name_x_pos, owner_name_y_pos, LCD_BLACK, LCD_WHITE, LCD_FONT12);
|
||||
|
||||
snprintf(text, UDP_BROADCAST_LCD_TEXT_SIZE, "%s%s",UDP_BROADCAST_LCD_NAME_PRE_TEXT,
|
||||
udp_owner.name);
|
||||
snprintf(text, UDP_BROADCAST_LCD_TEXT_SIZE, "%s%s", UDP_BROADCAST_LCD_NAME_PRE_TEXT, udp_owner.name);
|
||||
|
||||
lcd_display_text(text, owner_name_x_pos, owner_name_y_pos, LCD_BLACK, LCD_WHITE, LCD_FONT12);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @fn uint8_t udp_broadcast_set_owner_details_name(owner_details_t*, const char*)
|
||||
* @brief set_owner_details_name() sets the owner's name in the owner_details_t struct
|
||||
@@ -76,13 +74,12 @@ static void udp_broadcast_name_to_lcd(void){
|
||||
*/
|
||||
|
||||
static uint8_t udp_broadcast_set_owner_details_name(const char* name) {
|
||||
|
||||
if (name == NULL) {
|
||||
LOG_WARN(TAG, "%s: string given is a NULL pointer", __func__);
|
||||
return 1;
|
||||
}
|
||||
LOG_DEBUG(TAG, "set: %s", name);
|
||||
strncpy(udp_owner.name, name, sizeof(udp_owner.name) - 1); // -1: compensate for '\0'
|
||||
strncpy(udp_owner.name, name, sizeof(udp_owner.name) - 1); // -1: compensate for '\0'
|
||||
|
||||
udp_broadcast_name_to_lcd();
|
||||
return 0;
|
||||
@@ -104,7 +101,7 @@ static uint8_t udp_broadcast_set_owner_details_surname(const char* surname) {
|
||||
return 1;
|
||||
}
|
||||
LOG_DEBUG(TAG, "set: %s", surname);
|
||||
strncpy(udp_owner.surname, surname, sizeof(udp_owner.surname)-1); // -1: compensate for '\0'
|
||||
strncpy(udp_owner.surname, surname, sizeof(udp_owner.surname) - 1); // -1: compensate for '\0'
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -125,7 +122,7 @@ static uint8_t udp_broadcast_set_owner_details_reply(const char* reply) {
|
||||
return 1;
|
||||
}
|
||||
LOG_DEBUG(TAG, "set: %s", reply);
|
||||
strncpy(udp_owner.reply, reply, sizeof(udp_owner.reply) - 1); // -1: compensate for '\0'
|
||||
strncpy(udp_owner.reply, reply, sizeof(udp_owner.reply) - 1); // -1: compensate for '\0'
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -144,8 +141,8 @@ static void udp_broadcast_format_reply(void) {
|
||||
udp_owner.mac_address[1], udp_owner.mac_address[2], udp_owner.mac_address[3], udp_owner.mac_address[4],
|
||||
udp_owner.mac_address[5]);
|
||||
|
||||
snprintf(reply_buf, UDP_BROADCAST_MAX_REPLY_SIZE, "%s %s %s %s", mac_addr_str, UDP_BROADCAST_REPLY_MIDDLE_TEXT, udp_owner.surname,
|
||||
udp_owner.name);
|
||||
snprintf(reply_buf, UDP_BROADCAST_MAX_REPLY_SIZE, "%s %s %s %s", mac_addr_str, UDP_BROADCAST_REPLY_MIDDLE_TEXT,
|
||||
udp_owner.surname, udp_owner.name);
|
||||
udp_broadcast_set_owner_details_reply(reply_buf);
|
||||
}
|
||||
|
||||
@@ -163,7 +160,6 @@ static void udp_broadcast_format_reply(void) {
|
||||
*/
|
||||
err_t udp_broadcast_set_owner_details(const char* name, const char* surname) {
|
||||
if (!udp_broadcast_set_owner_details_name(name) && !udp_broadcast_set_owner_details_surname(surname)) {
|
||||
|
||||
// If both return 0 it's okay
|
||||
udp_broadcast_set_owner_details_mac();
|
||||
udp_broadcast_format_reply();
|
||||
@@ -234,7 +230,7 @@ static uint8_t udp_broadcast_check_function(const char data[UDP_BROADCAST_MAX_DA
|
||||
memset(func, 0, sizeof(func));
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
memcpy(func,data,UDP_BROADCAST_MAX_FUNC_LEN - 1);
|
||||
memcpy(func, data, UDP_BROADCAST_MAX_FUNC_LEN - 1);
|
||||
if (strcmp(func, "func1:") != 0) {
|
||||
LOG_WARN(TAG, "%s: datagram does not contain function that's currently available", __func__);
|
||||
return 1;
|
||||
@@ -245,16 +241,16 @@ static uint8_t udp_broadcast_check_function(const char data[UDP_BROADCAST_MAX_DA
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
if (enders[2] - enders[1] < UDP_BROADCAST_MAX_NAME_SIZE + 2 && data_len - enders[3] < UDP_BROADCAST_MAX_NAME_SIZE + 2
|
||||
&& strncmp(data + enders[0], ":name", 5) == 0 && strncmp(data + enders[2], ", surname", 9) == 0) {
|
||||
|
||||
if (enders[2] - enders[1] < UDP_BROADCAST_MAX_NAME_SIZE + 2
|
||||
&& data_len - enders[3] < UDP_BROADCAST_MAX_NAME_SIZE + 2 && strncmp(data + enders[0], ":name", 5) == 0
|
||||
&& strncmp(data + enders[2], ", surname", 9) == 0) {
|
||||
counter = 0;
|
||||
for (uint8_t i = enders[1] + 2; i < enders[2]; i++) {
|
||||
buffer[counter] = data[i];
|
||||
counter++;
|
||||
}
|
||||
if (buffer[0]=='\0') {
|
||||
strncpy(buffer, "name", sizeof(buffer) - 1); // -1: compensate for '\0'
|
||||
if (buffer[0] == '\0') {
|
||||
strncpy(buffer, "name", sizeof(buffer) - 1); // -1: compensate for '\0'
|
||||
}
|
||||
LOG_INFO(TAG, "new owner name:%s", buffer);
|
||||
udp_broadcast_set_owner_details_name(buffer);
|
||||
@@ -264,15 +260,15 @@ static uint8_t udp_broadcast_check_function(const char data[UDP_BROADCAST_MAX_DA
|
||||
buffer[counter] = data[i];
|
||||
counter++;
|
||||
}
|
||||
if (buffer[0]=='\0') {
|
||||
strncpy(buffer, "default", sizeof(buffer) - 1); // -1: compensate for '\0'
|
||||
if (buffer[0] == '\0') {
|
||||
strncpy(buffer, "default", sizeof(buffer) - 1); // -1: compensate for '\0'
|
||||
}
|
||||
LOG_INFO(TAG, "new owner surname:%s", buffer);
|
||||
udp_broadcast_set_owner_details_surname(buffer);
|
||||
udp_broadcast_format_reply();
|
||||
return 0;
|
||||
}
|
||||
LOG_WARN(TAG,"%s: function didn't receive the right formatting", __func__);
|
||||
LOG_WARN(TAG, "%s: function didn't receive the right formatting", __func__);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -311,7 +307,7 @@ static void udp_receive_callback(void* arg,
|
||||
}
|
||||
pc = (char*)p->payload;
|
||||
len = p->tot_len;
|
||||
if (len >= UDP_BROADCAST_MAX_DATA_SIZE) { // >= : only if it's smaller to compensate for '\0'
|
||||
if (len >= UDP_BROADCAST_MAX_DATA_SIZE) { // >= : only if it's smaller to compensate for '\0'
|
||||
LOG_WARN(TAG, "%s: input buffer was bigger than or was max size %d", __func__, UDP_BROADCAST_MAX_DATA_SIZE);
|
||||
return;
|
||||
}
|
||||
@@ -328,15 +324,14 @@ static void udp_receive_callback(void* arg,
|
||||
LOG_INFO(TAG, "%s: received data from %s at port: %d: %s", __func__, source_ip_str, port, data);
|
||||
LOG_INFO(TAG, "%s: checking which function was called", __func__);
|
||||
|
||||
if(!udp_broadcast_check_function(data)){ // Should return 0 to reply
|
||||
if (!udp_broadcast_check_function(data)) { // Should return 0 to reply
|
||||
p_data->payload = udp_owner.reply;
|
||||
p_data->len = strlen(udp_owner.reply);
|
||||
p_data->tot_len = strlen(udp_owner.reply);
|
||||
udp_sendto(connection, p_data, addr, 64000); // QT app listens on port 64000
|
||||
udp_sendto(connection, p_data, addr, 64000); // QT app listens on port 64000
|
||||
LOG_INFO(TAG, "%s: tried to reply to %s at port: %d: %s", __func__, source_ip_str, 64000, udp_owner.reply);
|
||||
}
|
||||
|
||||
|
||||
defer:
|
||||
pbuf_free(p);
|
||||
pbuf_free(p_data);
|
||||
@@ -375,8 +370,6 @@ err_t udp_broadcast_connection_init(void) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @fn err_t udp_broadcast_init()
|
||||
* @brief udp_broadcast_init() initializes the owner's variables and calls upon @see udp_broadcast_connection_init()
|
||||
@@ -391,7 +384,7 @@ err_t udp_broadcast_connection_init(void) {
|
||||
err_t udp_broadcast_init(uint32_t x_pos, uint32_t y_pos) {
|
||||
owner_name_x_pos = x_pos;
|
||||
owner_name_y_pos = y_pos;
|
||||
if(udp_broadcast_set_owner_details("name", "default") != ERR_OK){
|
||||
if (udp_broadcast_set_owner_details("name", "default") != ERR_OK) {
|
||||
LOG_WARN(TAG, "%s: don't give NULL pointers as arguments for the owner's details", __func__);
|
||||
return ERR_ARG;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "lcd_api.h"
|
||||
|
||||
|
||||
static const char* TAG = "lcd_api";
|
||||
|
||||
static DMA2D_HandleTypeDef hDma2dHandler2;
|
||||
@@ -85,7 +84,12 @@ void lcd_task(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void lcd_display_text(const char* text, uint32_t x_pos, uint32_t y_pos, uint32_t color, uint32_t bg_color, sFONT* font) {
|
||||
void lcd_display_text(const char* text,
|
||||
uint32_t x_pos,
|
||||
uint32_t y_pos,
|
||||
uint32_t color,
|
||||
uint32_t bg_color,
|
||||
sFONT* font) {
|
||||
BSP_LCD_SelectLayer(1);
|
||||
LOG_INFO(TAG, "Display text: %s @x=%d,y=%d", text, x_pos, y_pos);
|
||||
|
||||
@@ -118,7 +122,12 @@ void lcd_display_text(const char* text, uint32_t x_pos, uint32_t y_pos, uint32_t
|
||||
BSP_LCD_DisplayStringAt(x_pos, y_pos, (uint8_t*)text, LEFT_MODE);
|
||||
}
|
||||
|
||||
void lcd_draw_raw_img(const void* p_src, uint32_t x_pos, uint32_t y_pos, uint32_t x_size, uint32_t y_size, uint32_t color_mode) {
|
||||
void lcd_draw_raw_img(const void* p_src,
|
||||
uint32_t x_pos,
|
||||
uint32_t y_pos,
|
||||
uint32_t x_size,
|
||||
uint32_t y_size,
|
||||
uint32_t color_mode) {
|
||||
LOG_INFO(TAG, "Displaying raw image: @x=%lu, @y=%lu, width=%lu, height=%lu", x_pos, y_pos, x_size, y_size);
|
||||
BSP_LCD_SelectLayer(0);
|
||||
uint32_t address = hLtdcHandler.LayerCfg[1].FBStartAdress + (((BSP_LCD_GetXSize() * y_pos) + x_pos) * (4));
|
||||
@@ -197,7 +206,7 @@ void lcd_clear_images(void) {
|
||||
BSP_LCD_Clear(0);
|
||||
}
|
||||
|
||||
void lcd_set_bg_color_layer0(uint32_t color){
|
||||
void lcd_set_bg_color_layer0(uint32_t color) {
|
||||
BSP_LCD_SelectLayer(0);
|
||||
BSP_LCD_Clear(color);
|
||||
}
|
||||
@@ -316,9 +325,9 @@ static inline void free_gif_slot(lcd_gif_t* gif) {
|
||||
static void gif_draw_cb(GIFDRAW* pDraw) {
|
||||
BSP_LCD_SelectLayer(0);
|
||||
lcd_gif_t* gif = (lcd_gif_t*)pDraw->pUser;
|
||||
uint8_t* palette = pDraw->pPalette24; // The RGB888 color palette
|
||||
uint8_t* p_src = pDraw->pPixels; // Source pixel pointer
|
||||
int y = pDraw->iY + pDraw->y; // Current line being drawn
|
||||
uint8_t* palette = pDraw->pPalette24; // The RGB888 color palette
|
||||
uint8_t* p_src = pDraw->pPixels; // Source pixel pointer
|
||||
int y = pDraw->iY + pDraw->y; // Current line being drawn
|
||||
|
||||
// Calculate the destination address of the first pixel in the line
|
||||
uint32_t address = hLtdcHandler.LayerCfg[0].FBStartAdress + (((BSP_LCD_GetXSize() * gif->y_pos) + gif->x_pos) * 4)
|
||||
@@ -344,10 +353,10 @@ static void gif_draw_cb(GIFDRAW* pDraw) {
|
||||
}
|
||||
|
||||
// Get the color from the palette and convert it to ARGB8888
|
||||
uint8_t *p = palette + (pixel * 3);
|
||||
uint8_t* p = palette + (pixel * 3);
|
||||
uint32_t color = (0xFF << 24) | (p[0] << 16) | (p[1] << 8) | p[2];
|
||||
|
||||
// Draw the pixel
|
||||
((uint32_t *)address)[x] = color;
|
||||
((uint32_t*)address)[x] = color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define LOGGER_LEVEL_WARN
|
||||
#include "log.h"
|
||||
#include "llfs.h"
|
||||
#include "log.h"
|
||||
|
||||
/**
|
||||
* @brief The maximum number of files that can be opened concurrently using the POSIX API
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
extern struct llfs_data_file* llfs_root;
|
||||
static const char* TAG = "llfs";
|
||||
static size_t file_count = 0; // Cache for the number of files in the filesystem
|
||||
static size_t file_count = 0; // Cache for the number of files in the filesystem
|
||||
static FILE* file_table[POSIX_MAX_FILES];
|
||||
|
||||
#ifndef TESTING
|
||||
@@ -331,7 +331,7 @@ off_t _lseek(int file, int ptr, int dir) {
|
||||
*/
|
||||
int _fstat(int file, struct stat* st) {
|
||||
FILE* stream;
|
||||
llfs_file_t *llfs_file;
|
||||
llfs_file_t* llfs_file;
|
||||
|
||||
// Check if the file is stdin, stdout or stderr
|
||||
if (file == STDIN_FILENO || file == STDOUT_FILENO || file == STDERR_FILENO) {
|
||||
@@ -353,7 +353,7 @@ int _fstat(int file, struct stat* st) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
st->st_mode = S_IFREG; // Regular file
|
||||
st->st_mode = S_IFREG; // Regular file
|
||||
st->st_size = (off_t)llfs_file->len;
|
||||
return 0;
|
||||
}
|
||||
@@ -442,4 +442,3 @@ static uint8_t file_ext_cmp(const char* const filename, const char* const ext) {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
547405
project/Core/Src/llfs_data.c
547405
project/Core/Src/llfs_data.c
File diff suppressed because it is too large
Load Diff
@@ -7,8 +7,8 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "stm32f7xx_hal.h"
|
||||
#include "log.h"
|
||||
#include "stm32f7xx_hal.h"
|
||||
|
||||
extern UART_HandleTypeDef huart1;
|
||||
|
||||
@@ -18,7 +18,7 @@ extern UART_HandleTypeDef huart1;
|
||||
* @return The current timestamp in milliseconds since boot
|
||||
*/
|
||||
|
||||
int _write(int file, char *data, int len) {
|
||||
int _write(int file, char* data, int len) {
|
||||
HAL_StatusTypeDef status;
|
||||
|
||||
switch (file) {
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
static const char *TAG = "main";
|
||||
static const char* TAG = "main";
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
@@ -149,8 +149,8 @@ int main(void) {
|
||||
// Initialize the UDP broadcast service
|
||||
|
||||
if (udp_broadcast_init(10, 255) != ERR_OK) {
|
||||
LOG_WARN(TAG,
|
||||
"error initializing udp connection, check warnings from udp_broadcast_init() or udp_broadcast_connection_init()");
|
||||
LOG_WARN(TAG, "error initializing udp connection, check warnings from udp_broadcast_init() or "
|
||||
"udp_broadcast_connection_init()");
|
||||
}
|
||||
if (udp_broadcast_set_owner_details("Joran", "Van Nieuwenhoven") != ERR_OK) {
|
||||
LOG_WARN(TAG, "error setting owner's details");
|
||||
|
||||
@@ -17,24 +17,18 @@
|
||||
#include "log.h"
|
||||
|
||||
#define ATTEMPT_RECONNECT_AMOUNT 50
|
||||
#define PUBLISH_QOS 2
|
||||
#define PUBLISH_RETAIN 1
|
||||
#define PRINT_XPOS 50
|
||||
#define PRINT_YPOS 50
|
||||
#define MAX_FILES 20
|
||||
#define SERVER_IP4_A 192
|
||||
#define SERVER_IP4_B 168
|
||||
#define SERVER_IP4_C 69
|
||||
#define SERVER_IP4_D 11
|
||||
#define SERVER_PORT 1883
|
||||
#define PUBLISH_QOS 2
|
||||
#define PUBLISH_RETAIN 1
|
||||
#define PRINT_XPOS 50
|
||||
#define PRINT_YPOS 50
|
||||
#define MAX_FILES 20
|
||||
#define SERVER_IP4_A 192
|
||||
#define SERVER_IP4_B 168
|
||||
#define SERVER_IP4_C 69
|
||||
#define SERVER_IP4_D 11
|
||||
#define SERVER_PORT 1883
|
||||
|
||||
typedef enum input_topic {
|
||||
set_text,
|
||||
set_text_color,
|
||||
set_color,
|
||||
set_image,
|
||||
other_topic
|
||||
} input_topic_t;
|
||||
typedef enum input_topic { set_text, set_text_color, set_color, set_image, other_topic } input_topic_t;
|
||||
|
||||
// Function prototypes
|
||||
static void mqtt_pub_request_cb(void*, err_t);
|
||||
@@ -47,7 +41,8 @@ static void mosquitto_connect(mqtt_client_t*);
|
||||
static uint32_t color_picker(char*);
|
||||
static void create_publish_string(char*, char*, size_t);
|
||||
|
||||
// Global variables used in mqtt_incoming_publish_cb and mqtt_incoming_data_cb to give an easy to use ID to the subscribed topics
|
||||
// Global variables used in mqtt_incoming_publish_cb and mqtt_incoming_data_cb to give an easy to use ID to the
|
||||
// subscribed topics
|
||||
static sFONT* font;
|
||||
static uint16_t xpos;
|
||||
static uint16_t ypos;
|
||||
@@ -80,9 +75,10 @@ static void publish_data(mqtt_client_t* client, void* arg) {
|
||||
|
||||
LOG_DEBUG(TAG, "Entering publish");
|
||||
|
||||
create_publish_string("*.bmp", pub_payload,sizeof(pub_payload));
|
||||
create_publish_string("*.bmp", pub_payload, sizeof(pub_payload));
|
||||
|
||||
err = mqtt_publish(client, "getImageList", pub_payload, strlen(pub_payload), PUBLISH_QOS, PUBLISH_RETAIN, mqtt_pub_request_cb, arg);
|
||||
err = mqtt_publish(client, "getImageList", pub_payload, strlen(pub_payload), PUBLISH_QOS, PUBLISH_RETAIN,
|
||||
mqtt_pub_request_cb, arg);
|
||||
if (err != ERR_OK) {
|
||||
LOG_DEBUG(TAG, "Publish err: %d", err);
|
||||
}
|
||||
@@ -90,7 +86,8 @@ static void publish_data(mqtt_client_t* client, void* arg) {
|
||||
pub_payload[0] = '\0';
|
||||
create_publish_string("*.gif", pub_payload, sizeof(pub_payload));
|
||||
|
||||
err = mqtt_publish(client, "getGifList", pub_payload, strlen(pub_payload), PUBLISH_QOS, PUBLISH_RETAIN, mqtt_pub_request_cb, arg);
|
||||
err = mqtt_publish(client, "getGifList", pub_payload, strlen(pub_payload), PUBLISH_QOS, PUBLISH_RETAIN,
|
||||
mqtt_pub_request_cb, arg);
|
||||
if (err != ERR_OK) {
|
||||
LOG_DEBUG(TAG, "Publish err: %d", err);
|
||||
}
|
||||
@@ -142,8 +139,8 @@ static void mqtt_incoming_data_cb(void* arg, const uint8_t* data, uint16_t len,
|
||||
|
||||
LOG_INFO(TAG, "Incoming publish payload with length %d, flags %d", len, flags);
|
||||
if (!(flags & MQTT_DATA_FLAG_LAST)) {
|
||||
LOG_WARN(TAG, "incoming data too big to fit in buffer.");
|
||||
return;
|
||||
LOG_WARN(TAG, "incoming data too big to fit in buffer.");
|
||||
return;
|
||||
}
|
||||
memcpy(data_buffer, data, len);
|
||||
data_buffer[len] = '\0';
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
*/
|
||||
#include "tcp_cmd.h"
|
||||
|
||||
static uint32_t result_txt = 0xff000000; // Store text color
|
||||
static uint32_t result_bg = 0xff000000; // Store background color
|
||||
static uint32_t result_txt = 0xff000000; // Store text color
|
||||
static uint32_t result_bg = 0xff000000; // Store background color
|
||||
|
||||
static void tcp_cmd_close(struct tcp_pcb* pcb) {
|
||||
tcp_arg(pcb, NULL);
|
||||
@@ -36,7 +36,6 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
|
||||
|
||||
char* endptr;
|
||||
|
||||
|
||||
if (err == ERR_OK && p != NULL) {
|
||||
tcp_recved(pcb, p->tot_len);
|
||||
pc = (char*)p->payload;
|
||||
@@ -48,13 +47,15 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
|
||||
|
||||
if (!strncmp(tcp_buffer, "help", 4)) {
|
||||
check = 1;
|
||||
tcp_write(pcb, "help : laat lijst zien met alle commando's\r\n"
|
||||
"text : geeft tekst mee die op LCD komt (uw_text)\r\n"
|
||||
"color : kleur achtergrond van scherm (255 255 255)\r\n"
|
||||
"textColor : kleur van tekst (255 255 255)\r\n"
|
||||
"listImages: laat een lijst zien van de mogelijke afbeeldingen\r\n"
|
||||
"setImage : veranderd te afbeelding (naam_afbeelding)\r\n"
|
||||
"exit : sluit de verbinding\r\n", 354, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_write(pcb,
|
||||
"help : laat lijst zien met alle commando's\r\n"
|
||||
"text : geeft tekst mee die op LCD komt (uw_text)\r\n"
|
||||
"color : kleur achtergrond van scherm (255 255 255)\r\n"
|
||||
"textColor : kleur van tekst (255 255 255)\r\n"
|
||||
"listImages: laat een lijst zien van de mogelijke afbeeldingen\r\n"
|
||||
"setImage : veranderd te afbeelding (naam_afbeelding)\r\n"
|
||||
"exit : sluit de verbinding\r\n",
|
||||
354, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
} else if (!strncmp(tcp_buffer, "text ", 5)) {
|
||||
size_t i;
|
||||
for (i = 0; i < len - 4; i++) {
|
||||
@@ -64,7 +65,6 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
|
||||
lcd_clear_text();
|
||||
lcd_display_text(text, 10, 10, result_txt, result_bg, LCD_FONT24);
|
||||
|
||||
|
||||
check = 1;
|
||||
} else if (!strncmp(tcp_buffer, "color", 5)) {
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
@@ -96,7 +96,8 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
|
||||
number_of_files = llfs_file_list(file_list, number_of_files, NULL);
|
||||
|
||||
for (size_t i = 0; i < number_of_files; i++) {
|
||||
tcp_write(pcb, file_list[i].name, strlen(file_list[i].name), TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_write(pcb, file_list[i].name, strlen(file_list[i].name),
|
||||
TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_write(pcb, "\r\n", 2, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
}
|
||||
} else {
|
||||
@@ -117,7 +118,7 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
|
||||
|
||||
number_of_files = llfs_file_count();
|
||||
|
||||
if(number_of_files > 0) {
|
||||
if (number_of_files > 0) {
|
||||
llfs_file_t file_list[number_of_files];
|
||||
|
||||
number_of_files = llfs_file_list(file_list, number_of_files, NULL);
|
||||
@@ -154,7 +155,8 @@ static err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t
|
||||
}
|
||||
|
||||
if (!check && (strncmp(tcp_buffer, "\r\n", 2) != 0)) {
|
||||
tcp_write(pcb, "Onbestaand commando: help voor lijst van commando's\r\n", 53, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_write(pcb, "Onbestaand commando: help voor lijst van commando's\r\n", 53,
|
||||
TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
}
|
||||
|
||||
pbuf_free(p);
|
||||
@@ -184,10 +186,12 @@ static err_t tcp_cmd_accept(void* arg, struct tcp_pcb* pcb, err_t err) {
|
||||
tcp_recv(pcb, tcp_cmd_recv);
|
||||
tcp_err(pcb, NULL);
|
||||
tcp_poll(pcb, NULL, 4);
|
||||
tcp_write(pcb, " Welcom bij de TCP CMD Interface\r\n"
|
||||
"(Typ help voor een lijst van de commando's! X om te sluiten)\r\n"
|
||||
"============================================================\r\n"
|
||||
"User: ", 168, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_write(pcb,
|
||||
" Welcom bij de TCP CMD Interface\r\n"
|
||||
"(Typ help voor een lijst van de commando's! X om te sluiten)\r\n"
|
||||
"============================================================\r\n"
|
||||
"User: ",
|
||||
168, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE);
|
||||
tcp_sent(pcb, NULL);
|
||||
return ERR_OK;
|
||||
}
|
||||
@@ -200,4 +204,3 @@ void tcp_cmd_init(void) {
|
||||
tcp_pcb = tcp_listen(tcp_pcb);
|
||||
tcp_accept(tcp_pcb, tcp_cmd_accept);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ static void* tftp_open(const char* fname, const char* mode, uint8_t write);
|
||||
static void tftp_close(void* handle);
|
||||
static int tftp_read(void* handle, void* buf, int bytes);
|
||||
static int tftp_write(void* handle, struct pbuf* p);
|
||||
static struct tftp_context tftpContext_s = {.open = tftp_open, .close = tftp_close, .read = tftp_read, .write = tftp_write};
|
||||
static struct tftp_context tftpContext_s = {.open = tftp_open,
|
||||
.close = tftp_close,
|
||||
.read = tftp_read,
|
||||
.write = tftp_write};
|
||||
/**
|
||||
* @brief tftp custom file functions to set the offset and read the data
|
||||
* @param[in,out] handle Custom file handles
|
||||
@@ -237,7 +240,7 @@ void init_index(void) {
|
||||
for (int i = 0; i < MAX_VIRT_FILES; i++) {
|
||||
len += strlen(virt_file[i].name) + 1;
|
||||
}
|
||||
void* mem = NULL; // Pointer for internal use by the llfs library
|
||||
void* mem = NULL; // Pointer for internal use by the llfs library
|
||||
llfs_file_t* file;
|
||||
while ((file = llfs_next_file(&mem, NULL)) != NULL) {
|
||||
len += strlen(file->name) + 1;
|
||||
|
||||
@@ -14,7 +14,6 @@ static void wbe_decoding_url(const char* encoded, char* decoded);
|
||||
static uint32_t wbe_color_value(const char* rgb);
|
||||
|
||||
void wbe_init(void) {
|
||||
|
||||
httpd_init();
|
||||
LOG_DEBUG("WBE", "Initialize webserver");
|
||||
|
||||
@@ -25,15 +24,13 @@ void wbe_init(void) {
|
||||
}
|
||||
|
||||
int fs_open_custom(struct fs_file* file, const char* name) {
|
||||
|
||||
// Variables
|
||||
llfs_file_t *wanted_file = llfs_file_open(name + 1);
|
||||
llfs_file_t* wanted_file = llfs_file_open(name + 1);
|
||||
size_t buffer_len = 0;
|
||||
static char image_stringbuffer[STR_MAX] = "";
|
||||
|
||||
// The wanted file was found in the filesystem
|
||||
if (wanted_file != NULL) {
|
||||
|
||||
// Debug info
|
||||
LOG_DEBUG("WBE", "The file : %s was found", wanted_file->name);
|
||||
|
||||
@@ -53,7 +50,6 @@ int fs_open_custom(struct fs_file* file, const char* name) {
|
||||
* information string that contains the names of the available images.
|
||||
*/
|
||||
if (strncmp(name, "/images.info", strlen("/images.info")) == 0) {
|
||||
|
||||
// Create the information string for the images in the filesystem
|
||||
buffer_len = wbe_get_images(image_stringbuffer, llfs_file_count());
|
||||
|
||||
@@ -70,7 +66,6 @@ int fs_open_custom(struct fs_file* file, const char* name) {
|
||||
|
||||
// Endpoint when client wants to send information to the backend
|
||||
if (strncmp(name, "/cgi", 3) == 0) {
|
||||
|
||||
// Give the original index.html back to the client
|
||||
wanted_file = llfs_file_open("index.html");
|
||||
|
||||
@@ -84,14 +79,12 @@ int fs_open_custom(struct fs_file* file, const char* name) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void fs_close_custom(struct fs_file* file) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +96,6 @@ void fs_close_custom(struct fs_file* file) {
|
||||
* @param[in] file_count_fs, the number of files in the filesystem
|
||||
*/
|
||||
static size_t wbe_get_images(char* images_string, size_t file_count_fs) {
|
||||
|
||||
// Allocate space for the files
|
||||
llfs_file_t file_list[file_count_fs];
|
||||
|
||||
@@ -137,35 +129,29 @@ static size_t wbe_get_images(char* images_string, size_t file_count_fs) {
|
||||
* @param[in] cnt, the number of files
|
||||
*/
|
||||
static inline void wbe_build_infostring(const llfs_file_t* file_list, char* info_string, const size_t cnt) {
|
||||
|
||||
// Add the filenames to the info string
|
||||
for (size_t i = 0; i < cnt; ++i) {
|
||||
|
||||
strncat(info_string, file_list[i].name, strlen(file_list[i].name));
|
||||
strncat(info_string, "|", 2);
|
||||
}
|
||||
|
||||
//Remove last seperator '|'
|
||||
// Remove last seperator '|'
|
||||
info_string[strlen(info_string) - 1] = '\0';
|
||||
|
||||
}
|
||||
|
||||
void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char** pc_param, char** pc_value) {
|
||||
|
||||
// Variables
|
||||
uint32_t vktxt = LCD_GREEN;
|
||||
uint32_t vka = LCD_BLACK;
|
||||
|
||||
// Allocate space for parameters
|
||||
char vtxt[STR_MAX]; // The sentence that we want to print on the LCD.
|
||||
char vfo[STR_MAX]; // Name of the selected image on the website.
|
||||
char s_vktxt[CLR_MAX]; // The color of the sentence. (in #RGB)
|
||||
char s_vka[CLR_MAX]; // Color of the background. (also in #RGB)
|
||||
char vtxt[STR_MAX]; // The sentence that we want to print on the LCD.
|
||||
char vfo[STR_MAX]; // Name of the selected image on the website.
|
||||
char s_vktxt[CLR_MAX]; // The color of the sentence. (in #RGB)
|
||||
char s_vka[CLR_MAX]; // Color of the background. (also in #RGB)
|
||||
|
||||
if (strcmp("/cgi", uri) == 0) {
|
||||
|
||||
for (size_t i = 0; i < num_parm; ++i) {
|
||||
|
||||
// The given sentence
|
||||
if (strcmp("vtxt", pc_param[i]) == 0) {
|
||||
wbe_decoding_url(pc_value[i], vtxt);
|
||||
@@ -189,7 +175,6 @@ void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char
|
||||
if (s_vka != NULL) {
|
||||
vka = wbe_color_value(s_vka);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Name of the image
|
||||
@@ -203,9 +188,7 @@ void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char
|
||||
|
||||
// Display on LCD
|
||||
wbe_display(vtxt, vktxt, vka, vfo);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,18 +202,15 @@ void httpd_cgi_handler(struct fs_file* file, const char* uri, int num_parm, char
|
||||
* @param[in] decoded, string that will contain the decoded URL.
|
||||
*/
|
||||
static void wbe_decoding_url(const char* encoded, char* decoded) {
|
||||
|
||||
// Variables
|
||||
char *endptr;
|
||||
char* endptr;
|
||||
size_t decoded_index = 0;
|
||||
size_t encoded_length = strlen(encoded);
|
||||
uint32_t hex_val;
|
||||
|
||||
for (size_t i = 0; i < encoded_length; ++i) {
|
||||
|
||||
// If we encounter a %xx, decode it to ascii
|
||||
if ((encoded[i] == '%') && (i + 2 < encoded_length)) {
|
||||
|
||||
// Decode %xx
|
||||
hex_val = (uint32_t)strtoul(&encoded[i + 1], &endptr, 16);
|
||||
|
||||
@@ -246,25 +226,21 @@ static void wbe_decoding_url(const char* encoded, char* decoded) {
|
||||
|
||||
// If we encounter a +, add a space character
|
||||
} else if (encoded[i] == '+') {
|
||||
|
||||
decoded[decoded_index++] = ' ';
|
||||
|
||||
// If no % or +, just put what stands in 'encoded'
|
||||
} else {
|
||||
|
||||
decoded[decoded_index++] = encoded[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Finish the string
|
||||
decoded[decoded_index] = '\0';
|
||||
|
||||
}
|
||||
|
||||
static uint32_t wbe_color_value(const char* rgb) {
|
||||
|
||||
// Variables
|
||||
char *endptr;
|
||||
char* endptr;
|
||||
uint32_t color = LCD_BLACK;
|
||||
char argb[11] = "0xff";
|
||||
|
||||
@@ -284,10 +260,9 @@ static uint32_t wbe_color_value(const char* rgb) {
|
||||
}
|
||||
|
||||
void wbe_display(const char* txt, const uint32_t txt_color, const uint32_t bg_color, const char* image) {
|
||||
|
||||
// Variables
|
||||
lcd_gif_t *gif;
|
||||
const char *extension;
|
||||
lcd_gif_t* gif;
|
||||
const char* extension;
|
||||
|
||||
// clear the screen
|
||||
lcd_clear_text();
|
||||
|
||||
Reference in New Issue
Block a user