<commit_before>/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2010 GomSpace ApS (gomspace.com)
Copyright (C) 2010 AAUSAT3 Project (aausat3.space.aau.dk) 

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>

/* CSP includes */
#include <csp/csp.h>
#include <csp/csp_platform.h>

#include "arch/csp_thread.h"
#include "arch/csp_queue.h"
#include "arch/csp_semaphore.h"
#include "arch/csp_malloc.h"
#include "arch/csp_time.h"

#include "csp_port.h"
#include "csp_route.h"
#include "csp_conn.h"
#include "csp_io.h"

/* Static allocation of interfaces */
csp_iface_t iface[17];

/** Connection Fallback
 * This connection is used each time a packet is accepted for routing
 */
static csp_conn_t fallback_conn;

/** csp_route_table_init
 * Initialises the storage for the routing table
 */
void csp_route_table_init(void) {

	/* Clear table */
	memset(iface, 0, sizeof(csp_iface_t) * 17);

	/* Ensure that no traffic is routed until the Router task creates the RX queue */
	fallback_conn.rx_queue = NULL;

}

/** Router Task
 * This task received any non-local connection and collects the data
 * on the connection. All data is forwarded out of the router
 * using the csp_send call 
 */
csp_thread_return_t vTaskCSPRouter(void * pvParameters) {

	csp_packet_t * packet;
	
	/* Create fallback socket  */
    fallback_conn.rx_queue = csp_queue_create(20, sizeof(csp_packet_t *));

    /* Here there be routing */
	while (1) {

		packet = csp_read(&fallback_conn, CSP_MAX_DELAY);

		if (packet == NULL)
			continue;

		csp_debug("Routing packet with id %08X\r\n", packet->id);

		if (!csp_send_direct(packet->id, packet, 0))
			csp_buffer_free(packet);
	}

}

/**
 * Use this function to start the router task.
 * @param task_stack_size The number of portStackType to allocate. This only affects FreeRTOS systems.
 */
void csp_route_start_task(unsigned int task_stack_size) {
    csp_thread_handle_t handle;
    
    int ret = csp_thread_create(vTaskCSPRouter, (signed char *) "RTE", task_stack_size, NULL, 1, &handle);
    <commit_msg>Removed debug message from csp_route, this made the router task require much more stack, and the debug message is rarely used.<commit_after>/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2010 GomSpace ApS (gomspace.com)
Copyright (C) 2010 AAUSAT3 Project (aausat3.space.aau.dk) 

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>

/* CSP includes */
#include <csp/csp.h>
#include <csp/csp_platform.h>

#include "arch/csp_thread.h"
#include "arch/csp_queue.h"
#include "arch/csp_semaphore.h"
#include "arch/csp_malloc.h"
#include "arch/csp_time.h"

#include "csp_port.h"
#include "csp_route.h"
#include "csp_conn.h"
#include "csp_io.h"

/* Static allocation of interfaces */
csp_iface_t iface[17];

/** Connection Fallback
 * This connection is used each time a packet is accepted for routing
 */
static csp_conn_t fallback_conn;

/** csp_route_table_init
 * Initialises the storage for the routing table
 */
void csp_route_table_init(void) {

	/* Clear table */
	memset(iface, 0, sizeof(csp_iface_t) * 17);

	/* Ensure that no traffic is routed until the Router task creates the RX queue */
	fallback_conn.rx_queue = NULL;

}

/** Router Task
 * This task received any non-local connection and collects the data
 * on the connection. All data is forwarded out of the router
 * using the csp_send call 
 */
csp_thread_return_t vTaskCSPRouter(void * pvParameters) {

	csp_packet_t * packet;
	
	/* Create fallback socket  */
    fallback_conn.rx_queue = csp_queue_create(20, sizeof(csp_packet_t *));

    /* Here there be routing */
	while (1) {

		packet = csp_read(&fallback_conn, CSP_MAX_DELAY);

		if (packet == NULL)
			continue;

		if (!csp_send_direct(packet->id, packet, 0))
			csp_buffer_free(packet);
	}

}

/**
 * Use this function to start the router task.
 * @param task_stack_size The number of portStackType to allocate. This only affects FreeRTOS systems.
 */
void csp_route_start_task(unsigned int task_stack_size) {
    csp_thread_handle_t handle;
    
    int ret = csp_thread_create(vTaskCSPRouter, (signed char *) "RTE", task_stack_size, NULL, 1, &handle);
    
{'fraction_non_alphanumeric': 0.08949964763918253, 'fraction_numerical': 0.011980267794221282, 'mean_word_length': 4.3355263157894735, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 18, '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': '2045361', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1826, 'n_words': 664}