Function bodies 25 total
set_ethernet_interface function · cpp · L31-L63 (33 LOC)src/data_manager.cpp
void set_ethernet_interface()
{
net = new EthernetInterface;
if (net == NULL)
{
serial_write(" ## Ethernet memory allocation error.");
ThisThread::sleep_for(osWaitForever);
}
net->set_network(IP, NETMASK, GATEWAY); /* Can be deleted for dynamic IP adress. */
nsapi_size_or_error_t error = net->connect();
if (error != 0)
{
serial_write(" ## Ethernet connection error.");
ThisThread::sleep_for(osWaitForever);
}
net->get_ip_address(&ip);
net->get_netmask(&netmask);
net->get_gateway(&gateway);
ip.set_port(PORT);
const char *ipAddr = ip.get_ip_address();
const char *netmaskAddr = netmask.get_ip_address();
const char *gatewayAddr = gateway.get_ip_address();
string ip_str(ipAddr);
string netmask_str(netmaskAddr);
string gateway_str(gatewayAddr);
serial_write("IP address: " + ip_str);
serial_write("Netmask: " + netmask_str);
serial_write("Gateway: " + gateway_str);
servedata_manager_start_thread function · cpp · L64-L69 (6 LOC)src/data_manager.cpp
void data_manager_start_thread()
{
data_manager_thread.start(data_managing_thread);
serial_write("Data manager thread is started.");
}data_managing_thread function · cpp · L70-L184 (115 LOC)src/data_manager.cpp
void data_managing_thread()
{
std::string incoming_message;
while (true)
{
data_manager_mutex.lock();
nsapi_error_t error = 0;
clientSocket = server.accept(&error);
if (error != 0)
{
serial_write(" ## Connection error.");
}
else
{
clientSocket->getpeername(&clientAddress);
string client_ip(clientAddress.get_ip_address());
serial_write("Connected. IP : " + client_ip);
clientSocket->set_timeout(1000);
error = clientSocket->recv(rxBuf, sizeof(rxBuf));
if (error <= 0)
{
serial_write(" ## Data receive error.");
}
else
{
string received_data(rxBuf);
/* serial_write("Received Data : " + received_data); */
if (received_data.find("refresh_graph") != std::string::npos)
{
string web_string =get_file_name function · cpp · L185-L202 (18 LOC)src/data_manager.cpp
std::string get_file_name(std::string message)
{
int file_name_index = message.find("get_file") + string("get_file").size();
string file_name = message.substr(file_name_index, 20);
while (file_name.length() > 0)
{
if (file_name[file_name.length() - 1] != 't')
{
file_name.erase(file_name.length() - 1, 1);
}
else
{
break;
}
}
return file_name;
}main function · cpp · L24-L38 (15 LOC)src/main.cpp
int main()
{
serial_set_pins(USBTX, USBRX);
set_sd_card(PB_5, PB_4, PB_3, PA_4);
set_time_date();
serial_set_pins_esp_sd(D1, D0);
pwm_generator_set_pins(LED1, D9);
pwm_generator_start_thread();
pwm_capturing_set_pin(D8);
pwm_capturing_start_thread();
set_ethernet_interface();
data_manager_start_thread();
ThisThread::sleep_for(osWaitForever);
}set_time_date function · cpp · L22-L39 (18 LOC)src/pwm_capturing.cpp
void set_time_date()
{
srand(time(NULL));
real_time.day = (rand() % 31) + 1;
real_time.hour = (rand() % 24);
real_time.min = (rand() % 60);
real_time.millisec = 0;
if (real_time.day > 31 || real_time.hour > 23 || real_time.min > 59)
{
serial_write(" ## Time and date logic error.");
}
else
{
serial_write("Time and date is set. : Day : " + to_string(real_time.day) + " Hour : " + to_string(real_time.hour) + ":" + to_string(real_time.min));
}
}pwm_capturing_set_pin function · cpp · L40-L49 (10 LOC)src/pwm_capturing.cpp
void pwm_capturing_set_pin(PinName input_pin)
{
pwm_capture_mutex.lock();
pwm_in = new DigitalIn(input_pin);
input_interrupt = new InterruptIn(input_pin);
input_interrupt->rise(&pwm_input_rise);
pwm_capture_mutex.unlock();
serial_write("PWM input pins are initialized.");
}Want fix-PRs on findings? Install Repobility's GitHub App · github.com/apps/repobility-bot
pwm_capturing_start_thread function · cpp · L50-L62 (13 LOC)src/pwm_capturing.cpp
void pwm_capturing_start_thread()
{
if (pwm_in == NULL || input_interrupt == NULL)
{
serial_write(" ## Null pin error.");
}
else
{
pwm_capture_thread.start(pwm_capturing_thread);
serial_write("PWM capturing thread is started.");
}
}pwm_input_rise function · cpp · L63-L67 (5 LOC)src/pwm_capturing.cpp
void pwm_input_rise()
{
pulse_counter++;
}pwm_capturing_thread function · cpp · L68-L91 (24 LOC)src/pwm_capturing.cpp
void pwm_capturing_thread()
{
rpm_timer.start();
while (true)
{
pwm_capture_mutex.lock();
if (rpm_timer.read_ms() >= CAPTURE_PERIOD)
{
rpm_timer.reset();
int rpm = pulse_counter * 600;
pulse_counter = 0;
rpm_mutex.lock();
rpm_string = to_string(rpm) + "-";
rpm_mutex.unlock();
/* serial_write("rpm : " + to_string(rpm)); */
std::string file_name = to_string(real_time.day) + "_" + to_string(real_time.hour) + "_" + to_string(real_time.min) + CAP_FILE_EXTENTION;
file_append(to_string(rpm) + '-', file_name);
update_time(CAPTURE_PERIOD);
}
pwm_capture_mutex.unlock();
ThisThread::sleep_for(1);
}
}update_time function · cpp · L92-L115 (24 LOC)src/pwm_capturing.cpp
void update_time(int update_period)
{
real_time.millisec += CAPTURE_PERIOD;
if (real_time.millisec >= 60000)
{
real_time.millisec = 0;
real_time.min++;
}
if (real_time.min >= 60)
{
real_time.min = 0;
real_time.hour++;
}
if (real_time.hour >= 24)
{
real_time.hour = 0;
real_time.day++;
}
if (real_time.day >= 31)
{
real_time.day = 1;
}
}pwm_generator_set_pins function · cpp · L21-L29 (9 LOC)src/pwm_generator.cpp
void pwm_generator_set_pins(PinName led_pin, PinName cable_pin)
{
pwm_generate_mutex.lock();
led_pwm_out = new PwmOut(led_pin);
cable_pwm_out = new PwmOut(cable_pin);
pwm_generate_mutex.unlock();
serial_write("PWM generator pins are initialized.");
}pwm_generator_start_thread function · cpp · L30-L42 (13 LOC)src/pwm_generator.cpp
void pwm_generator_start_thread()
{
if (led_pwm_out == NULL || cable_pwm_out == NULL)
{
serial_write(" ## Null pin error.");
}
else
{
pwm_generate_thread.start(pwm_generator_thread);
serial_write("PWM generator thread is started.");
}
}pwm_generator_thread function · cpp · L43-L85 (43 LOC)src/pwm_generator.cpp
void pwm_generator_thread()
{
PWM_PERIOD_DIR pwm_dir = RISING_DIR;
int pwm_period_us = PWM_PERIOD_MIN;
while (true)
{
pwm_generate_mutex.lock();
if (pwm_dir == RISING_DIR)
{
if (pwm_period_us < PWM_PERIOD_MAX)
{
pwm_period_us += 1000;
}
else
{
pwm_dir = FALLING_DIR;
}
}
else if (pwm_dir == FALLING_DIR)
{
if (pwm_period_us > PWM_PERIOD_MIN)
{
pwm_period_us -= 1000;
}
else
{
pwm_dir = RISING_DIR;
}
}
else
{
serial_write(" ## Led direction error.");
}
led_pwm_out->period_us(pwm_period_us);
led_pwm_out->write(0.50f);
cable_pwm_out->period_us(pwm_period_us);
cable_pwm_out->write(0.50f);
pwm_generate_mutex.unlock();
ThisThread::sleset_sd_card function · cpp · L18-L33 (16 LOC)src/sd_manager.cpp
void set_sd_card(PinName mosi, PinName miso, PinName sclk, PinName cs)
{
sd_card.lock();
device = new SDBlockDevice(mosi, miso, sclk, cs);
int err = fs.mount(device);
if (err == 0)
{
serial_write("SD card init OK.");
}
else
{
serial_write(" ## SD card init error!");
}
sd_card.unlock();
}Repobility · severity-and-effort ranking · https://repobility.com
file_read function · cpp · L34-L65 (32 LOC)src/sd_manager.cpp
std::string file_read(std::string file_name, int starting_index, int read_size)
{
sd_card.lock();
std::string ret_str;
file_name = "/fs/" + file_name;
FILE *file = fopen(file_name.c_str(), READ_WRITE);
if (file != NULL)
{
fseek(file, starting_index, SEEK_SET);
while (ret_str.length() < read_size)
{
char temp_char = fgetc(file);
if (temp_char < 255 && temp_char > 0)
{
ret_str += temp_char;
}
else
{
break;
}
}
fclose(file);
}
else
{
serial_write(" ## File opening error. 3");
}
fflush(file);
sd_card.unlock();
return ret_str;
}file_write function · cpp · L66-L87 (22 LOC)src/sd_manager.cpp
void file_write(std::string data, std::string file_name, int starting_index)
{
sd_card.lock();
file_name = "/fs/" + file_name;
FILE *file = fopen(file_name.c_str(), WRITE_CREATE);
if (file != NULL)
{
fseek(file, starting_index, SEEK_SET);
for (int i = 0; i < data.length(); i++)
{
fputc(data[i], file);
}
fclose(file);
}
else
{
serial_write(" ## File opening error. 2");
}
fflush(file);
sd_card.unlock();
}file_append function · cpp · L88-L108 (21 LOC)src/sd_manager.cpp
void file_append(std::string data, std::string file_name)
{
sd_card.lock();
file_name = "/fs/" + file_name;
FILE *file = fopen(file_name.c_str(), APPEND_CREATE);
if (file != NULL)
{
for (int i = 0; i < data.length(); i++)
{
fputc(data[i], file);
}
fclose(file);
}
else
{
serial_write(" ## File opening error. 1");
}
fflush(file);
sd_card.unlock();
}get_file_list function · cpp · L109-L132 (24 LOC)src/sd_manager.cpp
std::vector<std::string> get_file_list(std::string dir_name)
{
sd_card.lock();
std::vector<std::string> ret_list;
dir_name = "/fs/" + dir_name;
DIR *d;
struct dirent *dir;
d = opendir(dir_name.c_str());
if (d)
{
while ((dir = readdir(d)) != NULL)
{
ret_list.push_back(std::string(dir->d_name));
}
closedir(d);
}
else
{
serial_write(" ## Dir opening error.");
}
sd_card.unlock();
return ret_list;
}serial_set_pins function · cpp · L18-L25 (8 LOC)src/serial_output.cpp
void serial_set_pins(PinName tx_pin, PinName rx_pin)
{
serial_mutex.lock();
serial_hardware = new UnbufferedSerial(tx_pin, rx_pin);
serial_mutex.unlock();
serial_write("Serial pins are initialized.");
}serial_set_pins_esp_sd function · cpp · L26-L33 (8 LOC)src/serial_output.cpp
void serial_set_pins_esp_sd(PinName tx_pin, PinName rx_pin)
{
serial_mutex_esp_sd.lock();
serial_hardware_esp_sd = new BufferedSerial(tx_pin, rx_pin, 115200);
serial_mutex_esp_sd.unlock();
serial_write("ES32 SD Serial pins are initialized.");
}serial_write function · cpp · L34-L45 (12 LOC)src/serial_output.cpp
void serial_write(std::string message_p)
{
serial_mutex.lock();
if (serial_hardware != NULL)
{
message_p += "\r\n";
const char *cstr = message_p.c_str();
serial_hardware->write(cstr, strlen(cstr));
}
serial_mutex.unlock();
}serial_write_esp_sd function · cpp · L46-L58 (13 LOC)src/serial_output.cpp
void serial_write_esp_sd(std::string message_p)
{
serial_mutex_esp_sd.lock();
if (serial_hardware_esp_sd != NULL)
{
for (int i = 0; i < message_p.size(); i++)
{
serial_hardware_esp_sd->write((char *)&message_p[i], 1);
}
}
serial_mutex_esp_sd.unlock();
}Repobility · open methodology · https://repobility.com/research/
serial_readable_esp_sd function · cpp · L59-L66 (8 LOC)src/serial_output.cpp
bool serial_readable_esp_sd()
{
serial_mutex_esp_sd.lock();
bool ret_val = serial_hardware_esp_sd->readable();
serial_mutex_esp_sd.unlock();
return ret_val;
}serial_read_esp_sd function · cpp · L67-L88 (22 LOC)src/serial_output.cpp
std::string serial_read_esp_sd(int message_size)
{
serial_mutex_esp_sd.lock();
std::string ret_str = " ## Null serial_hardware_esp_sd error.";
if (serial_hardware_esp_sd != NULL)
{
ret_str = "";
while (serial_hardware_esp_sd->readable() == true)
{
char incoming_char;
serial_hardware_esp_sd->read(&incoming_char, 1);
ret_str += incoming_char;
if (ret_str.size() >= message_size)
{
break;
}
}
}
serial_mutex_esp_sd.unlock();
return ret_str;
}