Skip to content

Commit

Permalink
Coding style fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Tzvetomir Stoyanov <[email protected]>
  • Loading branch information
tzstoyanov committed Jan 17, 2024
1 parent 290bb1e commit ef0b04f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 75 deletions.
32 changes: 17 additions & 15 deletions libs/common/api/common_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ extern "C" {
#endif

#ifndef UNUSED
#define UNUSED(x) (void)(x)
#define UNUSED(x) { (void)(x); }
#endif

#define LED_ON {cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);}
#define LED_OFF {cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);}
#define LED_ON { cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1); }
#define LED_OFF { cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0); }
#define param_get(X) base64_decode(X, X ## _len)

bool system_common_init();
void system_common_run();
bool system_common_init(void);
void system_common_run(void);
void mqtt_msg_publish(char *message, bool force);
uint32_t samples_filter(uint32_t *samples, int total_count, int filter_count);
char *get_current_time_str(char *buf, int buflen);
bool tz_datetime_get(datetime_t *date);
float temperature_internal_get();
float temperature_internal_get(void);
void dump_hex_data(char *topic, const uint8_t *data, int len);
void dump_char_data(char *topic, const uint8_t *data, int len);

Expand All @@ -42,19 +42,19 @@ int lcd_clear_cell(int idx);

/* USB API */
bool usb_init(void);
void usb_run();
void usb_run(void);
int usb_send_to_device(int idx, char *buf, int len);
typedef struct {
uint16_t vid; /* Vendor ID */
uint16_t pid; /* Product ID */
}usb_dev_desc_t;
} usb_dev_desc_t;
typedef enum {
CDC_MOUNT,
CDC_UNMOUNT,
HID_MOUNT,
HID_UNMOUNT,
HID_REPORT
}usb_event_t;
} usb_event_t;
typedef void (*usb_event_handler_t) (int idx, usb_event_t event, const void *data, int deta_len, void *context);
int usb_add_known_device(uint16_t vid, uint16_t pid, usb_event_handler_t cb, void *context);

Expand All @@ -70,7 +70,7 @@ enum {
HLOG_INFO,
HLOG_DEBUG
};
bool hlog_remoute();
bool hlog_remoute(void);
#define hlog_info(topic, args...) hlog_any(HLOG_INFO, topic, args)
#define hlog_warning(topic, args...) hlog_any(HLOG_WARN, topic, args)
#define hlog_err(topic, args...) hlog_any(HLOG_ERR, topic, args)
Expand All @@ -82,7 +82,9 @@ bool hlog_remoute();
#define BT_MAX_SERVICES 40
#define BT_UUID128_LEN 16
#define UUID_128_FMT "%0.2X%0.2X%0.2X%0.2X-%0.2X%0.2X-%0.2X%0.2X-%0.2X%0.2X-%0.2X%0.2X%0.2X%0.2X%0.2X%0.2X"
#define UUID_128_PARAM(_XX_) (_XX_)[0],(_XX_)[1],(_XX_)[2],(_XX_)[3],(_XX_)[4],(_XX_)[5],(_XX_)[6],(_XX_)[7],(_XX_)[8],(_XX_)[9],(_XX_)[10],(_XX_)[11],(_XX_)[12],(_XX_)[13],(_XX_)[14],(_XX_)[15]
#define UUID_128_PARAM(_XX_) (_XX_)[0], (_XX_)[1], (_XX_)[2], (_XX_)[3], (_XX_)[4], (_XX_)[5], (_XX_)[6],\
(_XX_)[7], (_XX_)[8], (_XX_)[9], (_XX_)[10], (_XX_)[11], (_XX_)[12], (_XX_)[13],\
(_XX_)[14], (_XX_)[15]
typedef uint8_t bt_addr_t[6];
typedef uint8_t bt_uuid128_t[BT_UUID128_LEN];
typedef enum {
Expand All @@ -92,25 +94,25 @@ typedef enum {
BT_NEW_CHARACTERISTIC,
BT_READY,
BT_VALUE_RECEIVED
}bt_event_t;
} bt_event_t;
typedef struct {
uint32_t svc_id;
bool primary;
uint16_t uuid16;
bt_uuid128_t uuid128;
}bt_service_t;
} bt_service_t;
typedef struct {
uint32_t char_id;
uint32_t properties;
uint16_t uuid16;
bt_uuid128_t uuid128;
}bt_characteristic_t;
} bt_characteristic_t;
typedef struct {
bool val_long;
uint32_t charId;
uint8_t *data;
uint16_t len;
}bt_characteristicvalue_t;
} bt_characteristicvalue_t;
typedef void (*bt_event_handler_t) (int device_idx, bt_event_t event, const void *data, int deta_len, void *context);
int bt_add_known_device(bt_addr_t addr, char *pin, bt_event_handler_t cb, void *context);
int bt_service_get_uuid(uint32_t id, bt_uuid128_t *u128, uint16_t *u16);
Expand Down
2 changes: 1 addition & 1 deletion libs/common/api/usb/tusb_config.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
Expand Down
119 changes: 60 additions & 59 deletions libs/common/src/base64.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***********************************************************
* Base64 library implementation *
* @author Ahmed Elzoughby *
* @date July 23, 2017 *
***********************************************************/
/***********************************************************
* Base64 library implementation *
* @author Ahmed Elzoughby *
* @date July 23, 2017 *
***********************************************************/

