<commit_before>/* Copyright 2016-2018 <NAME> ALl Rights Reserved */


#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <string>
#include <sos/dev/sys.h>
#include <sos/fs/sysfs.h>

#define MAX_TRIES 3

#include "fs/File.hpp"
#include "sys/Link.hpp"
#include "sys/Appfs.hpp"
#include "chrono/Timer.hpp"

using namespace sys;
using namespace fs;

static var::String gen_error(const var::String & msg, int err_number){
	var::String s;
	s.sprintf("%s (%d)", msg.cstring(), err_number);
	return s;
}

Link::Link(){
	//check to see if the device is connected -- if it is not connected, connect to it
	m_stdout_fd = -1;
	m_stdin_fd = -1;
	m_lock = 0;
	m_is_bootloader = false;
	m_error_message = "";
	m_driver = &m_driver_instance;
	link_load_default_driver(m_driver);
}

Link::~Link(){}

int Link::check_error(int err){
	switch(err){
		case LINK_PHY_ERROR:
			m_error_message = "Physical Connection Error";
			this->disconnect();
			return LINK_PHY_ERROR;
		case LINK_PROT_ERROR:
			m_error_message = "Protocol Error";
			return LINK_PROT_ERROR;
	}
	return err;
}


void Link::reset_progress(){
	m_progress = 0;
	m_progress_max = 0;
}

var::Vector<var::String> Link::get_port_list(){
	var::Vector<var::String> result;
	var::Data device_name(256);
	var::String last_device;


	while( driver()->getname(
					 device_name.to_char(),
					 last_device.cstring(),
					 static_cast<int>(device_name.capacity())
					 ) == 0 ){
		var::String device_string(
					device_name.to_const_char(),
					var::String::Length(
						strnlen(
							device_name.to_const_char(),
							device_name.size()
							)
						)
					);
		result.push_back( device_string ); //this will make a copy of device name and put it on the list
		last_device = device_string;
	}

	return result;
}

var::Vector<LinkInfo> Link::get_info_list(){
	var::Vector<LinkInfo> result;
	var::Vector<var::String> port_list = get_port_list();

	//disconnect if already connected
	disconnect();

	for(u32 i = 0; i < port_list.count(); i++){
		//ping and grab the info
		if( connect(
					port_list.at(i)
					) < 0 ){
			//couldn't connect
		} else {
			result.push_back(LinkInfo(port_list.at(i), sys_info()));
			//disconnect();
		}
	}<commit_msg>Update Link.cpp<commit_after>/* Copyright 2016-2018 <NAME> ALl Rights Reserved */


#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <string>
#include <sos/dev/sys.h>
#include <sos/fs/sysfs.h>

#define MAX_TRIES 3

#include "fs/File.hpp"
#include "sys/Link.hpp"
#include "sys/Appfs.hpp"
#include "chrono/Timer.hpp"

using namespace sys;
using namespace fs;

static var::String gen_error(const var::String & msg, int err_number){
	var::String s;
	s.sprintf("%s (%d)", msg.cstring(), err_number);
	return s;
}

Link::Link(){
	//check to see if the device is connected -- if it is not connected, connect to it
	m_stdout_fd = -1;
	m_stdin_fd = -1;
	m_lock = 0;
	m_is_bootloader = false;
	m_error_message = "";
	m_driver = &m_driver_instance;
	link_load_default_driver(m_driver);
}

Link::~Link(){}

int Link::check_error(int err){
	switch(err){
		case LINK_PHY_ERROR:
			m_error_message = "Physical Connection Error";
			this->disconnect();
			return LINK_PHY_ERROR;
		case LINK_PROT_ERROR:
			m_error_message = "Protocol Error";
			return LINK_PROT_ERROR;
	}
	return err;
}


void Link::reset_progress(){
	m_progress = 0;
	m_progress_max = 0;
}

var::Vector<var::String> Link::get_port_list(){
	var::Vector<var::String> result;
	var::Data device_name(256);
	var::String last_device;


	while( driver()->getname(
					 device_name.to_char(),
					 last_device.cstring(),
					 static_cast<int>(device_name.capacity())
					 ) == 0 ){
		var::String device_string(
					device_name.to_const_char(),
					var::String::Length(
						strnlen(
							device_name.to_const_char(),
							device_name.size()
							)
						)
					);
		result.push_back( device_string ); //this will make a copy of device name and put it on the list
		last_device = device_string;
	}

	return result;
}

var::Vector<LinkInfo> Link::get_info_list(){
	var::Vector<LinkInfo> result;
	var::Vector<var::String> port_list = get_port_list();

	//disconnect if already connected
	disconnect();

	for(u32 i = 0; i < port_list.count(); i++){
		//ping and grab the info
		if( connect(
					port_list.at(i)
					) < 0 ){
			//couldn't connect
		} else {
			result.push_back(LinkInfo(port_list.at(i), sys_info()));
			disconnect();
		}
	}
{'fraction_non_alphanumeric': 0.1468609865470852, 'fraction_numerical': 0.009865470852017937, 'mean_word_length': 4.052095130237825, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7273090', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1619, 'n_words': 371}