Skip to content

Commit

Permalink
removed clutter, added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi authored and hegyibalint committed Oct 21, 2017
1 parent d9e8954 commit c570219
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 30 deletions.
6 changes: 2 additions & 4 deletions src/cpp/sensor_monitor/esp32/main/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
static TaskHandle_t task = NULL;
static void networking(void *p) {
char *payload = "ping \n";


double* data;
for (;;) {

mqtt_write(payload, "ping");
Expand Down Expand Up @@ -51,6 +48,7 @@ static void status_callback(esp_mqtt_status_t status) {
switch (status) {
case ESP_MQTT_STATUS_CONNECTED:
esp_mqtt_subscribe("test", 0);
esp_mqtt_subscribe("ping", 0);
xTaskCreatePinnedToCore(networking, "networking", 4096, NULL, 10, &task, 1);
break;
case ESP_MQTT_STATUS_DISCONNECTED:
Expand All @@ -60,7 +58,7 @@ static void status_callback(esp_mqtt_status_t status) {
}

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

static esp_err_t event_handler(void *ctx, system_event_t *event) {
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/sensor_monitor/esp32/main/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#include <esp_mqtt.h>
#include <esp_wifi.h>

#define WIFI_SSID "Router"
#define WIFI_PASS "19670227"
#define WIFI_SSID "SSID"
#define WIFI_PASS "PASS"

#define MQTT_HOST "192.168.1.105"
#define MQTT_HOST "HOST"
#define MQTT_PORT 1883
#define MQTT_USER ""
#define MQTT_PASS ""
Expand Down
26 changes: 5 additions & 21 deletions src/cpp/sensor_monitor/esp32/main/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ static void IRAM_ATTR gpio_isr_handler(void* arg)
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}

typedef struct sens sens;

struct sens{
uint64_t d_time;
uint64_t f_time;
};
uint64_t * carriages; // 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
// |=========1. sensor times=========| |=========0. sensor times=========|
// |t__out| |t__out| |tstart| |tstart| |t__out| |t__out| |tstart| |tstart|
Expand All @@ -36,7 +30,7 @@ void calculate(uint64_t *carriage){
char* payload = (char*)malloc(sizeof(char)*50);
double speed = ((double)SENSOR_DISTANCE) * 100 /dt;
double length = speed * t_block / 100;
sprintf(payload, "speed: %010.3lfcm/s length: %010.3lfcm\n", speed, length);
sprintf(payload, "speed: %010.3lfcm/s length: %010.3lfcm\n", speed, length);
mqtt_write(payload, "test");
}

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

carriages = (uint64_t*)malloc(sizeof(uint64_t)*5);
for(int i = 0; i<5; i++)carriages[i] = 0;
uint8_t a = 0;
uint8_t i = 0;

while (1){
Expand All @@ -63,29 +56,20 @@ static void sensor() {
switch(level[id] - last_level[id]){
case -1: //LOW vezérlés esetén jön a vonat
i = 0;
while(carriages[i] & ((uint64_t)(0b1111111111111111)<<(2*id*16))) {

i++;

}

carriages[i] |= (uint64_t)((uint16_t)(clock() * 100 / CLOCKS_PER_SEC)) << (2*id*16);
while(carriages[i] & ((uint64_t)((1<<16) - 1)<<(2*id*16))) i++;
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
break;
case 1:
i = 0;
while(carriages[i] & ((uint64_t)(0b1111111111111111)<<((2*id+1)*16))) {

i++;
}
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);
while(carriages[i] & ((uint64_t)((1<<16) - 1)<<((2*id+1)*16))) i++;
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
if(is_full(carriages[i])) calculate(&(carriages[i]));
break;
default:
break;
}
time[id] = clock();
last_level[id] = level[id];

}

}
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/sensor_monitor/esp32/main/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#define GPIO_INPUT_IO_1 27
#define GPIO_INPUT_PIN_SEL ((1<<GPIO_INPUT_IO_0) | (1<<GPIO_INPUT_IO_1))
#define ESP_INTR_FLAG_DEFAULT 0
#define EPS 10
#define EPS_MEASURE 200
#define EPS 20
#define EPS_MEASURE 20
#define SENSOR_DISTANCE 7

static void IRAM_ATTR gpio_isr_handler(void*);
Expand Down

0 comments on commit c570219

Please sign in to comment.