#include "base64.h"

Expand All @@ -11,68 +11,69 @@ extern "C" {
#endif

char base46_map[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};

char *base64_encode(const char *plain, int len)
{
char *cipher = malloc(len * 4 / 3 + 4);
unsigned char counts = 0;
char buffer[3];
int i = 0, c = 0;

char* base64_encode(const char *plain, int len) {
for (i = 0; i < len; i++) {
buffer[counts++] = plain[i];
if (counts == 3) {
cipher[c++] = base46_map[buffer[0] >> 2];
cipher[c++] = base46_map[((buffer[0] & 0x03) << 4) + (buffer[1] >> 4)];
cipher[c++] = base46_map[((buffer[1] & 0x0f) << 2) + (buffer[2] >> 6)];
cipher[c++] = base46_map[buffer[2] & 0x3f];
counts = 0;
}
}

unsigned char counts = 0;
char buffer[3];
char* cipher = malloc(len * 4 / 3 + 4);
int i = 0, c = 0;
if (counts > 0) {
cipher[c++] = base46_map[buffer[0] >> 2];
if (counts == 1) {
cipher[c++] = base46_map[(buffer[0] & 0x03) << 4];
cipher[c++] = '=';
} else {
// if counts == 2
cipher[c++] = base46_map[((buffer[0] & 0x03) << 4) + (buffer[1] >> 4)];
cipher[c++] = base46_map[(buffer[1] & 0x0f) << 2];
}
cipher[c++] = '=';
}

for(i = 0; i < len; i++) {
buffer[counts++] = plain[i];
if(counts == 3) {
cipher[c++] = base46_map[buffer[0] >> 2];
cipher[c++] = base46_map[((buffer[0] & 0x03) << 4) + (buffer[1] >> 4)];
cipher[c++] = base46_map[((buffer[1] & 0x0f) << 2) + (buffer[2] >> 6)];
cipher[c++] = base46_map[buffer[2] & 0x3f];
counts = 0;
}
}

if(counts > 0) {
cipher[c++] = base46_map[buffer[0] >> 2];
if(counts == 1) {
cipher[c++] = base46_map[(buffer[0] & 0x03) << 4];
cipher[c++] = '=';
} else { // if counts == 2
cipher[c++] = base46_map[((buffer[0] & 0x03) << 4) + (buffer[1] >> 4)];
cipher[c++] = base46_map[(buffer[1] & 0x0f) << 2];
}
cipher[c++] = '=';
}

cipher[c] = '\0'; /* string padding character */
return cipher;
/* string padding character */
cipher[c] = '\0';
return cipher;
}

char *base64_decode(const char *cipher, int len)
{
char *plain = malloc(len * 3 / 4);
unsigned char counts = 0;
char buffer[4];
int i = 0, p = 0;

char* base64_decode(const char *cipher, int len) {

unsigned char counts = 0;
char buffer[4];
char* plain = malloc(len * 3 / 4);
int i = 0, p = 0;
for (i = 0; i < len; i++) {
unsigned char k;

for(i = 0; i < len; i++) {
unsigned char k;
for(k = 0 ; k < 64 && base46_map[k] != cipher[i]; k++);
buffer[counts++] = k;
if(counts == 4) {
plain[p++] = (buffer[0] << 2) + (buffer[1] >> 4);
if(buffer[2] != 64)
plain[p++] = (buffer[1] << 4) + (buffer[2] >> 2);
if(buffer[3] != 64)
plain[p++] = (buffer[2] << 6) + buffer[3];
counts = 0;
}
}
plain[p] = '\0'; /* string padding character */
return plain;
for (k = 0; k < 64 && base46_map[k] != cipher[i]; k++);
buffer[counts++] = k;
if (counts == 4) {
plain[p++] = (buffer[0] << 2) + (buffer[1] >> 4);
if (buffer[2] != 64)
plain[p++] = (buffer[1] << 4) + (buffer[2] >> 2);
if (buffer[3] != 64)
plain[p++] = (buffer[2] << 6) + buffer[3];
counts = 0;
}
}
plain[p] = '\0'; /* string padding character */
return plain;
}

#ifdef __cplusplus
Expand Down

0 comments on commit ef0b04f

Please sign in to comment.