Skip to content

Commit c570219

Browse files
leventeBajczihegyibalint
authored andcommitted
removed clutter, added comments
1 parent d9e8954 commit c570219

File tree

4 files changed

+12
-30
lines changed

4 files changed

+12
-30
lines changed

src/cpp/sensor_monitor/esp32/main/network.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
static TaskHandle_t task = NULL;
44
static void networking(void *p) {
55
char *payload = "ping \n";
6-
7-
8-
double* data;
96
for (;;) {
107

118
mqtt_write(payload, "ping");
@@ -51,6 +48,7 @@ static void status_callback(esp_mqtt_status_t status) {
5148
switch (status) {
5249
case ESP_MQTT_STATUS_CONNECTED:
5350
esp_mqtt_subscribe("test", 0);
51+
esp_mqtt_subscribe("ping", 0);
5452
xTaskCreatePinnedToCore(networking, "networking", 4096, NULL, 10, &task, 1);
5553
break;
5654
case ESP_MQTT_STATUS_DISCONNECTED:
@@ -60,7 +58,7 @@ static void status_callback(esp_mqtt_status_t status) {
6058
}
6159

6260
static void message_callback(const char *topic, uint8_t *payload, size_t len) {
63-
//printf("incoming: %s => %s (%d)\n", topic, payload, (int)len);
61+
printf("incoming: %s => %s (%d)\n", topic, payload, (int)len);
6462
}
6563

6664
static esp_err_t event_handler(void *ctx, system_event_t *event) {

src/cpp/sensor_monitor/esp32/main/network.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#include <esp_mqtt.h>
55
#include <esp_wifi.h>
66

7-
#define WIFI_SSID "Router"
8-
#define WIFI_PASS "19670227"
7+
#define WIFI_SSID "SSID"
8+
#define WIFI_PASS "PASS"
99

10-
#define MQTT_HOST "192.168.1.105"
10+
#define MQTT_HOST "HOST"
1111
#define MQTT_PORT 1883
1212
#define MQTT_USER ""
1313
#define MQTT_PASS ""

src/cpp/sensor_monitor/esp32/main/sensor.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ static void IRAM_ATTR gpio_isr_handler(void* arg)
1010
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
1111
}
1212

13-
typedef struct sens sens;
14-
15-
struct sens{
16-
uint64_t d_time;
17-
uint64_t f_time;
18-
};
1913
uint64_t * carriages; // 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
2014
// |=========1. sensor times=========| |=========0. sensor times=========|
2115
// |t__out| |t__out| |tstart| |tstart| |t__out| |t__out| |tstart| |tstart|
@@ -36,7 +30,7 @@ void calculate(uint64_t *carriage){
3630
char* payload = (char*)malloc(sizeof(char)*50);
3731
double speed = ((double)SENSOR_DISTANCE) * 100 /dt;
3832
double length = speed * t_block / 100;
39-
sprintf(payload, "speed: %010.3lfcm/s length: %010.3lfcm\n", speed, length);
33+
sprintf(payload, "speed: %010.3lfcm/s length: %010.3lfcm\n", speed, length);
4034
mqtt_write(payload, "test");
4135
}
4236

@@ -51,7 +45,6 @@ static void sensor() {
5145

5246
carriages = (uint64_t*)malloc(sizeof(uint64_t)*5);
5347
for(int i = 0; i<5; i++)carriages[i] = 0;
54-
uint8_t a = 0;
5548
uint8_t i = 0;
5649

5750
while (1){
@@ -63,29 +56,20 @@ static void sensor() {
6356
switch(level[id] - last_level[id]){
6457
case -1: //LOW vezérlés esetén jön a vonat
6558
i = 0;
66-
while(carriages[i] & ((uint64_t)(0b1111111111111111)<<(2*id*16))) {
67-
68-
i++;
69-
70-
}
71-
72-
carriages[i] |= (uint64_t)((uint16_t)(clock() * 100 / CLOCKS_PER_SEC)) << (2*id*16);
59+
while(carriages[i] & ((uint64_t)((1<<16) - 1)<<(2*id*16))) i++;
60+
carriages[i] |= ((uint64_t)(clock() * 100 / CLOCKS_PER_SEC)) << (2*id*16); //shifting the current time (on 16 bits) to its correct place (in 'centiseconds') -> max is reached after cca 10 minutes
7361
break;
7462
case 1:
7563
i = 0;
76-
while(carriages[i] & ((uint64_t)(0b1111111111111111)<<((2*id+1)*16))) {
77-
78-
i++;
79-
}
80-
carriages[i] |= (uint64_t)((uint64_t)(clock() * 100 / CLOCKS_PER_SEC - (uint64_t)((carriages[i] & ((uint64_t)0b1111111111111111<<(2*id*16)))>>(2*id*16)))) << ((2*id+1)*16);
64+
while(carriages[i] & ((uint64_t)((1<<16) - 1)<<((2*id+1)*16))) i++;
65+
carriages[i] |= ((uint64_t)(clock() * 100 / CLOCKS_PER_SEC - (uint64_t)((carriages[i] & ((uint64_t)((1<<16) - 1)<<(2*id*16)))>>(2*id*16)))) << ((2*id+1)*16); //shifting the time difference (on 16 bits) to its correct place
8166
if(is_full(carriages[i])) calculate(&(carriages[i]));
8267
break;
8368
default:
8469
break;
8570
}
8671
time[id] = clock();
8772
last_level[id] = level[id];
88-
8973
}
9074

9175
}

src/cpp/sensor_monitor/esp32/main/sensor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#define GPIO_INPUT_IO_1 27
1414
#define GPIO_INPUT_PIN_SEL ((1<<GPIO_INPUT_IO_0) | (1<<GPIO_INPUT_IO_1))
1515
#define ESP_INTR_FLAG_DEFAULT 0
16-
#define EPS 10
17-
#define EPS_MEASURE 200
16+
#define EPS 20
17+
#define EPS_MEASURE 20
1818
#define SENSOR_DISTANCE 7
1919

2020
static void IRAM_ATTR gpio_isr_handler(void*);

0 commit comments

Comments
 (0)