issue with makefile
This commit is contained in:
60
libcsp/include/csp/arch/csp_clock.h
Normal file
60
libcsp/include/csp/arch/csp_clock.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_CLOCK_H_
|
||||
#define _CSP_CLOCK_H_
|
||||
|
||||
/**
|
||||
@file
|
||||
|
||||
Clock API.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
Cross-platform timestamp.
|
||||
*/
|
||||
typedef struct {
|
||||
//! Seconds
|
||||
uint32_t tv_sec;
|
||||
//! Nano-seconds.
|
||||
uint32_t tv_nsec;
|
||||
} csp_timestamp_t;
|
||||
|
||||
/**
|
||||
Get time - must be implemented by the user.
|
||||
*/
|
||||
__attribute__((weak)) extern void clock_get_time(csp_timestamp_t * time);
|
||||
|
||||
/**
|
||||
Set time - must be implemented by the user.
|
||||
*/
|
||||
__attribute__((weak)) extern void clock_set_time(csp_timestamp_t * time);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_CLOCK_H_
|
39
libcsp/include/csp/arch/csp_malloc.h
Normal file
39
libcsp/include/csp/arch/csp_malloc.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_MALLOC_H_
|
||||
#define _CSP_MALLOC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void * csp_malloc(size_t size);
|
||||
void csp_free(void * ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_MALLOC_H_
|
49
libcsp/include/csp/arch/csp_queue.h
Normal file
49
libcsp/include/csp/arch/csp_queue.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_QUEUE_H_
|
||||
#define _CSP_QUEUE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CSP_QUEUE_FULL 0
|
||||
#define CSP_QUEUE_ERROR 0
|
||||
#define CSP_QUEUE_OK 1
|
||||
typedef void * csp_queue_handle_t;
|
||||
|
||||
#include <stdint.h>
|
||||
#include <csp/csp.h>
|
||||
|
||||
csp_queue_handle_t csp_queue_create(int length, size_t item_size);
|
||||
void csp_queue_remove(csp_queue_handle_t queue);
|
||||
int csp_queue_enqueue(csp_queue_handle_t handle, void *value, uint32_t timeout);
|
||||
int csp_queue_enqueue_isr(csp_queue_handle_t handle, void * value, CSP_BASE_TYPE * task_woken);
|
||||
int csp_queue_dequeue(csp_queue_handle_t handle, void *buf, uint32_t timeout);
|
||||
int csp_queue_dequeue_isr(csp_queue_handle_t handle, void * buf, CSP_BASE_TYPE * task_woken);
|
||||
int csp_queue_size(csp_queue_handle_t handle);
|
||||
int csp_queue_size_isr(csp_queue_handle_t handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_QUEUE_H_
|
109
libcsp/include/csp/arch/csp_semaphore.h
Normal file
109
libcsp/include/csp/arch/csp_semaphore.h
Normal file
@ -0,0 +1,109 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_SEMAPHORE_H_
|
||||
#define _CSP_SEMAPHORE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <csp/csp.h>
|
||||
|
||||
/* POSIX interface */
|
||||
#if defined(CSP_POSIX)
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#define CSP_SEMAPHORE_OK 1
|
||||
#define CSP_SEMAPHORE_ERROR 2
|
||||
#define CSP_MUTEX_OK CSP_SEMAPHORE_OK
|
||||
#define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
|
||||
|
||||
typedef sem_t csp_bin_sem_handle_t;
|
||||
typedef pthread_mutex_t csp_mutex_t;
|
||||
|
||||
#endif // CSP_POSIX
|
||||
|
||||
/* MAC OS X interface */
|
||||
#if defined(CSP_MACOSX)
|
||||
|
||||
#include <pthread.h>
|
||||
#include "posix/pthread_queue.h"
|
||||
|
||||
#define CSP_SEMAPHORE_OK PTHREAD_QUEUE_OK
|
||||
#define CSP_SEMAPHORE_ERROR PTHREAD_QUEUE_EMPTY
|
||||
#define CSP_MUTEX_OK CSP_SEMAPHORE_OK
|
||||
#define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
|
||||
|
||||
typedef pthread_queue_t * csp_bin_sem_handle_t;
|
||||
typedef pthread_queue_t * csp_mutex_t;
|
||||
|
||||
#endif // CSP_MACOSX
|
||||
|
||||
#if defined(CSP_WINDOWS)
|
||||
|
||||
#include <Windows.h>
|
||||
#undef interface
|
||||
|
||||
#define CSP_SEMAPHORE_OK 1
|
||||
#define CSP_SEMAPHORE_ERROR 2
|
||||
#define CSP_MUTEX_OK CSP_SEMAPHORE_OK
|
||||
#define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
|
||||
|
||||
typedef HANDLE csp_bin_sem_handle_t;
|
||||
typedef HANDLE csp_mutex_t;
|
||||
|
||||
#endif
|
||||
|
||||
/* FreeRTOS interface */
|
||||
#if defined(CSP_FREERTOS)
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <semphr.h>
|
||||
|
||||
#define CSP_SEMAPHORE_OK pdPASS
|
||||
#define CSP_SEMAPHORE_ERROR pdFAIL
|
||||
#define CSP_MUTEX_OK CSP_SEMAPHORE_OK
|
||||
#define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
|
||||
|
||||
typedef xSemaphoreHandle csp_bin_sem_handle_t;
|
||||
typedef xSemaphoreHandle csp_mutex_t;
|
||||
|
||||
#endif // CSP_FREERTOS
|
||||
|
||||
int csp_mutex_create(csp_mutex_t * mutex);
|
||||
int csp_mutex_remove(csp_mutex_t * mutex);
|
||||
int csp_mutex_lock(csp_mutex_t * mutex, uint32_t timeout);
|
||||
int csp_mutex_unlock(csp_mutex_t * mutex);
|
||||
int csp_bin_sem_create(csp_bin_sem_handle_t * sem);
|
||||
int csp_bin_sem_remove(csp_bin_sem_handle_t * sem);
|
||||
int csp_bin_sem_wait(csp_bin_sem_handle_t * sem, uint32_t timeout);
|
||||
int csp_bin_sem_post(csp_bin_sem_handle_t * sem);
|
||||
int csp_bin_sem_post_isr(csp_bin_sem_handle_t * sem, CSP_BASE_TYPE * task_woken);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_SEMAPHORE_H_
|
74
libcsp/include/csp/arch/csp_system.h
Normal file
74
libcsp/include/csp/arch/csp_system.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_SYSTEM_H_
|
||||
#define _CSP_SYSTEM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define COLOR_MASK_COLOR 0x0F
|
||||
#define COLOR_MASK_MODIFIER 0xF0
|
||||
|
||||
typedef enum {
|
||||
/* Colors */
|
||||
COLOR_RESET = 0xF0,
|
||||
COLOR_BLACK = 0x01,
|
||||
COLOR_RED = 0x02,
|
||||
COLOR_GREEN = 0x03,
|
||||
COLOR_YELLOW = 0x04,
|
||||
COLOR_BLUE = 0x05,
|
||||
COLOR_MAGENTA = 0x06,
|
||||
COLOR_CYAN = 0x07,
|
||||
COLOR_WHITE = 0x08,
|
||||
/* Modifiers */
|
||||
COLOR_NORMAL = 0x0F,
|
||||
COLOR_BOLD = 0x10,
|
||||
COLOR_UNDERLINE = 0x20,
|
||||
COLOR_BLINK = 0x30,
|
||||
COLOR_HIDE = 0x40,
|
||||
} csp_color_t;
|
||||
|
||||
/**
|
||||
* Writes out a task list into a pre-allocate buffer,
|
||||
* use csp_sys_tasklist_size to get sizeof buffer to allocate
|
||||
* @param out pointer to output buffer
|
||||
* @return
|
||||
*/
|
||||
int csp_sys_tasklist(char * out);
|
||||
|
||||
/**
|
||||
* @return Size of tasklist buffer to allocate for the csp_sys_tasklist call
|
||||
*/
|
||||
int csp_sys_tasklist_size(void);
|
||||
|
||||
uint32_t csp_sys_memfree(void);
|
||||
int csp_sys_reboot(void);
|
||||
int csp_sys_shutdown(void);
|
||||
void csp_sys_set_color(csp_color_t color);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_SYSTEM_H_
|
100
libcsp/include/csp/arch/csp_thread.h
Normal file
100
libcsp/include/csp/arch/csp_thread.h
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_THREAD_H_
|
||||
#define _CSP_THREAD_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <csp/csp.h>
|
||||
|
||||
/* POSIX interface */
|
||||
#if defined(CSP_POSIX) || defined(CSP_MACOSX)
|
||||
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define csp_thread_exit() pthread_exit(NULL)
|
||||
|
||||
typedef pthread_t csp_thread_handle_t;
|
||||
typedef void * csp_thread_return_t;
|
||||
|
||||
#define CSP_DEFINE_TASK(task_name) csp_thread_return_t task_name(void * param)
|
||||
#define CSP_TASK_RETURN NULL
|
||||
|
||||
#define csp_sleep_ms(time_ms) usleep(time_ms * 1000);
|
||||
|
||||
#endif // CSP_POSIX
|
||||
|
||||
/* Windows interface */
|
||||
#if defined(CSP_WINDOWS)
|
||||
|
||||
#include <Windows.h>
|
||||
#undef interface
|
||||
#include <process.h>
|
||||
|
||||
#define csp_thread_exit() _endthreadex(0)
|
||||
|
||||
typedef HANDLE csp_thread_handle_t;
|
||||
typedef unsigned int csp_thread_return_t;
|
||||
|
||||
#define CSP_DEFINE_TASK(task_name) csp_thread_return_t __attribute__((stdcall)) task_name(void * param)
|
||||
#define CSP_TASK_RETURN 0
|
||||
|
||||
#define csp_sleep_ms(time_ms) Sleep(time_ms);
|
||||
|
||||
#endif // CSP_WINDOWS
|
||||
|
||||
/* FreeRTOS interface */
|
||||
#if defined(CSP_FREERTOS)
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#if INCLUDE_vTaskDelete
|
||||
#define csp_thread_exit() vTaskDelete(NULL)
|
||||
#else
|
||||
#define csp_thread_exit()
|
||||
#endif
|
||||
|
||||
typedef xTaskHandle csp_thread_handle_t;
|
||||
typedef void csp_thread_return_t;
|
||||
|
||||
#define CSP_DEFINE_TASK(task_name) csp_thread_return_t task_name(void * param)
|
||||
#define CSP_TASK_RETURN
|
||||
|
||||
#define csp_sleep_ms(time_ms) vTaskDelay(time_ms / portTICK_RATE_MS);
|
||||
|
||||
#endif // CSP_FREERTOS
|
||||
|
||||
#ifndef CSP_WINDOWS
|
||||
int csp_thread_create(csp_thread_return_t (* routine)(void *), const char * const thread_name, unsigned short stack_depth, void * parameters, unsigned int priority, csp_thread_handle_t * handle);
|
||||
#else
|
||||
int csp_thread_create(csp_thread_return_t (* routine)(void *)__attribute__((stdcall)), const char * const thread_name, unsigned short stack_depth, void * parameters, unsigned int priority, csp_thread_handle_t * handle);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_THREAD_H_
|
57
libcsp/include/csp/arch/csp_time.h
Normal file
57
libcsp/include/csp/arch/csp_time.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_TIME_H_
|
||||
#define _CSP_TIME_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <csp/csp.h>
|
||||
|
||||
/* Blackfin/x86 on Linux */
|
||||
#if defined(CSP_POSIX)
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#endif // CSP_POSIX
|
||||
|
||||
/* AVR/ARM on FreeRTOS */
|
||||
#if defined(CSP_FREERTOS)
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#endif // CSP_FREERTOS
|
||||
|
||||
uint32_t csp_get_ms(void);
|
||||
uint32_t csp_get_ms_isr(void);
|
||||
uint32_t csp_get_s(void);
|
||||
uint32_t csp_get_s_isr(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_TIME_H_
|
118
libcsp/include/csp/arch/posix/pthread_queue.h
Normal file
118
libcsp/include/csp/arch/posix/pthread_queue.h
Normal file
@ -0,0 +1,118 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _PTHREAD_QUEUE_H_
|
||||
#define _PTHREAD_QUEUE_H_
|
||||
|
||||
/**
|
||||
@file
|
||||
|
||||
Queue implemented using pthread locks and conds.
|
||||
|
||||
Inspired by c-pthread-queue by Matthew Dickinson: http://code.google.com/p/c-pthread-queue/
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <csp/arch/csp_queue.h>
|
||||
|
||||
/**
|
||||
Queue error codes.
|
||||
@{
|
||||
*/
|
||||
/**
|
||||
General error code - something went wrong.
|
||||
*/
|
||||
#define PTHREAD_QUEUE_ERROR CSP_QUEUE_ERROR
|
||||
/**
|
||||
Queue is empty - cannot extract element.
|
||||
*/
|
||||
#define PTHREAD_QUEUE_EMPTY CSP_QUEUE_ERROR
|
||||
/**
|
||||
Queue is full - cannot insert element.
|
||||
*/
|
||||
#define PTHREAD_QUEUE_FULL CSP_QUEUE_ERROR
|
||||
/**
|
||||
Ok - no error.
|
||||
*/
|
||||
#define PTHREAD_QUEUE_OK CSP_QUEUE_OK
|
||||
/** @{ */
|
||||
|
||||
/**
|
||||
Queue handle.
|
||||
*/
|
||||
typedef struct pthread_queue_s {
|
||||
//! Memory area.
|
||||
void * buffer;
|
||||
//! Memory size.
|
||||
int size;
|
||||
//! Item/element size.
|
||||
int item_size;
|
||||
//! Items/elements in queue.
|
||||
int items;
|
||||
//! Insert point.
|
||||
int in;
|
||||
//! Extract point.
|
||||
int out;
|
||||
//! Lock.
|
||||
pthread_mutex_t mutex;
|
||||
//! Wait because queue is full (insert).
|
||||
pthread_cond_t cond_full;
|
||||
//! Wait because queue is empty (extract).
|
||||
pthread_cond_t cond_empty;
|
||||
} pthread_queue_t;
|
||||
|
||||
/**
|
||||
Create queue.
|
||||
*/
|
||||
pthread_queue_t * pthread_queue_create(int length, size_t item_size);
|
||||
|
||||
/**
|
||||
Delete queue.
|
||||
*/
|
||||
void pthread_queue_delete(pthread_queue_t * q);
|
||||
|
||||
/**
|
||||
Enqueue/insert element.
|
||||
*/
|
||||
int pthread_queue_enqueue(pthread_queue_t * queue, void * value, uint32_t timeout);
|
||||
|
||||
/**
|
||||
Dequeue/extract element.
|
||||
*/
|
||||
int pthread_queue_dequeue(pthread_queue_t * queue, void * buf, uint32_t timeout);
|
||||
|
||||
/**
|
||||
Return number of elements in the queue.
|
||||
*/
|
||||
int pthread_queue_items(pthread_queue_t * queue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _PTHREAD_QUEUE_H_
|
||||
|
73
libcsp/include/csp/crypto/csp_hmac.h
Normal file
73
libcsp/include/csp/crypto/csp_hmac.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_HMAC_H_
|
||||
#define _CSP_HMAC_H_
|
||||
|
||||
#include <csp/csp_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CSP_HMAC_LENGTH 4
|
||||
|
||||
/**
|
||||
* Append HMAC to packet
|
||||
* @param packet Pointer to packet
|
||||
* @param include_header use header in hmac calculation (this will not modify the flags field)
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
int csp_hmac_append(csp_packet_t * packet, bool include_header);
|
||||
|
||||
/**
|
||||
* Verify HMAC of packet
|
||||
* @param packet Pointer to packet
|
||||
* @param include_header use header in hmac calculation (this will not modify the flags field)
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
int csp_hmac_verify(csp_packet_t * packet, bool include_header);
|
||||
|
||||
/**
|
||||
* Calculate HMAC on buffer
|
||||
*
|
||||
* This function is used by append/verify but cal also be called separately.
|
||||
* @param key HMAC key
|
||||
* @param keylen HMAC key length
|
||||
* @param data pointer to data
|
||||
* @param datalen lehgth of data
|
||||
* @param hmac output HMAC calculation (CSP_HMAC_LENGTH)
|
||||
* @return 0 on success, negative on failure
|
||||
*/
|
||||
int csp_hmac_memory(const uint8_t * key, uint32_t keylen, const uint8_t * data, uint32_t datalen, uint8_t * hmac);
|
||||
|
||||
/**
|
||||
* Save a copy of the key string for use by the append/verify functions
|
||||
* @param key HMAC key
|
||||
* @param keylen HMAC key length
|
||||
* @return Always returns 0
|
||||
*/
|
||||
int csp_hmac_set_key(char * key, uint32_t keylen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_HMAC_H_
|
81
libcsp/include/csp/crypto/csp_sha1.h
Normal file
81
libcsp/include/csp/crypto/csp_sha1.h
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_SHA1_H_
|
||||
#define _CSP_SHA1_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The SHA1 block and message digest size in bytes */
|
||||
#define SHA1_BLOCKSIZE 64
|
||||
#define SHA1_DIGESTSIZE 20
|
||||
|
||||
/**
|
||||
SHA1 state structure
|
||||
*/
|
||||
typedef struct {
|
||||
//! Internal SHA1 state.
|
||||
uint64_t length;
|
||||
//! Internal SHA1 state.
|
||||
uint32_t state[5];
|
||||
//! Internal SHA1 state.
|
||||
uint32_t curlen;
|
||||
//! Internal SHA1 state.
|
||||
uint8_t buf[SHA1_BLOCKSIZE];
|
||||
} csp_sha1_state;
|
||||
|
||||
/**
|
||||
* Initialize the hash state
|
||||
* @param sha1 The hash state you wish to initialize
|
||||
*/
|
||||
void csp_sha1_init(csp_sha1_state * sha1);
|
||||
|
||||
/**
|
||||
* Process a block of memory though the hash
|
||||
* @param sha1 The hash state
|
||||
* @param in The data to hash
|
||||
* @param inlen The length of the data (octets)
|
||||
*/
|
||||
void csp_sha1_process(csp_sha1_state * sha1, const uint8_t * in, uint32_t inlen);
|
||||
|
||||
/**
|
||||
* Terminate the hash to get the digest
|
||||
* @param sha1 The hash state
|
||||
* @param out [out] The destination of the hash (20 bytes)
|
||||
*/
|
||||
void csp_sha1_done(csp_sha1_state * sha1, uint8_t * out);
|
||||
|
||||
/**
|
||||
* Calculate SHA1 hash of block of memory.
|
||||
* @param msg Pointer to message buffer
|
||||
* @param len Length of message
|
||||
* @param sha1 Pointer to SHA1 output buffer. Must be 20 bytes or more!
|
||||
*/
|
||||
void csp_sha1_memory(const uint8_t * msg, uint32_t len, uint8_t * hash);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_SHA1_H_
|
52
libcsp/include/csp/crypto/csp_xtea.h
Normal file
52
libcsp/include/csp/crypto/csp_xtea.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_XTEA_H_
|
||||
#define _CSP_XTEA_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CSP_XTEA_IV_LENGTH 8
|
||||
|
||||
/**
|
||||
* XTEA encrypt byte array
|
||||
* @param plain Pointer to plain text
|
||||
* @param len Length of plain text
|
||||
* @param iv Initialization vector
|
||||
*/
|
||||
int csp_xtea_encrypt(uint8_t * plain, const uint32_t len, uint32_t iv[2]);
|
||||
|
||||
/**
|
||||
* Decrypt XTEA encrypted byte array
|
||||
* @param cipher Pointer to cipher text
|
||||
* @param len Length of plain text
|
||||
* @param iv Initialization vector
|
||||
*/
|
||||
int csp_xtea_decrypt(uint8_t * cipher, const uint32_t len, uint32_t iv[2]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_XTEA_H_
|
545
libcsp/include/csp/csp.h
Normal file
545
libcsp/include/csp/csp.h
Normal file
@ -0,0 +1,545 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_H_
|
||||
#define _CSP_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes */
|
||||
#include <stdint.h>
|
||||
|
||||
#include <csp/csp_autoconfig.h>
|
||||
|
||||
/* CSP includes */
|
||||
#include "csp_types.h"
|
||||
#include "csp_platform.h"
|
||||
#include "csp_error.h"
|
||||
#include "csp_debug.h"
|
||||
#include "csp_buffer.h"
|
||||
#include "csp_rtable.h"
|
||||
#include "csp_iflist.h"
|
||||
|
||||
/** csp_init
|
||||
* Start up the can-space protocol
|
||||
* @param my_node_address The CSP node address
|
||||
*/
|
||||
int csp_init(uint8_t my_node_address);
|
||||
|
||||
/** csp_set_address
|
||||
* Set the systems own address
|
||||
* @param addr The new address of the system
|
||||
*/
|
||||
void csp_set_address(uint8_t addr);
|
||||
|
||||
/** csp_get_address
|
||||
* Get the systems own address
|
||||
* @return The current address of the system
|
||||
*/
|
||||
uint8_t csp_get_address(void);
|
||||
|
||||
/** csp_set_hostname
|
||||
* Set subsystem hostname.
|
||||
* This function takes a pointer to a string, which should remain static
|
||||
* @param hostname Hostname to set
|
||||
*/
|
||||
void csp_set_hostname(const char *hostname);
|
||||
|
||||
/** csp_get_hostname
|
||||
* Get current subsystem hostname.
|
||||
* @return Pointer to char array with current hostname.
|
||||
*/
|
||||
const char *csp_get_hostname(void);
|
||||
|
||||
/** csp_set_model
|
||||
* Set subsystem model name.
|
||||
* This function takes a pointer to a string, which should remain static
|
||||
* @param model Model name to set
|
||||
*/
|
||||
void csp_set_model(const char *model);
|
||||
|
||||
/** csp_get_model
|
||||
* Get current model name.
|
||||
* @return Pointer to char array with current model name.
|
||||
*/
|
||||
const char *csp_get_model(void);
|
||||
|
||||
/** csp_set_revision
|
||||
* Set subsystem revision. This can be used to override the CMP revision field.
|
||||
* This function takes a pointer to a string, which should remain static
|
||||
* @param revision Revision name to set
|
||||
*/
|
||||
void csp_set_revision(const char *revision);
|
||||
|
||||
/** csp_get_revision
|
||||
* Get subsystem revision.
|
||||
* @return Pointer to char array with software revision.
|
||||
*/
|
||||
const char *csp_get_revision(void);
|
||||
|
||||
/** csp_socket
|
||||
* Create CSP socket endpoint
|
||||
* @param opts Socket options
|
||||
* @return Pointer to socket on success, NULL on failure
|
||||
*/
|
||||
csp_socket_t *csp_socket(uint32_t opts);
|
||||
|
||||
/**
|
||||
* Wait for a new connection on a socket created by csp_socket
|
||||
* @param socket Socket to accept connections on
|
||||
* @param timeout use CSP_MAX_DELAY for infinite timeout
|
||||
* @return Return pointer to csp_conn_t or NULL if timeout was reached
|
||||
*/
|
||||
csp_conn_t *csp_accept(csp_socket_t *socket, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Read data from a connection
|
||||
* This fuction uses the RX queue of a connection to receive a packet
|
||||
* If no packet is available and a timeout has been specified
|
||||
* The call will block.
|
||||
* Do NOT call this from ISR
|
||||
* @param conn pointer to connection
|
||||
* @param timeout timeout in ms, use CSP_MAX_DELAY for infinite blocking time
|
||||
* @return Returns pointer to csp_packet_t, which you MUST free yourself, either by calling csp_buffer_free() or reusing the buffer for a new csp_send.
|
||||
*/
|
||||
csp_packet_t *csp_read(csp_conn_t *conn, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Send a packet on an already established connection
|
||||
* @param conn pointer to connection
|
||||
* @param packet pointer to packet,
|
||||
* @param timeout a timeout to wait for TX to complete. NOTE: not all underlying drivers supports flow-control.
|
||||
* @return returns 1 if successful and 0 otherwise. you MUST free the frame yourself if the transmission was not successful.
|
||||
*/
|
||||
int csp_send(csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Send a packet on an already established connection, and change the default priority of the connection
|
||||
*
|
||||
* @note When using this function, the priority of the connection will change. If you need to change it back
|
||||
* use another call to csp_send_prio, or ensure that all packets sent on a given connection is using send_prio call.
|
||||
*
|
||||
* @param prio csp priority
|
||||
* @param conn pointer to connection
|
||||
* @param packet pointer to packet,
|
||||
* @param timeout a timeout to wait for TX to complete. NOTE: not all underlying drivers supports flow-control.
|
||||
* @return returns 1 if successful and 0 otherwise. you MUST free the frame yourself if the transmission was not successful.
|
||||
*/
|
||||
int csp_send_prio(uint8_t prio, csp_conn_t *conn, csp_packet_t *packet, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Perform an entire request/reply transaction
|
||||
* Copies both input buffer and reply to output buffeer.
|
||||
* Also makes the connection and closes it again
|
||||
* @param prio CSP Prio
|
||||
* @param dest CSP Dest
|
||||
* @param port CSP Port
|
||||
* @param timeout timeout in ms
|
||||
* @param outbuf pointer to outgoing data buffer
|
||||
* @param outlen length of request to send
|
||||
* @param inbuf pointer to incoming data buffer
|
||||
* @param inlen length of expected reply, -1 for unknown size (note inbuf MUST be large enough)
|
||||
* @return Return 1 or reply size if successful, 0 if error or incoming length does not match or -1 if timeout was reached
|
||||
*/
|
||||
int csp_transaction(uint8_t prio, uint8_t dest, uint8_t port, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen);
|
||||
|
||||
/**
|
||||
* Perform an entire request/reply transaction
|
||||
* Copies both input buffer and reply to output buffeer.
|
||||
* Also makes the connection and closes it again
|
||||
* @param prio CSP Prio
|
||||
* @param dest CSP Dest
|
||||
* @param port CSP Port
|
||||
* @param timeout timeout in ms
|
||||
* @param outbuf pointer to outgoing data buffer
|
||||
* @param outlen length of request to send
|
||||
* @param inbuf pointer to incoming data buffer
|
||||
* @param inlen length of expected reply, -1 for unknown size (note inbuf MUST be large enough)
|
||||
* @param opts Connection options.
|
||||
* @return Return 1 or reply size if successful, 0 if error or incoming length does not match or -1 if timeout was reached
|
||||
*/
|
||||
int csp_transaction2(uint8_t prio, uint8_t dest, uint8_t port, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen, uint32_t opts);
|
||||
|
||||
/**
|
||||
* Use an existing connection to perform a transaction,
|
||||
* This is only possible if the next packet is on the same port and destination!
|
||||
* @param conn pointer to connection structure
|
||||
* @param timeout timeout in ms
|
||||
* @param outbuf pointer to outgoing data buffer
|
||||
* @param outlen length of request to send
|
||||
* @param inbuf pointer to incoming data buffer
|
||||
* @param inlen length of expected reply, -1 for unknown size (note inbuf MUST be large enough)
|
||||
* @return
|
||||
*/
|
||||
int csp_transaction_persistent(csp_conn_t *conn, uint32_t timeout, void *outbuf, int outlen, void *inbuf, int inlen);
|
||||
|
||||
/**
|
||||
* Read data from a connection-less server socket
|
||||
* This fuction uses the socket directly to receive a frame
|
||||
* If no packet is available and a timeout has been specified the call will block.
|
||||
* Do NOT call this from ISR
|
||||
* @return Returns pointer to csp_packet_t, which you MUST free yourself, either by calling csp_buffer_free() or reusing the buffer for a new csp_send.
|
||||
*/
|
||||
csp_packet_t *csp_recvfrom(csp_socket_t *socket, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Send a packet without previously opening a connection
|
||||
* @param prio CSP_PRIO_x
|
||||
* @param dest destination node
|
||||
* @param dport destination port
|
||||
* @param src_port source port
|
||||
* @param opts CSP_O_x
|
||||
* @param packet pointer to packet
|
||||
* @param timeout timeout used by interfaces with blocking send
|
||||
* @return -1 if error (you must free packet), 0 if OK (you must discard pointer)
|
||||
*/
|
||||
int csp_sendto(uint8_t prio, uint8_t dest, uint8_t dport, uint8_t src_port, uint32_t opts, csp_packet_t *packet, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Send a packet as a direct reply to the source of an incoming packet,
|
||||
* but still without holding an entire connection
|
||||
* @param request_packet pointer to packet to reply to
|
||||
* @param reply_packet actual reply data
|
||||
* @param opts CSP_O_x
|
||||
* @param timeout timeout used by interfaces with blocking send
|
||||
* @return -1 if error (you must free packet), 0 if OK (you must discard pointer)
|
||||
*/
|
||||
int csp_sendto_reply(csp_packet_t * request_packet, csp_packet_t * reply_packet, uint32_t opts, uint32_t timeout);
|
||||
|
||||
/** csp_connect
|
||||
* Used to establish outgoing connections
|
||||
* This function searches the port table for free slots and finds an unused
|
||||
* connection from the connection pool
|
||||
* There is no handshake in the CSP protocol
|
||||
* @param prio Connection priority.
|
||||
* @param dest Destination address.
|
||||
* @param dport Destination port.
|
||||
* @param timeout Timeout in ms.
|
||||
* @param opts Connection options.
|
||||
* @return a pointer to a new connection or NULL
|
||||
*/
|
||||
csp_conn_t *csp_connect(uint8_t prio, uint8_t dest, uint8_t dport, uint32_t timeout, uint32_t opts);
|
||||
|
||||
/** csp_close
|
||||
* Closes a given connection and frees buffers used.
|
||||
* @param conn pointer to connection structure
|
||||
* @return CSP_ERR_NONE if connection was closed. Otherwise, an err code is returned.
|
||||
*/
|
||||
int csp_close(csp_conn_t *conn);
|
||||
|
||||
/**
|
||||
* @param conn pointer to connection structure
|
||||
* @return destination port of an incoming connection
|
||||
*/
|
||||
int csp_conn_dport(csp_conn_t *conn);
|
||||
|
||||
/**
|
||||
* @param conn pointer to connection structure
|
||||
* @return source port of an incoming connection
|
||||
*/
|
||||
int csp_conn_sport(csp_conn_t *conn);
|
||||
|
||||
/**
|
||||
* @param conn pointer to connection structure
|
||||
* @return destination address of an incoming connection
|
||||
*/
|
||||
int csp_conn_dst(csp_conn_t *conn);
|
||||
|
||||
/**
|
||||
* @param conn pointer to connection structure
|
||||
* @return source address of an incoming connection
|
||||
*/
|
||||
int csp_conn_src(csp_conn_t *conn);
|
||||
|
||||
/**
|
||||
* @param conn pointer to connection structure
|
||||
* @return flags field of an incoming connection
|
||||
*/
|
||||
int csp_conn_flags(csp_conn_t *conn);
|
||||
|
||||
/**
|
||||
* Set socket to listen for incoming connections
|
||||
* @param socket Socket to enable listening on
|
||||
* @param conn_queue_length Lenght of backlog connection queue
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
int csp_listen(csp_socket_t *socket, size_t conn_queue_length);
|
||||
|
||||
/**
|
||||
* Bind port to socket
|
||||
* @param socket Socket to bind port to
|
||||
* @param port Port number to bind
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
int csp_bind(csp_socket_t *socket, uint8_t port);
|
||||
|
||||
/**
|
||||
* Start the router task.
|
||||
* @param task_stack_size The number of portStackType to allocate. This only affects FreeRTOS systems.
|
||||
* @param priority The OS task priority of the router
|
||||
*/
|
||||
int csp_route_start_task(unsigned int task_stack_size, unsigned int priority);
|
||||
|
||||
/**
|
||||
* Call the router worker function manually (without the router task)
|
||||
* This must be run inside a loop or called periodically for the csp router to work.
|
||||
* Use this function instead of calling and starting the router task.
|
||||
* @param timeout max blocking time
|
||||
* @return -1 if no packet was processed, 0 otherwise
|
||||
*/
|
||||
int csp_route_work(uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Start the bridge task.
|
||||
* @param task_stack_size The number of portStackType to allocate. This only affects FreeRTOS systems.
|
||||
* @param priority The OS task priority of the router
|
||||
* @param _if_a pointer to first side
|
||||
* @param _if_b pointer to second side
|
||||
* @return CSP_ERR type
|
||||
*/
|
||||
int csp_bridge_start(unsigned int task_stack_size, unsigned int task_priority, csp_iface_t * _if_a, csp_iface_t * _if_b);
|
||||
|
||||
/**
|
||||
* Enable promiscuous mode packet queue
|
||||
* This function is used to enable promiscuous mode for the router.
|
||||
* If enabled, a copy of all incoming packets are placed in a queue
|
||||
* that can be read with csp_promisc_get(). Not all interface drivers
|
||||
* support promiscuous mode.
|
||||
*
|
||||
* @param buf_size Size of buffer for incoming packets
|
||||
*/
|
||||
int csp_promisc_enable(unsigned int buf_size);
|
||||
|
||||
/**
|
||||
* Disable promiscuous mode.
|
||||
* If the queue was initialised prior to this, it can be re-enabled
|
||||
* by calling promisc_enable(0)
|
||||
*/
|
||||
void csp_promisc_disable(void);
|
||||
|
||||
/**
|
||||
* Get packet from promiscuous mode packet queue
|
||||
* Returns the first packet from the promiscuous mode packet queue.
|
||||
* The queue is FIFO, so the returned packet is the oldest one
|
||||
* in the queue.
|
||||
*
|
||||
* @param timeout Timeout in ms to wait for a new packet
|
||||
*/
|
||||
csp_packet_t *csp_promisc_read(uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Send multiple packets using the simple fragmentation protocol
|
||||
* CSP will add total size and offset to all packets
|
||||
* This can be read by the client using the csp_sfp_recv, if the CSP_FFRAG flag is set
|
||||
* @param conn pointer to connection
|
||||
* @param data pointer to data to send
|
||||
* @param totalsize size of data to send
|
||||
* @param mtu maximum transfer unit
|
||||
* @param timeout timeout in ms to wait for csp_send()
|
||||
* @return 0 if OK, -1 if ERR
|
||||
*/
|
||||
int csp_sfp_send(csp_conn_t * conn, const void * data, int totalsize, int mtu, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Same as csp_sfp_send but with option to supply your own memcpy function.
|
||||
* This is usefull if you wish to send data stored in flash memory or another location
|
||||
* @param conn pointer to connection
|
||||
* @param data pointer to data to send
|
||||
* @param totalsize size of data to send
|
||||
* @param mtu maximum transfer unit
|
||||
* @param timeout timeout in ms to wait for csp_send()
|
||||
* @param memcpyfcn, pointer to memcpy function
|
||||
* @return 0 if OK, -1 if ERR
|
||||
*/
|
||||
int csp_sfp_send_own_memcpy(csp_conn_t * conn, const void * data, int totalsize, int mtu, uint32_t timeout, void * (*memcpyfcn)(void *, const void *, size_t));
|
||||
|
||||
/**
|
||||
* This is the counterpart to the csp_sfp_send function
|
||||
* @param conn pointer to active conn, on which you expect to receive sfp packed data
|
||||
* @param dataout pointer to NULL pointer, whill be overwritten with malloc pointer
|
||||
* @param datasize actual size of received data
|
||||
* @param timeout timeout in ms to wait for csp_recv()
|
||||
* @return 0 if OK, -1 if ERR
|
||||
*/
|
||||
int csp_sfp_recv(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* This is the counterpart to the csp_sfp_send function
|
||||
* @param conn pointer to active conn, on which you expect to receive sfp packed data
|
||||
* @param dataout pointer to NULL pointer, whill be overwritten with malloc pointer
|
||||
* @param datasize actual size of received data
|
||||
* @param timeout timeout in ms to wait for csp_recv()
|
||||
* @param first_packet This is a pointer to the first SFP packet (previously received with csp_read)
|
||||
* @return 0 if OK, -1 if ERR
|
||||
*/
|
||||
int csp_sfp_recv_fp(csp_conn_t * conn, void ** dataout, int * datasize, uint32_t timeout, csp_packet_t * first_packet);
|
||||
|
||||
/**
|
||||
* If the given packet is a service-request (that is uses one of the csp service ports)
|
||||
* it will be handled according to the CSP service handler.
|
||||
* This function will either use the packet buffer or delete it,
|
||||
* so this function is typically called in the last "default" clause of
|
||||
* a switch/case statement in a csp_listener task.
|
||||
* In order to listen to csp service ports, bind your listener to the CSP_ANY port.
|
||||
* This function may only be called from task context.
|
||||
* @param conn Pointer to the new connection
|
||||
* @param packet Pointer to the first packet, obtained by using csp_read()
|
||||
*/
|
||||
void csp_service_handler(csp_conn_t *conn, csp_packet_t *packet);
|
||||
|
||||
/**
|
||||
* Send a single ping/echo packet
|
||||
* @param node node id
|
||||
* @param timeout timeout in ms
|
||||
* @param size size of packet to transmit
|
||||
* @param conn_options csp connection options
|
||||
* @return >0 = Echo time in ms, -1 = ERR
|
||||
*/
|
||||
int csp_ping(uint8_t node, uint32_t timeout, unsigned int size, uint8_t conn_options);
|
||||
|
||||
/**
|
||||
* Send a single ping/echo packet without waiting for reply
|
||||
* @param node node id
|
||||
*/
|
||||
void csp_ping_noreply(uint8_t node);
|
||||
|
||||
/**
|
||||
* Request process list.
|
||||
* @note This is only available for FreeRTOS systems
|
||||
* @param node node id
|
||||
* @param timeout timeout in ms
|
||||
*/
|
||||
void csp_ps(uint8_t node, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Request amount of free memory
|
||||
* @param node node id
|
||||
* @param timeout timeout in ms
|
||||
*/
|
||||
void csp_memfree(uint8_t node, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Request number of free buffer elements
|
||||
* @param node node id
|
||||
* @param timeout timeout in ms
|
||||
*/
|
||||
void csp_buf_free(uint8_t node, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Reboot subsystem
|
||||
* @param node node id
|
||||
*/
|
||||
void csp_reboot(uint8_t node);
|
||||
|
||||
/**
|
||||
* Shutdown subsystem
|
||||
* @param node node id
|
||||
*/
|
||||
void csp_shutdown(uint8_t node);
|
||||
|
||||
/**
|
||||
* Request subsystem uptime
|
||||
* @param node node id
|
||||
* @param timeout timeout in ms
|
||||
*/
|
||||
void csp_uptime(uint8_t node, uint32_t timeout);
|
||||
|
||||
/**
|
||||
* Set RDP options
|
||||
* @param window_size Window size
|
||||
* @param conn_timeout_ms Connection timeout in ms
|
||||
* @param packet_timeout_ms Packet timeout in ms
|
||||
* @param delayed_acks Enable/disable delayed acknowledgements
|
||||
* @param ack_timeout Acknowledgement timeout when delayed ACKs is enabled
|
||||
* @param ack_delay_count Send acknowledgement for every ack_delay_count packets
|
||||
*/
|
||||
void csp_rdp_set_opt(unsigned int window_size, unsigned int conn_timeout_ms,
|
||||
unsigned int packet_timeout_ms, unsigned int delayed_acks,
|
||||
unsigned int ack_timeout, unsigned int ack_delay_count);
|
||||
|
||||
/**
|
||||
* Get RDP options
|
||||
* @param window_size Window size
|
||||
* @param conn_timeout_ms Connection timeout in ms
|
||||
* @param packet_timeout_ms Packet timeout in ms
|
||||
* @param delayed_acks Enable/disable delayed acknowledgements
|
||||
* @param ack_timeout Acknowledgement timeout when delayed ACKs is enabled
|
||||
* @param ack_delay_count Send acknowledgement for every ack_delay_count packets
|
||||
*/
|
||||
void csp_rdp_get_opt(unsigned int *window_size, unsigned int *conn_timeout_ms,
|
||||
unsigned int *packet_timeout_ms, unsigned int *delayed_acks,
|
||||
unsigned int *ack_timeout, unsigned int *ack_delay_count);
|
||||
|
||||
/**
|
||||
* Set XTEA key
|
||||
* @param key Pointer to key array
|
||||
* @param keylen Length of key
|
||||
* @return 0 if key was successfully set, -1 otherwise
|
||||
*/
|
||||
int csp_xtea_set_key(char *key, uint32_t keylen);
|
||||
|
||||
/**
|
||||
* Set HMAC key
|
||||
* @param key Pointer to key array
|
||||
* @param keylen Length of key
|
||||
* @return 0 if key was successfully set, -1 otherwise
|
||||
*/
|
||||
int csp_hmac_set_key(char *key, uint32_t keylen);
|
||||
|
||||
/**
|
||||
* Print connection table
|
||||
*/
|
||||
void csp_conn_print_table(void);
|
||||
int csp_conn_print_table_str(char * str_buf, int str_size);
|
||||
|
||||
/**
|
||||
* Print buffer usage table
|
||||
*/
|
||||
void csp_buffer_print_table(void);
|
||||
|
||||
/**
|
||||
* Hex dump to stdout
|
||||
*/
|
||||
void csp_hex_dump(const char *desc, void *addr, int len);
|
||||
|
||||
#ifdef __AVR__
|
||||
typedef uint32_t csp_memptr_t;
|
||||
#else
|
||||
typedef void * csp_memptr_t;
|
||||
#endif
|
||||
|
||||
typedef csp_memptr_t (*csp_memcpy_fnc_t)(csp_memptr_t, const csp_memptr_t, size_t);
|
||||
void csp_cmp_set_memcpy(csp_memcpy_fnc_t fnc);
|
||||
|
||||
/**
|
||||
* Set csp_debug hook function
|
||||
* @param f Hook function
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
typedef void (*csp_debug_hook_func_t)(csp_debug_level_t level, const char *format, va_list args);
|
||||
void csp_debug_hook_set(csp_debug_hook_func_t f);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_H_
|
48
libcsp/include/csp/csp_autoconfig.h
Normal file
48
libcsp/include/csp/csp_autoconfig.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* csp_autoconfig.h
|
||||
*
|
||||
* Created on: 20.11.2020
|
||||
* Author: jakob
|
||||
*/
|
||||
|
||||
#ifndef GOMSPACE_LIBCSP_INCLUDE_CSP_CSP_AUTOCONFIG_H_
|
||||
#define GOMSPACE_LIBCSP_INCLUDE_CSP_CSP_AUTOCONFIG_H_
|
||||
|
||||
#define ENABLE_NANOPOWER2_CLIENT 1
|
||||
#define GIT_REV "unknown"
|
||||
/* #undef CSP_FREERTOS */
|
||||
#define CSP_POSIX 1
|
||||
/* #undef CSP_WINDOWS */
|
||||
/* #undef CSP_MACOSX */
|
||||
#define HAVE_LIBZMQ 1
|
||||
#define CSP_DEBUG 1
|
||||
#define CSP_USE_RDP 1
|
||||
#define CSP_USE_CRC32 1
|
||||
#define CSP_USE_HMAC 1
|
||||
#define CSP_USE_XTEA 1
|
||||
#define CSP_USE_PROMISC 1
|
||||
#define CSP_USE_QOS 1
|
||||
/* #undef CSP_USE_DEDUP */
|
||||
/* #undef CSP_USE_INIT_SHUTDOWN */
|
||||
#define CSP_USE_CAN 1
|
||||
/* #define CSP_USE_I2C 1 */
|
||||
/* #define CSP_USE_KISS 1 */
|
||||
/* #define CSP_USE_ZMQHUB 1 */
|
||||
#define CSP_CONN_MAX 10
|
||||
#define CSP_CONN_QUEUE_LENGTH 100
|
||||
#define CSP_FIFO_INPUT 100
|
||||
#define CSP_MAX_BIND_PORT 31
|
||||
#define CSP_RDP_MAX_WINDOW 20
|
||||
#define CSP_PADDING_BYTES 8
|
||||
#define CSP_CONNECTION_SO 64
|
||||
#define CSP_LOG_LEVEL_DEBUG 1
|
||||
#define CSP_LOG_LEVEL_INFO 1
|
||||
#define CSP_LOG_LEVEL_WARN 1
|
||||
#define CSP_LOG_LEVEL_ERROR 1
|
||||
#define CSP_LITTLE_ENDIAN 1
|
||||
/* #undef CSP_BIG_ENDIAN */
|
||||
#define CSP_HAVE_STDBOOL_H 1
|
||||
/* #define CSP_HAVE_LIBSOCKETCAN 1 */
|
||||
#define LIBCSP_VERSION "1.5"
|
||||
|
||||
#endif /* GOMSPACE_LIBCSP_INCLUDE_CSP_CSP_AUTOCONFIG_H_ */
|
92
libcsp/include/csp/csp_buffer.h
Normal file
92
libcsp/include/csp/csp_buffer.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_BUFFER_H_
|
||||
#define _CSP_BUFFER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Start the buffer handling system
|
||||
* You must specify the number for buffers and the size. All buffers are fixed
|
||||
* size so you must specify the size of your largest buffer.
|
||||
*
|
||||
* @param count Number of buffers to allocate
|
||||
* @param size Buffer size in bytes.
|
||||
*
|
||||
* @return CSP_ERR_NONE if malloc() succeeded, CSP_ERR message otherwise.
|
||||
*/
|
||||
int csp_buffer_init(int count, int size);
|
||||
|
||||
/**
|
||||
* Get a reference to a free buffer. This function can only be called
|
||||
* from task context.
|
||||
*
|
||||
* @param size Specify what data-size you will put in the buffer
|
||||
* @return pointer to a free csp_packet_t or NULL if out of memory
|
||||
*/
|
||||
void * csp_buffer_get(size_t size);
|
||||
|
||||
/**
|
||||
* Get a reference to a free buffer. This function can only be called
|
||||
* from interrupt context.
|
||||
*
|
||||
* @param buf_size Specify what data-size you will put in the buffer
|
||||
* @return pointer to a free csp_packet_t or NULL if out of memory
|
||||
*/
|
||||
void * csp_buffer_get_isr(size_t buf_size);
|
||||
|
||||
/**
|
||||
* Free a buffer after use.
|
||||
* @param packet pointer to memory area, must be acquired by csp_buffer_get().
|
||||
*/
|
||||
void csp_buffer_free(void *packet);
|
||||
|
||||
/**
|
||||
* Free a buffer after use in ISR context.
|
||||
* @param packet pointer to memory area, must be acquired by csp_buffer_get().
|
||||
*/
|
||||
void csp_buffer_free_isr(void *packet);
|
||||
|
||||
/**
|
||||
* Clone an existing packet and increase/decrease cloned packet size.
|
||||
* @param buffer Existing buffer to clone.
|
||||
*/
|
||||
void * csp_buffer_clone(void *buffer);
|
||||
|
||||
/**
|
||||
* Return how many buffers that are currently free.
|
||||
* @return number of free buffers
|
||||
*/
|
||||
int csp_buffer_remaining(void);
|
||||
|
||||
/**
|
||||
* Return the size of the CSP buffers
|
||||
* @return size of CSP buffers
|
||||
*/
|
||||
int csp_buffer_size(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* _CSP_BUFFER_H_ */
|
189
libcsp/include/csp/csp_cmp.h
Normal file
189
libcsp/include/csp/csp_cmp.h
Normal file
@ -0,0 +1,189 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_CMP_H_
|
||||
#define _CSP_CMP_H_
|
||||
|
||||
/**
|
||||
@file
|
||||
CSP management protocol (CMP).
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <csp/csp.h>
|
||||
#include <csp/arch/csp_clock.h>
|
||||
|
||||
/**
|
||||
CMP type.
|
||||
@{
|
||||
*/
|
||||
/**
|
||||
CMP request.
|
||||
*/
|
||||
#define CSP_CMP_REQUEST 0x00
|
||||
/**
|
||||
CMP reply.
|
||||
*/
|
||||
#define CSP_CMP_REPLY 0xff
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
CMP requests.
|
||||
@{
|
||||
*/
|
||||
/**
|
||||
CMP request codes.
|
||||
*/
|
||||
/**
|
||||
Request identification, compile time, revision, name.
|
||||
*/
|
||||
#define CSP_CMP_IDENT 1
|
||||
/**
|
||||
Set/configure routing.
|
||||
*/
|
||||
#define CSP_CMP_ROUTE_SET 2
|
||||
/**
|
||||
Request interface statistics.
|
||||
*/
|
||||
#define CSP_CMP_IF_STATS 3
|
||||
/**
|
||||
Peek/read data from memory.
|
||||
*/
|
||||
#define CSP_CMP_PEEK 4
|
||||
/**
|
||||
Poke/write data from memory.
|
||||
*/
|
||||
#define CSP_CMP_POKE 5
|
||||
/**
|
||||
Get/set clock.
|
||||
*/
|
||||
#define CSP_CMP_CLOCK 6
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
CMP identification - max revision length.
|
||||
*/
|
||||
#define CSP_CMP_IDENT_REV_LEN 20
|
||||
/**
|
||||
CMP identification - max date length.
|
||||
*/
|
||||
#define CSP_CMP_IDENT_DATE_LEN 12
|
||||
/**
|
||||
CMP identification - max time length.
|
||||
*/
|
||||
#define CSP_CMP_IDENT_TIME_LEN 9
|
||||
|
||||
/**
|
||||
CMP interface statistics - max interface name length.
|
||||
*/
|
||||
#define CSP_CMP_ROUTE_IFACE_LEN 11
|
||||
|
||||
/**
|
||||
CMP peek/read memeory - max read length.
|
||||
*/
|
||||
#define CSP_CMP_PEEK_MAX_LEN 200
|
||||
|
||||
/**
|
||||
CMP poke/write memeory - max write length.
|
||||
*/
|
||||
#define CSP_CMP_POKE_MAX_LEN 200
|
||||
|
||||
/**
|
||||
CSP management protocol description.
|
||||
*/
|
||||
struct csp_cmp_message {
|
||||
//! CMP request type.
|
||||
uint8_t type;
|
||||
//! CMP request code.
|
||||
uint8_t code;
|
||||
union {
|
||||
struct {
|
||||
char hostname[CSP_HOSTNAME_LEN];
|
||||
char model[CSP_MODEL_LEN];
|
||||
char revision[CSP_CMP_IDENT_REV_LEN];
|
||||
char date[CSP_CMP_IDENT_DATE_LEN];
|
||||
char time[CSP_CMP_IDENT_TIME_LEN];
|
||||
} ident;
|
||||
struct {
|
||||
uint8_t dest_node;
|
||||
uint8_t next_hop_mac;
|
||||
char interface[CSP_CMP_ROUTE_IFACE_LEN];
|
||||
} route_set;
|
||||
struct __attribute__((__packed__)) {
|
||||
char interface[CSP_CMP_ROUTE_IFACE_LEN];
|
||||
uint32_t tx;
|
||||
uint32_t rx;
|
||||
uint32_t tx_error;
|
||||
uint32_t rx_error;
|
||||
uint32_t drop;
|
||||
uint32_t autherr;
|
||||
uint32_t frame;
|
||||
uint32_t txbytes;
|
||||
uint32_t rxbytes;
|
||||
uint32_t irq;
|
||||
} if_stats;
|
||||
struct {
|
||||
uint32_t addr;
|
||||
uint8_t len;
|
||||
char data[CSP_CMP_PEEK_MAX_LEN];
|
||||
} peek;
|
||||
struct {
|
||||
uint32_t addr;
|
||||
uint8_t len;
|
||||
char data[CSP_CMP_POKE_MAX_LEN];
|
||||
} poke;
|
||||
csp_timestamp_t clock;
|
||||
};
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/**
|
||||
Macro for calculating size of management message.
|
||||
*/
|
||||
#define CMP_SIZE(_memb) (sizeof(((struct csp_cmp_message *)0)->_memb) + sizeof(uint8_t) + sizeof(uint8_t))
|
||||
|
||||
/**
|
||||
Generic send management message request.
|
||||
*/
|
||||
int csp_cmp(uint8_t node, uint32_t timeout, uint8_t code, int membsize, struct csp_cmp_message *msg);
|
||||
|
||||
/**
|
||||
Macro for defining management handling function.
|
||||
*/
|
||||
#define CMP_MESSAGE(_code, _memb) \
|
||||
static inline int csp_cmp_##_memb(uint8_t node, uint32_t timeout, struct csp_cmp_message *msg) { \
|
||||
return csp_cmp(node, timeout, _code, CMP_SIZE(_memb), msg); \
|
||||
}
|
||||
|
||||
CMP_MESSAGE(CSP_CMP_IDENT, ident)
|
||||
CMP_MESSAGE(CSP_CMP_ROUTE_SET, route_set)
|
||||
CMP_MESSAGE(CSP_CMP_IF_STATS, if_stats)
|
||||
CMP_MESSAGE(CSP_CMP_PEEK, peek)
|
||||
CMP_MESSAGE(CSP_CMP_POKE, poke)
|
||||
CMP_MESSAGE(CSP_CMP_CLOCK, clock)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_CMP_H_
|
63
libcsp/include/csp/csp_crc32.h
Normal file
63
libcsp/include/csp/csp_crc32.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_CRC32_H_
|
||||
#define _CSP_CRC32_H_
|
||||
|
||||
#include <csp/csp.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Generate precomputed CRC32 table
|
||||
*/
|
||||
void csp_crc32_gentab(void);
|
||||
|
||||
/**
|
||||
* Append CRC32 checksum to packet
|
||||
* @param packet Packet to append checksum
|
||||
* @param include_header use header in calculation (this will not modify the flags field)
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
int csp_crc32_append(csp_packet_t * packet, bool include_header);
|
||||
|
||||
/**
|
||||
* Verify CRC32 checksum on packet
|
||||
* @param packet Packet to verify
|
||||
* @param include_header use header in calculation (this will not modify the flags field)
|
||||
* @return 0 if checksum is valid, -1 otherwise
|
||||
*/
|
||||
int csp_crc32_verify(csp_packet_t * packet, bool include_header);
|
||||
|
||||
/**
|
||||
* Calculate checksum for a given memory area
|
||||
* @param data pointer to memory
|
||||
* @param length length of memory to do checksum on
|
||||
* @return return uint32_t checksum
|
||||
*/
|
||||
uint32_t csp_crc32_memory(const uint8_t * data, uint32_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* _CSP_CRC32_H_ */
|
150
libcsp/include/csp/csp_debug.h
Normal file
150
libcsp/include/csp/csp_debug.h
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_DEBUG_H_
|
||||
#define _CSP_DEBUG_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Debug levels */
|
||||
typedef enum {
|
||||
CSP_ERROR = 0,
|
||||
CSP_WARN = 1,
|
||||
CSP_INFO = 2,
|
||||
CSP_BUFFER = 3,
|
||||
CSP_PACKET = 4,
|
||||
CSP_PROTOCOL = 5,
|
||||
CSP_LOCK = 6,
|
||||
} csp_debug_level_t;
|
||||
|
||||
/* Extract filename component from path */
|
||||
#define BASENAME(_file) ((strrchr(_file, '/') ? : (strrchr(_file, '\\') ? : _file)) + 1)
|
||||
|
||||
/* Implement csp_assert_fail_action to override default failure action */
|
||||
extern void __attribute__((weak)) csp_assert_fail_action(const char *assertion, const char *file, int line);
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define csp_assert(exp) \
|
||||
do { \
|
||||
if (!(exp)) { \
|
||||
const char *assertion = #exp; \
|
||||
const char *file = BASENAME(__FILE__); \
|
||||
int line = __LINE__; \
|
||||
printf("\E[1;31m[%02" PRIu8 "] Assertion \'%s\' failed in %s:%d\E[0m\r\n", \
|
||||
csp_get_address(), assertion, file, line); \
|
||||
if (csp_assert_fail_action) \
|
||||
csp_assert_fail_action(assertion, file, line); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define csp_assert(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef __AVR__
|
||||
#include <stdio.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#define CONSTSTR(data) PSTR(data)
|
||||
#undef printf
|
||||
#undef sscanf
|
||||
#undef scanf
|
||||
#undef sprintf
|
||||
#undef snprintf
|
||||
#define printf(s, ...) printf_P(PSTR(s), ## __VA_ARGS__)
|
||||
#define sscanf(buf, s, ...) sscanf_P(buf, PSTR(s), ## __VA_ARGS__)
|
||||
#define scanf(s, ...) scanf_P(PSTR(s), ## __VA_ARGS__)
|
||||
#define sprintf(buf, s, ...) sprintf_P(buf, PSTR(s), ## __VA_ARGS__)
|
||||
#define snprintf(buf, size, s, ...) snprintf_P(buf, size, PSTR(s), ## __VA_ARGS__)
|
||||
#else
|
||||
#define CONSTSTR(data) data
|
||||
#endif
|
||||
|
||||
#ifdef CSP_DEBUG
|
||||
#define csp_debug(level, format, ...) do { do_csp_debug(level, CONSTSTR(format), ##__VA_ARGS__); } while(0)
|
||||
#else
|
||||
#define csp_debug(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef CSP_LOG_LEVEL_ERROR
|
||||
#define csp_log_error(format, ...) csp_debug(CSP_ERROR, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define csp_log_error(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef CSP_LOG_LEVEL_WARN
|
||||
#define csp_log_warn(format, ...) csp_debug(CSP_WARN, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define csp_log_warn(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef CSP_LOG_LEVEL_INFO
|
||||
#define csp_log_info(format, ...) csp_debug(CSP_INFO, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define csp_log_info(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#ifdef CSP_LOG_LEVEL_DEBUG
|
||||
#define csp_log_buffer(format, ...) csp_debug(CSP_BUFFER, format, ##__VA_ARGS__)
|
||||
#define csp_log_packet(format, ...) csp_debug(CSP_PACKET, format, ##__VA_ARGS__)
|
||||
#define csp_log_protocol(format, ...) csp_debug(CSP_PROTOCOL, format, ##__VA_ARGS__)
|
||||
#define csp_log_lock(format, ...) csp_debug(CSP_LOCK, format, ##__VA_ARGS__)
|
||||
#else
|
||||
#define csp_log_buffer(...) do {} while (0)
|
||||
#define csp_log_packet(...) do {} while (0)
|
||||
#define csp_log_protocol(...) do {} while (0)
|
||||
#define csp_log_lock(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function should not be used directly, use csp_log_<level>() macro instead
|
||||
* @param level
|
||||
* @param format
|
||||
*/
|
||||
void do_csp_debug(csp_debug_level_t level, const char *format, ...);
|
||||
|
||||
/**
|
||||
* Toggle debug level on/off
|
||||
* @param level Level to toggle
|
||||
*/
|
||||
void csp_debug_toggle_level(csp_debug_level_t level);
|
||||
|
||||
/**
|
||||
* Set debug level
|
||||
* @param level Level to set
|
||||
* @param value New level value
|
||||
*/
|
||||
void csp_debug_set_level(csp_debug_level_t level, bool value);
|
||||
|
||||
/**
|
||||
* Get current debug level value
|
||||
* @param level Level value to get
|
||||
* @return Level value
|
||||
*/
|
||||
int csp_debug_get_level(csp_debug_level_t level);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_DEBUG_H_
|
170
libcsp/include/csp/csp_endian.h
Normal file
170
libcsp/include/csp/csp_endian.h
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_ENDIAN_H_
|
||||
#define _CSP_ENDIAN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Convert 16-bit integer from host byte order to network byte order
|
||||
* @param h16 Host byte order 16-bit integer
|
||||
*/
|
||||
uint16_t csp_hton16(uint16_t h16);
|
||||
|
||||
/**
|
||||
* Convert 16-bit integer from host byte order to host byte order
|
||||
* @param n16 Network byte order 16-bit integer
|
||||
*/
|
||||
uint16_t csp_ntoh16(uint16_t n16);
|
||||
|
||||
/**
|
||||
* Convert 32-bit integer from host byte order to network byte order
|
||||
* @param h32 Host byte order 32-bit integer
|
||||
*/
|
||||
uint32_t csp_hton32(uint32_t h32);
|
||||
|
||||
/**
|
||||
* Convert 32-bit integer from host byte order to host byte order
|
||||
* @param n32 Network byte order 32-bit integer
|
||||
*/
|
||||
uint32_t csp_ntoh32(uint32_t n32);
|
||||
|
||||
/**
|
||||
* Convert 64-bit integer from host byte order to network byte order
|
||||
* @param h64 Host byte order 64-bit integer
|
||||
*/
|
||||
uint64_t csp_hton64(uint64_t h64);
|
||||
|
||||
/**
|
||||
* Convert 64-bit integer from host byte order to host byte order
|
||||
* @param n64 Network byte order 64-bit integer
|
||||
*/
|
||||
uint64_t csp_ntoh64(uint64_t n64);
|
||||
|
||||
/**
|
||||
* Convert 16-bit integer from host byte order to big endian byte order
|
||||
* @param h16 Host byte order 16-bit integer
|
||||
*/
|
||||
uint16_t csp_htobe16(uint16_t h16);
|
||||
|
||||
/**
|
||||
* Convert 16-bit integer from host byte order to little endian byte order
|
||||
* @param h16 Host byte order 16-bit integer
|
||||
*/
|
||||
uint16_t csp_htole16(uint16_t h16);
|
||||
|
||||
/**
|
||||
* Convert 16-bit integer from big endian byte order to little endian byte order
|
||||
* @param be16 Big endian byte order 16-bit integer
|
||||
*/
|
||||
uint16_t csp_betoh16(uint16_t be16);
|
||||
|
||||
/**
|
||||
* Convert 16-bit integer from little endian byte order to host byte order
|
||||
* @param le16 Little endian byte order 16-bit integer
|
||||
*/
|
||||
uint16_t csp_letoh16(uint16_t le16);
|
||||
|
||||
/**
|
||||
* Convert 32-bit integer from host byte order to big endian byte order
|
||||
* @param h32 Host byte order 32-bit integer
|
||||
*/
|
||||
uint32_t csp_htobe32(uint32_t h32);
|
||||
|
||||
/**
|
||||
* Convert 32-bit integer from little endian byte order to host byte order
|
||||
* @param h32 Host byte order 32-bit integer
|
||||
*/
|
||||
uint32_t csp_htole32(uint32_t h32);
|
||||
|
||||
/**
|
||||
* Convert 32-bit integer from big endian byte order to host byte order
|
||||
* @param be32 Big endian byte order 32-bit integer
|
||||
*/
|
||||
uint32_t csp_betoh32(uint32_t be32);
|
||||
|
||||
/**
|
||||
* Convert 32-bit integer from little endian byte order to host byte order
|
||||
* @param le32 Little endian byte order 32-bit integer
|
||||
*/
|
||||
uint32_t csp_letoh32(uint32_t le32);
|
||||
|
||||
/**
|
||||
* Convert 64-bit integer from host byte order to big endian byte order
|
||||
* @param h64 Host byte order 64-bit integer
|
||||
*/
|
||||
uint64_t csp_htobe64(uint64_t h64);
|
||||
|
||||
/**
|
||||
* Convert 64-bit integer from host byte order to little endian byte order
|
||||
* @param h64 Host byte order 64-bit integer
|
||||
*/
|
||||
uint64_t csp_htole64(uint64_t h64);
|
||||
|
||||
/**
|
||||
* Convert 64-bit integer from big endian byte order to host byte order
|
||||
* @param be64 Big endian byte order 64-bit integer
|
||||
*/
|
||||
uint64_t csp_betoh64(uint64_t be64);
|
||||
|
||||
/**
|
||||
* Convert 64-bit integer from little endian byte order to host byte order
|
||||
* @param le64 Little endian byte order 64-bit integer
|
||||
*/
|
||||
uint64_t csp_letoh64(uint64_t le64);
|
||||
|
||||
/**
|
||||
* Convert float from host to network byte order
|
||||
* @param f Float in host order
|
||||
* @return Float in network order
|
||||
*/
|
||||
float csp_htonflt(float f);
|
||||
|
||||
/**
|
||||
* Convert float from network to host byte order
|
||||
* @param f Float in network order
|
||||
* @return Float in host order
|
||||
*/
|
||||
float csp_ntohflt(float f);
|
||||
|
||||
/**
|
||||
* Convert double from host to network byte order
|
||||
* @param d Double in host order
|
||||
* @return Double in network order
|
||||
*/
|
||||
double csp_htondbl(double d);
|
||||
|
||||
/**
|
||||
* Convert double from network to host order
|
||||
* @param d Double in network order
|
||||
* @return Double in host order
|
||||
*/
|
||||
double csp_ntohdbl(double d);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_ENDIAN_H_
|
50
libcsp/include/csp/csp_error.h
Normal file
50
libcsp/include/csp/csp_error.h
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_ERROR_H_
|
||||
#define _CSP_ERROR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CSP_ERR_NONE 0 /* No error */
|
||||
#define CSP_ERR_NOMEM -1 /* Not enough memory */
|
||||
#define CSP_ERR_INVAL -2 /* Invalid argument */
|
||||
#define CSP_ERR_TIMEDOUT -3 /* Operation timed out */
|
||||
#define CSP_ERR_USED -4 /* Resource already in use */
|
||||
#define CSP_ERR_NOTSUP -5 /* Operation not supported */
|
||||
#define CSP_ERR_BUSY -6 /* Device or resource busy */
|
||||
#define CSP_ERR_ALREADY -7 /* Connection already in progress */
|
||||
#define CSP_ERR_RESET -8 /* Connection reset */
|
||||
#define CSP_ERR_NOBUFS -9 /* No more buffer space available */
|
||||
#define CSP_ERR_TX -10 /* Transmission failed */
|
||||
#define CSP_ERR_DRIVER -11 /* Error in driver layer */
|
||||
#define CSP_ERR_AGAIN -12 /* Resource temporarily unavailable */
|
||||
|
||||
#define CSP_ERR_HMAC -100 /* HMAC failed */
|
||||
#define CSP_ERR_XTEA -101 /* XTEA failed */
|
||||
#define CSP_ERR_CRC32 -102 /* CRC32 failed */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_ERROR_H_
|
56
libcsp/include/csp/csp_iflist.h
Normal file
56
libcsp/include/csp/csp_iflist.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef CSP_IFLIST_H_
|
||||
#define CSP_IFLIST_H_
|
||||
|
||||
#include <csp/csp_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Add interface to list
|
||||
* @param ifc Pointer to interface to add
|
||||
*/
|
||||
void csp_iflist_add(csp_iface_t *ifc);
|
||||
|
||||
/**
|
||||
* Lookup interface by name
|
||||
* @param name String with interface name
|
||||
* @return Pointer to interface or NULL if not found
|
||||
*/
|
||||
csp_iface_t * csp_iflist_get_by_name(const char *name);
|
||||
|
||||
/**
|
||||
* Print list of interfaces to stdout
|
||||
*/
|
||||
void csp_iflist_print(void);
|
||||
|
||||
/**
|
||||
* Return list of registered interfaces.
|
||||
*/
|
||||
csp_iface_t * csp_iflist_get(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* CSP_IFLIST_H_ */
|
54
libcsp/include/csp/csp_interface.h
Normal file
54
libcsp/include/csp/csp_interface.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_INTERFACE_H_
|
||||
#define _CSP_INTERFACE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <csp/csp.h>
|
||||
|
||||
/**
|
||||
* Inputs a new packet into the system
|
||||
* This function is called from interface drivers ISR to route and accept packets.
|
||||
* But it can also be called from a task, provided that the pxTaskWoken parameter is NULL!
|
||||
*
|
||||
* EXTREMELY IMPORTANT:
|
||||
* pxTaskWoken arg must ALWAYS be NULL if called from task,
|
||||
* and ALWAYS be NON NULL if called from ISR!
|
||||
* If this condition is met, this call is completely thread-safe
|
||||
*
|
||||
* This function is fire and forget, it returns void, meaning
|
||||
* that a packet will always be either accepted or dropped
|
||||
* so the memory will always be freed.
|
||||
*
|
||||
* @param packet A pointer to the incoming packet
|
||||
* @param interface A pointer to the incoming interface TX function.
|
||||
* @param pxTaskWoken This must be a pointer a valid variable if called from ISR or NULL otherwise!
|
||||
*/
|
||||
void csp_qfifo_write(csp_packet_t *packet, csp_iface_t *interface, CSP_BASE_TYPE *pxTaskWoken);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_INTERFACE_H_
|
56
libcsp/include/csp/csp_platform.h
Normal file
56
libcsp/include/csp/csp_platform.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_PLATFORM_H_
|
||||
#define _CSP_PLATFORM_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Set OS */
|
||||
#if defined(CSP_POSIX) || defined(CSP_WINDOWS) || defined(CSP_MACOSX)
|
||||
#define CSP_BASE_TYPE int
|
||||
#define CSP_MAX_DELAY (UINT32_MAX)
|
||||
#define CSP_INFINITY (UINT32_MAX)
|
||||
#define CSP_DEFINE_CRITICAL(lock) static csp_bin_sem_handle_t lock
|
||||
#define CSP_INIT_CRITICAL(lock) ({(csp_bin_sem_create(&lock) == CSP_SEMAPHORE_OK) ? CSP_ERR_NONE : CSP_ERR_NOMEM;})
|
||||
#define CSP_ENTER_CRITICAL(lock) do { csp_bin_sem_wait(&lock, CSP_MAX_DELAY); } while(0)
|
||||
#define CSP_EXIT_CRITICAL(lock) do { csp_bin_sem_post(&lock); } while(0)
|
||||
#elif defined(CSP_FREERTOS)
|
||||
#include "FreeRTOS.h"
|
||||
#define CSP_BASE_TYPE portBASE_TYPE
|
||||
#define CSP_MAX_DELAY portMAX_DELAY
|
||||
#define CSP_INFINITY portMAX_DELAY
|
||||
#define CSP_DEFINE_CRITICAL(lock)
|
||||
#define CSP_INIT_CRITICAL(lock) ({CSP_ERR_NONE;})
|
||||
#define CSP_ENTER_CRITICAL(lock) do { portENTER_CRITICAL(); } while (0)
|
||||
#define CSP_EXIT_CRITICAL(lock) do { portEXIT_CRITICAL(); } while (0)
|
||||
#else
|
||||
#error "OS must be either CSP_POSIX, CSP_MACOSX, CSP_FREERTOS OR CSP_WINDOWS"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_PLATFORM_H_
|
149
libcsp/include/csp/csp_rtable.h
Normal file
149
libcsp/include/csp/csp_rtable.h
Normal file
@ -0,0 +1,149 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef CSP_RTABLE_H_
|
||||
#define CSP_RTABLE_H_
|
||||
|
||||
#include <csp/csp_iflist.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CSP_NODE_MAC 0xFF
|
||||
#define CSP_ROUTE_COUNT (CSP_ID_HOST_MAX + 2)
|
||||
#define CSP_ROUTE_TABLE_SIZE 5 * CSP_ROUTE_COUNT
|
||||
|
||||
/**
|
||||
* Find outgoing interface in routing table
|
||||
* @param id Destination node
|
||||
* @return pointer to outgoing interface or NULL
|
||||
*/
|
||||
csp_iface_t * csp_rtable_find_iface(uint8_t id);
|
||||
|
||||
/**
|
||||
* Find MAC address associated with node
|
||||
* @param id Destination node
|
||||
* @return MAC address
|
||||
*/
|
||||
uint8_t csp_rtable_find_mac(uint8_t id);
|
||||
|
||||
/**
|
||||
* Setup routing entry
|
||||
* @param node Host
|
||||
* @param mask Number of bits in netmask
|
||||
* @param ifc Interface
|
||||
* @param mac MAC address
|
||||
* @return CSP error type
|
||||
*/
|
||||
int csp_rtable_set(uint8_t node, uint8_t mask, csp_iface_t *ifc, uint8_t mac);
|
||||
|
||||
/**
|
||||
* Print routing table to stdout
|
||||
*/
|
||||
void csp_rtable_print(void);
|
||||
|
||||
|
||||
/**
|
||||
* Load the routing table from a buffer
|
||||
* (deprecated, please use new csp_rtable_load)
|
||||
*
|
||||
* Warning:
|
||||
* The table will be RAW from memory and contains direct pointers, not interface names.
|
||||
* Therefore it's very important that a saved routing table is deleted after a firmware update
|
||||
*
|
||||
* @param route_table_in pointer to routing table buffer
|
||||
*/
|
||||
void csp_route_table_load(uint8_t route_table_in[CSP_ROUTE_TABLE_SIZE]);
|
||||
|
||||
/**
|
||||
* Save the routing table to a buffer
|
||||
* (deprecated, please use new csp_rtable_save)
|
||||
*
|
||||
* Warning:
|
||||
* The table will be RAW from memory and contains direct pointers, not interface names.
|
||||
* Therefore it's very important that a saved routing table is deleted after a firmware update
|
||||
*
|
||||
* @param route_table_out pointer to routing table buffer
|
||||
*/
|
||||
void csp_route_table_save(uint8_t route_table_out[CSP_ROUTE_TABLE_SIZE]);
|
||||
|
||||
/**
|
||||
* Save routing table as a string to a buffer, which can be parsed
|
||||
* again by csp_rtable_load.
|
||||
* @param buffer pointer to buffer
|
||||
* @param maxlen length of buffer
|
||||
* @return length of saved string
|
||||
*/
|
||||
int csp_rtable_save(char * buffer, int maxlen);
|
||||
|
||||
/**
|
||||
* Load routing table from a string in the format
|
||||
* %u/%u %s %u
|
||||
* - Address
|
||||
* - Netmask
|
||||
* - Ifname
|
||||
* - Mac Address (this field is optional)
|
||||
* An example routing string is "0/0 I2C, 8/2 KISS"
|
||||
* The string must be \0 null terminated
|
||||
* @param buffer Pointer to string
|
||||
*/
|
||||
void csp_rtable_load(const char * buffer);
|
||||
|
||||
/**
|
||||
* Check string for valid routing table
|
||||
* @param buffer Pointer to string
|
||||
* @return number of valid entries found
|
||||
*/
|
||||
int csp_rtable_check(const char * buffer);
|
||||
|
||||
/**
|
||||
* Clear routing table:
|
||||
* This could be done before load to ensure an entire clean table is loaded.
|
||||
*/
|
||||
void csp_rtable_clear(void);
|
||||
|
||||
/**
|
||||
* Setup routing entry to single node
|
||||
* (deprecated, please use csp_rtable_set)
|
||||
*
|
||||
* @param node Host
|
||||
* @param ifc Interface
|
||||
* @param mac MAC address
|
||||
* @return CSP error type
|
||||
*/
|
||||
#define csp_route_set(node, ifc, mac) csp_rtable_set(node, CSP_ID_HOST_SIZE, ifc, mac)
|
||||
|
||||
/**
|
||||
* Print routing table
|
||||
* (deprecated, please use csp_rtable_print)
|
||||
*/
|
||||
#define csp_route_print_table() csp_rtable_print();
|
||||
|
||||
/**
|
||||
* Print list of interfaces
|
||||
* (deprecated, please use csp_iflist_print)
|
||||
*/
|
||||
#define csp_route_print_interfaces() csp_iflist_print();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* CSP_RTABLE_H_ */
|
235
libcsp/include/csp/csp_types.h
Normal file
235
libcsp/include/csp/csp_types.h
Normal file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef CSP_TYPES_H_
|
||||
#define CSP_TYPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <csp/csp_autoconfig.h> // -> CSP_HAVE_X defines
|
||||
#ifdef CSP_HAVE_STDBOOL_H
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Make bool for compilers without stdbool.h */
|
||||
#ifndef CSP_HAVE_STDBOOL_H
|
||||
#define bool int
|
||||
#define false 0
|
||||
#define true !false
|
||||
#endif
|
||||
|
||||
/**
|
||||
* RESERVED PORTS (SERVICES)
|
||||
*/
|
||||
|
||||
enum csp_reserved_ports_e {
|
||||
CSP_CMP = 0,
|
||||
CSP_PING = 1,
|
||||
CSP_PS = 2,
|
||||
CSP_MEMFREE = 3,
|
||||
CSP_REBOOT = 4,
|
||||
CSP_BUF_FREE = 5,
|
||||
CSP_UPTIME = 6,
|
||||
CSP_ANY = (CSP_MAX_BIND_PORT + 1),
|
||||
CSP_PROMISC = (CSP_MAX_BIND_PORT + 2)
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
CSP_PRIO_CRITICAL = 0,
|
||||
CSP_PRIO_HIGH = 1,
|
||||
CSP_PRIO_NORM = 2,
|
||||
CSP_PRIO_LOW = 3,
|
||||
} csp_prio_t;
|
||||
|
||||
#define CSP_PRIORITIES (1 << CSP_ID_PRIO_SIZE)
|
||||
|
||||
#ifdef CSP_USE_QOS
|
||||
#define CSP_RX_QUEUE_LENGTH (CSP_CONN_QUEUE_LENGTH / CSP_PRIORITIES)
|
||||
#define CSP_ROUTE_FIFOS CSP_PRIORITIES
|
||||
#define CSP_RX_QUEUES CSP_PRIORITIES
|
||||
#else
|
||||
#define CSP_RX_QUEUE_LENGTH CSP_CONN_QUEUE_LENGTH
|
||||
#define CSP_ROUTE_FIFOS 1
|
||||
#define CSP_RX_QUEUES 1
|
||||
#endif
|
||||
|
||||
/** Size of bit-fields in CSP header */
|
||||
#define CSP_ID_PRIO_SIZE 2
|
||||
#define CSP_ID_HOST_SIZE 5
|
||||
#define CSP_ID_PORT_SIZE 6
|
||||
#define CSP_ID_FLAGS_SIZE 8
|
||||
|
||||
#define CSP_HEADER_BITS (CSP_ID_PRIO_SIZE + 2 * CSP_ID_HOST_SIZE + 2 * CSP_ID_PORT_SIZE + CSP_ID_FLAGS_SIZE)
|
||||
#define CSP_HEADER_LENGTH (CSP_HEADER_BITS / 8)
|
||||
|
||||
#if CSP_HEADER_BITS != 32 && __GNUC__
|
||||
#error "Header length must be 32 bits"
|
||||
#endif
|
||||
|
||||
/** Highest number to be entered in field */
|
||||
#define CSP_ID_PRIO_MAX ((1 << (CSP_ID_PRIO_SIZE)) - 1)
|
||||
#define CSP_ID_HOST_MAX ((1 << (CSP_ID_HOST_SIZE)) - 1)
|
||||
#define CSP_ID_PORT_MAX ((1 << (CSP_ID_PORT_SIZE)) - 1)
|
||||
#define CSP_ID_FLAGS_MAX ((1 << (CSP_ID_FLAGS_SIZE)) - 1)
|
||||
|
||||
/** Identifier field masks */
|
||||
#define CSP_ID_PRIO_MASK ((uint32_t) CSP_ID_PRIO_MAX << (CSP_ID_FLAGS_SIZE + 2 * CSP_ID_PORT_SIZE + 2 * CSP_ID_HOST_SIZE))
|
||||
#define CSP_ID_SRC_MASK ((uint32_t) CSP_ID_HOST_MAX << (CSP_ID_FLAGS_SIZE + 2 * CSP_ID_PORT_SIZE + 1 * CSP_ID_HOST_SIZE))
|
||||
#define CSP_ID_DST_MASK ((uint32_t) CSP_ID_HOST_MAX << (CSP_ID_FLAGS_SIZE + 2 * CSP_ID_PORT_SIZE))
|
||||
#define CSP_ID_DPORT_MASK ((uint32_t) CSP_ID_PORT_MAX << (CSP_ID_FLAGS_SIZE + 1 * CSP_ID_PORT_SIZE))
|
||||
#define CSP_ID_SPORT_MASK ((uint32_t) CSP_ID_PORT_MAX << (CSP_ID_FLAGS_SIZE))
|
||||
#define CSP_ID_FLAGS_MASK ((uint32_t) CSP_ID_FLAGS_MAX << (0))
|
||||
|
||||
#define CSP_ID_CONN_MASK (CSP_ID_SRC_MASK | CSP_ID_DST_MASK | CSP_ID_DPORT_MASK | CSP_ID_SPORT_MASK)
|
||||
|
||||
/**
|
||||
CSP identifier.
|
||||
*/
|
||||
typedef union {
|
||||
//! Entire identifier.
|
||||
uint32_t ext;
|
||||
//! Individual fields.
|
||||
struct __attribute__((__packed__)) {
|
||||
#if defined(CSP_BIG_ENDIAN) && !defined(CSP_LITTLE_ENDIAN)
|
||||
unsigned int pri : CSP_ID_PRIO_SIZE;
|
||||
unsigned int src : CSP_ID_HOST_SIZE;
|
||||
unsigned int dst : CSP_ID_HOST_SIZE;
|
||||
unsigned int dport : CSP_ID_PORT_SIZE;
|
||||
unsigned int sport : CSP_ID_PORT_SIZE;
|
||||
unsigned int flags : CSP_ID_FLAGS_SIZE;
|
||||
#elif defined(CSP_LITTLE_ENDIAN) && !defined(CSP_BIG_ENDIAN)
|
||||
unsigned int flags : CSP_ID_FLAGS_SIZE;
|
||||
unsigned int sport : CSP_ID_PORT_SIZE;
|
||||
unsigned int dport : CSP_ID_PORT_SIZE;
|
||||
unsigned int dst : CSP_ID_HOST_SIZE;
|
||||
unsigned int src : CSP_ID_HOST_SIZE;
|
||||
unsigned int pri : CSP_ID_PRIO_SIZE;
|
||||
#else
|
||||
#error "Must define one of CSP_BIG_ENDIAN or CSP_LITTLE_ENDIAN in csp_platform.h"
|
||||
#endif
|
||||
};
|
||||
} csp_id_t;
|
||||
|
||||
/** Broadcast address */
|
||||
#define CSP_BROADCAST_ADDR CSP_ID_HOST_MAX
|
||||
|
||||
/** Default routing address */
|
||||
#define CSP_DEFAULT_ROUTE (CSP_ID_HOST_MAX + 1)
|
||||
|
||||
/** CSP Flags */
|
||||
#define CSP_FRES1 0x80 // Reserved for future use
|
||||
#define CSP_FRES2 0x40 // Reserved for future use
|
||||
#define CSP_FRES3 0x20 // Reserved for future use
|
||||
#define CSP_FFRAG 0x10 // Use fragmentation
|
||||
#define CSP_FHMAC 0x08 // Use HMAC verification
|
||||
#define CSP_FXTEA 0x04 // Use XTEA encryption
|
||||
#define CSP_FRDP 0x02 // Use RDP protocol
|
||||
#define CSP_FCRC32 0x01 // Use CRC32 checksum
|
||||
|
||||
/** CSP Socket options */
|
||||
#define CSP_SO_NONE 0x0000 // No socket options
|
||||
#define CSP_SO_RDPREQ 0x0001 // Require RDP
|
||||
#define CSP_SO_RDPPROHIB 0x0002 // Prohibit RDP
|
||||
#define CSP_SO_HMACREQ 0x0004 // Require HMAC
|
||||
#define CSP_SO_HMACPROHIB 0x0008 // Prohibit HMAC
|
||||
#define CSP_SO_XTEAREQ 0x0010 // Require XTEA
|
||||
#define CSP_SO_XTEAPROHIB 0x0020 // Prohibit HMAC
|
||||
#define CSP_SO_CRC32REQ 0x0040 // Require CRC32
|
||||
#define CSP_SO_CRC32PROHIB 0x0080 // Prohibit CRC32
|
||||
#define CSP_SO_CONN_LESS 0x0100 // Enable Connection Less mode
|
||||
#define CSP_SO_INTERNAL_LISTEN 0x1000 // Internal flag: listen called on socket
|
||||
|
||||
/** CSP Connect options */
|
||||
#define CSP_O_NONE CSP_SO_NONE // No connection options
|
||||
#define CSP_O_RDP CSP_SO_RDPREQ // Enable RDP
|
||||
#define CSP_O_NORDP CSP_SO_RDPPROHIB // Disable RDP
|
||||
#define CSP_O_HMAC CSP_SO_HMACREQ // Enable HMAC
|
||||
#define CSP_O_NOHMAC CSP_SO_HMACPROHIB // Disable HMAC
|
||||
#define CSP_O_XTEA CSP_SO_XTEAREQ // Enable XTEA
|
||||
#define CSP_O_NOXTEA CSP_SO_XTEAPROHIB // Disable XTEA
|
||||
#define CSP_O_CRC32 CSP_SO_CRC32REQ // Enable CRC32
|
||||
#define CSP_O_NOCRC32 CSP_SO_CRC32PROHIB // Disable CRC32
|
||||
|
||||
/**
|
||||
* CSP PACKET STRUCTURE
|
||||
* Note: This structure is constructed to fit
|
||||
* with all interface frame types in order to
|
||||
* have buffer reuse
|
||||
*/
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
uint8_t padding[CSP_PADDING_BYTES]; /**< Interface dependent padding */
|
||||
uint16_t length; /**< Length field must be just before CSP ID */
|
||||
csp_id_t id; /**< CSP id must be just before data */
|
||||
union {
|
||||
uint8_t data[0]; /**< This just points to the rest of the buffer, without a size indication. */
|
||||
uint16_t data16[0]; /**< The data 16 and 32 types makes it easy to reference an integer (properly aligned) */
|
||||
uint32_t data32[0]; /**< without the compiler warning about strict aliasing rules. */
|
||||
};
|
||||
} csp_packet_t;
|
||||
|
||||
/** Interface TX function */
|
||||
struct csp_iface_s;
|
||||
typedef int (*nexthop_t)(struct csp_iface_s * interface, csp_packet_t *packet, uint32_t timeout);
|
||||
|
||||
/** Interface struct */
|
||||
typedef struct csp_iface_s {
|
||||
const char *name; /**< Interface name (keep below 10 bytes) */
|
||||
void * driver; /**< Pointer to interface handler structure */
|
||||
nexthop_t nexthop; /**< Next hop function */
|
||||
uint16_t mtu; /**< Maximum Transmission Unit of interface */
|
||||
uint8_t split_horizon_off; /**< Disable the route-loop prevention on if */
|
||||
uint32_t tx; /**< Successfully transmitted packets */
|
||||
uint32_t rx; /**< Successfully received packets */
|
||||
uint32_t tx_error; /**< Transmit errors */
|
||||
uint32_t rx_error; /**< Receive errors */
|
||||
uint32_t drop; /**< Dropped packets */
|
||||
uint32_t autherr; /**< Authentication errors */
|
||||
uint32_t frame; /**< Frame format errors */
|
||||
uint32_t txbytes; /**< Transmitted bytes */
|
||||
uint32_t rxbytes; /**< Received bytes */
|
||||
uint32_t irq; /**< Interrupts */
|
||||
struct csp_iface_s *next; /**< Next interface */
|
||||
} csp_iface_t;
|
||||
|
||||
/**
|
||||
* This define must be equal to the size of the packet overhead in csp_packet_t.
|
||||
* It is used in csp_buffer_get() to check the allocated buffer size against
|
||||
* the required buffer size.
|
||||
*/
|
||||
#define CSP_BUFFER_PACKET_OVERHEAD (sizeof(csp_packet_t) - sizeof(((csp_packet_t *)0)->data))
|
||||
|
||||
/** Forward declaration of socket and connection structures */
|
||||
typedef struct csp_conn_s csp_socket_t;
|
||||
typedef struct csp_conn_s csp_conn_t;
|
||||
|
||||
#define CSP_HOSTNAME_LEN 20
|
||||
#define CSP_MODEL_LEN 30
|
||||
|
||||
/* CSP_REBOOT magic values */
|
||||
#define CSP_REBOOT_MAGIC 0x80078007
|
||||
#define CSP_REBOOT_SHUTDOWN_MAGIC 0xD1E5529A
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* CSP_TYPES_H_ */
|
22
libcsp/include/csp/drivers/can_socketcan.h
Normal file
22
libcsp/include/csp/drivers/can_socketcan.h
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* can_socketcan.h
|
||||
*
|
||||
* Created on: Feb 6, 2017
|
||||
* Author: johan
|
||||
*/
|
||||
|
||||
#ifndef LIB_CSP_INCLUDE_CSP_DRIVERS_CAN_SOCKETCAN_H_
|
||||
#define LIB_CSP_INCLUDE_CSP_DRIVERS_CAN_SOCKETCAN_H_
|
||||
|
||||
#include <csp/csp_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
csp_iface_t * csp_can_socketcan_init(const char * ifc, int bitrate, int promisc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* LIB_CSP_INCLUDE_CSP_DRIVERS_CAN_SOCKETCAN_H_ */
|
120
libcsp/include/csp/drivers/i2c.h
Normal file
120
libcsp/include/csp/drivers/i2c.h
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common I2C interface,
|
||||
* This file is derived from the Gomspace I2C driver,
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef I2C_H_
|
||||
#define I2C_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The return value of the driver is a bit strange,
|
||||
* It should return E_NO_ERR if successfull and the value is -1
|
||||
*/
|
||||
#define E_NO_ERR -1
|
||||
|
||||
/**
|
||||
* Maximum transfer length on I2C
|
||||
*/
|
||||
#define I2C_MTU 256
|
||||
|
||||
/**
|
||||
I2C device modes
|
||||
@{
|
||||
*/
|
||||
/**
|
||||
I2C Master mode.
|
||||
*/
|
||||
#define I2C_MASTER 0
|
||||
/**
|
||||
I2C Slave mode.
|
||||
*/
|
||||
#define I2C_SLAVE 1
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
Data structure for I2C frames.
|
||||
This structs fits on top of #csp_packet_t, removing the need for copying data.
|
||||
*/
|
||||
typedef struct __attribute__((packed)) i2c_frame_s {
|
||||
//! Not used by CSP
|
||||
uint8_t padding;
|
||||
//! Not used by CSP - cleared before Tx
|
||||
uint8_t retries;
|
||||
//! Not used by CSP
|
||||
uint32_t reserved;
|
||||
//! Destination address
|
||||
uint8_t dest;
|
||||
//! Not used by CSP - cleared before Tx
|
||||
uint8_t len_rx;
|
||||
//! Length of \a data part
|
||||
uint16_t len;
|
||||
//! CSP data
|
||||
uint8_t data[I2C_MTU];
|
||||
} i2c_frame_t;
|
||||
|
||||
/**
|
||||
Callback for receiving data.
|
||||
|
||||
@param[in] frame received I2C frame
|
||||
@param[out] pxTaskWoken can be set, if context switch is required due to received data.
|
||||
*/
|
||||
typedef void (*i2c_callback_t) (i2c_frame_t * frame, void * pxTaskWoken);
|
||||
|
||||
/**
|
||||
Initialise the I2C driver
|
||||
|
||||
Functions is called by csp_i2c_init().
|
||||
|
||||
@param handle Which I2C bus (if more than one exists)
|
||||
@param mode I2C device mode. Must be either I2C_MASTER or I2C_SLAVE
|
||||
@param addr Own slave address
|
||||
@param speed Bus speed in kbps
|
||||
@param queue_len_tx Length of transmit queue
|
||||
@param queue_len_rx Length of receive queue
|
||||
@param callback If this value is set, the driver will call this function instead of using an RX queue
|
||||
@return Error code
|
||||
*/
|
||||
int i2c_init(int handle, int mode, uint8_t addr, uint16_t speed, int queue_len_tx, int queue_len_rx, i2c_callback_t callback);
|
||||
|
||||
/**
|
||||
User I2C transmit function.
|
||||
|
||||
Called by CSP, when sending message over I2C.
|
||||
|
||||
@param handle Handle to the device
|
||||
@param frame Pointer to I2C frame
|
||||
@param timeout Ticks to wait
|
||||
@return Error code
|
||||
*/
|
||||
int i2c_send(int handle, i2c_frame_t * frame, uint16_t timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
107
libcsp/include/csp/drivers/usart.h
Normal file
107
libcsp/include/csp/drivers/usart.h
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common USART interface,
|
||||
* This file is derived from the Gomspace USART driver,
|
||||
* the main difference is the assumption that only one USART will be present on a PC
|
||||
*/
|
||||
|
||||
#ifndef USART_H_
|
||||
#define USART_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
Usart configuration, to be used with the usart_init call.
|
||||
*/
|
||||
struct usart_conf {
|
||||
//! USART device.
|
||||
const char *device;
|
||||
//! bits per second.
|
||||
uint32_t baudrate;
|
||||
//! Number of data bits.
|
||||
uint8_t databits;
|
||||
//! Number of stop bits.
|
||||
uint8_t stopbits;
|
||||
//! Parity setting.
|
||||
uint8_t paritysetting;
|
||||
//! Enable parity checking (Windows only).
|
||||
uint8_t checkparity;
|
||||
};
|
||||
|
||||
/**
|
||||
Initialise UART with the usart_conf data structure
|
||||
@param[in] conf full configuration structure
|
||||
*/
|
||||
void usart_init(struct usart_conf *conf);
|
||||
|
||||
/**
|
||||
In order to catch incoming chars use the callback.
|
||||
Only one callback per interface.
|
||||
@param[in] handle usart[0,1,2,3]
|
||||
@param[in] callback function pointer
|
||||
*/
|
||||
typedef void (*usart_callback_t) (uint8_t *buf, int len, void *pxTaskWoken);
|
||||
|
||||
/**
|
||||
Set callback for receiving data.
|
||||
*/
|
||||
void usart_set_callback(usart_callback_t callback);
|
||||
|
||||
/**
|
||||
Insert a character to the RX buffer of a usart
|
||||
|
||||
@param[in] c character to insert
|
||||
@param[out] pxTaskWoken can be set, if context switch is required due to received data.
|
||||
*/
|
||||
void usart_insert(char c, void *pxTaskWoken);
|
||||
|
||||
/**
|
||||
Polling putchar (stdin).
|
||||
|
||||
@param[in] c Character to transmit
|
||||
*/
|
||||
void usart_putc(char c);
|
||||
|
||||
/**
|
||||
Send char buffer on UART (stdout).
|
||||
|
||||
@param[in] buf Pointer to data
|
||||
@param[in] len Length of data
|
||||
*/
|
||||
void usart_putstr(char *buf, int len);
|
||||
|
||||
/**
|
||||
Buffered getchar (stdin).
|
||||
|
||||
@return Character received
|
||||
*/
|
||||
char usart_getc(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* USART_H_ */
|
76
libcsp/include/csp/interfaces/csp_if_can.h
Normal file
76
libcsp/include/csp/interfaces/csp_if_can.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_IF_CAN_H_
|
||||
#define _CSP_IF_CAN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <csp/csp.h>
|
||||
#include <csp/csp_interface.h>
|
||||
|
||||
/* CAN header macros */
|
||||
#define CFP_HOST_SIZE 5
|
||||
#define CFP_TYPE_SIZE 1
|
||||
#define CFP_REMAIN_SIZE 8
|
||||
#define CFP_ID_SIZE 10
|
||||
|
||||
/* Macros for extracting header fields */
|
||||
#define CFP_FIELD(id,rsiz,fsiz) ((uint32_t)((uint32_t)((id) >> (rsiz)) & (uint32_t)((1 << (fsiz)) - 1)))
|
||||
#define CFP_SRC(id) CFP_FIELD(id, CFP_HOST_SIZE + CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_HOST_SIZE)
|
||||
#define CFP_DST(id) CFP_FIELD(id, CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_HOST_SIZE)
|
||||
#define CFP_TYPE(id) CFP_FIELD(id, CFP_REMAIN_SIZE + CFP_ID_SIZE, CFP_TYPE_SIZE)
|
||||
#define CFP_REMAIN(id) CFP_FIELD(id, CFP_ID_SIZE, CFP_REMAIN_SIZE)
|
||||
#define CFP_ID(id) CFP_FIELD(id, 0, CFP_ID_SIZE)
|
||||
|
||||
/* Macros for building CFP headers */
|
||||
#define CFP_MAKE_FIELD(id,fsiz,rsiz) ((uint32_t)(((id) & (uint32_t)((uint32_t)(1 << (fsiz)) - 1)) << (rsiz)))
|
||||
#define CFP_MAKE_SRC(id) CFP_MAKE_FIELD(id, CFP_HOST_SIZE, CFP_HOST_SIZE + CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE)
|
||||
#define CFP_MAKE_DST(id) CFP_MAKE_FIELD(id, CFP_HOST_SIZE, CFP_TYPE_SIZE + CFP_REMAIN_SIZE + CFP_ID_SIZE)
|
||||
#define CFP_MAKE_TYPE(id) CFP_MAKE_FIELD(id, CFP_TYPE_SIZE, CFP_REMAIN_SIZE + CFP_ID_SIZE)
|
||||
#define CFP_MAKE_REMAIN(id) CFP_MAKE_FIELD(id, CFP_REMAIN_SIZE, CFP_ID_SIZE)
|
||||
#define CFP_MAKE_ID(id) CFP_MAKE_FIELD(id, CFP_ID_SIZE, 0)
|
||||
|
||||
/* Mask to uniquely separate connections */
|
||||
#define CFP_ID_CONN_MASK (CFP_MAKE_SRC((uint32_t)(1 << CFP_HOST_SIZE) - 1) | \
|
||||
CFP_MAKE_DST((uint32_t)(1 << CFP_HOST_SIZE) - 1) | \
|
||||
CFP_MAKE_ID((uint32_t)(1 << CFP_ID_SIZE) - 1))
|
||||
|
||||
/**
|
||||
Default Maximum Transmission Unit (MTU) for CSP over CAN.
|
||||
Maximum value is 2042 bytes.
|
||||
*/
|
||||
#define CSP_CAN_MTU 256
|
||||
|
||||
int csp_can_rx(csp_iface_t *interface, uint32_t id, const uint8_t * data, uint8_t dlc, CSP_BASE_TYPE *task_woken);
|
||||
int csp_can_tx(csp_iface_t *interface, csp_packet_t *packet, uint32_t timeout);
|
||||
|
||||
/* Must be implemented by the driver */
|
||||
int csp_can_tx_frame(csp_iface_t *interface, uint32_t id, const uint8_t * data, uint8_t dlc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* _CSP_IF_CAN_H_ */
|
51
libcsp/include/csp/interfaces/csp_if_i2c.h
Normal file
51
libcsp/include/csp/interfaces/csp_if_i2c.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_IF_I2C_H_
|
||||
#define _CSP_IF_I2C_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <csp/csp.h>
|
||||
#include <csp/csp_interface.h>
|
||||
#include <csp/drivers/i2c.h>
|
||||
|
||||
extern csp_iface_t csp_if_i2c;
|
||||
|
||||
/**
|
||||
* Capture I2C RX events for CSP
|
||||
* @param opt_addr local i2c address
|
||||
* @param handle which i2c device to use
|
||||
* @param speed interface speed in kHz (normally 100 or 400)
|
||||
* @return csp_error.h code
|
||||
*/
|
||||
int csp_i2c_init(uint8_t opt_addr, int handle, int speed);
|
||||
|
||||
void csp_i2c_rx(i2c_frame_t * frame, void * pxTaskWoken);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* _CSP_IF_I2C_H_ */
|
110
libcsp/include/csp/interfaces/csp_if_kiss.h
Normal file
110
libcsp/include/csp/interfaces/csp_if_kiss.h
Normal file
@ -0,0 +1,110 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_IF_KISS_H_
|
||||
#define _CSP_IF_KISS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <csp/csp.h>
|
||||
#include <csp/csp_interface.h>
|
||||
|
||||
/**
|
||||
* The KISS interface relies on the USART callback in order to parse incoming
|
||||
* messaged from the serial interface. The USART callback however does not
|
||||
* support passing the handle number of the responding USART, so you need to implement
|
||||
* a USART callback for each handle and then call kiss_rx subsequently.
|
||||
*
|
||||
* In order to initialize the KISS interface. Fist call kiss_init() and then
|
||||
* setup your usart to call csp_kiss_rx when new data is available.
|
||||
*
|
||||
* When a byte is not a part of a kiss packet, it will be returned to your
|
||||
* usart driver using the usart_insert funtion that you provide.
|
||||
*
|
||||
* @param csp_iface pointer to interface
|
||||
* @param buf pointer to incoming data
|
||||
* @param len length of incoming data
|
||||
* @param pxTaskWoken NULL if task context, pointer to variable if ISR
|
||||
*/
|
||||
void csp_kiss_rx(csp_iface_t * interface, uint8_t *buf, int len, void *pxTaskWoken);
|
||||
|
||||
/**
|
||||
* The putc function is used by the kiss interface to send
|
||||
* a string of data to the serial port. This function must
|
||||
* be implemented by the user, and passed to the kiss
|
||||
* interface through the kiss_init function.
|
||||
* @param buf byte to push
|
||||
*/
|
||||
typedef void (*csp_kiss_putc_f)(char buf);
|
||||
|
||||
/**
|
||||
* The characters not accepted by the kiss interface, are discarded
|
||||
* using this function, which must be implemented by the user
|
||||
* and passed through the kiss_init function.
|
||||
*
|
||||
* This reject function is typically used to display ASCII strings
|
||||
* sent over the serial port, which are not in KISS format. Such as
|
||||
* debugging information.
|
||||
*
|
||||
* @param c rejected character
|
||||
* @param pxTaskWoken NULL if task context, pointer to variable if ISR
|
||||
*/
|
||||
typedef void (*csp_kiss_discard_f)(char c, void *pxTaskWoken);
|
||||
|
||||
typedef enum {
|
||||
KISS_MODE_NOT_STARTED,
|
||||
KISS_MODE_STARTED,
|
||||
KISS_MODE_ESCAPED,
|
||||
KISS_MODE_SKIP_FRAME,
|
||||
} kiss_mode_e;
|
||||
|
||||
/**
|
||||
* This structure should be statically allocated by the user
|
||||
* and passed to the kiss interface during the init function
|
||||
* no member information should be changed
|
||||
*/
|
||||
typedef struct csp_kiss_handle_s {
|
||||
//! Put character on usart (tx).
|
||||
csp_kiss_putc_f kiss_putc;
|
||||
//! Discard - not KISS data (rx).
|
||||
csp_kiss_discard_f kiss_discard;
|
||||
//! Internal KISS state.
|
||||
unsigned int rx_length;
|
||||
//! Internal KISS state.
|
||||
kiss_mode_e rx_mode;
|
||||
//! Internal KISS state.
|
||||
unsigned int rx_first;
|
||||
//! Not used.
|
||||
volatile unsigned char *rx_cbuf;
|
||||
//! Internal KISS state.
|
||||
csp_packet_t * rx_packet;
|
||||
} csp_kiss_handle_t;
|
||||
|
||||
void csp_kiss_init(csp_iface_t * csp_iface, csp_kiss_handle_t * csp_kiss_handle, csp_kiss_putc_f kiss_putc_f, csp_kiss_discard_f kiss_discard_f, const char * name);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* _CSP_IF_KISS_H_ */
|
38
libcsp/include/csp/interfaces/csp_if_lo.h
Normal file
38
libcsp/include/csp/interfaces/csp_if_lo.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
|
||||
Copyright (C) 2012 GomSpace ApS (http://www.gomspace.com)
|
||||
Copyright (C) 2012 AAUSAT3 Project (http://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
|
||||
*/
|
||||
|
||||
#ifndef _CSP_IF_LO_H_
|
||||
#define _CSP_IF_LO_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* CSP includes */
|
||||
#include <csp/csp.h>
|
||||
#include <csp/csp_interface.h>
|
||||
|
||||
extern csp_iface_t csp_if_lo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif // _CSP_IF_LO_H_
|
26
libcsp/include/csp/interfaces/csp_if_zmqhub.h
Normal file
26
libcsp/include/csp/interfaces/csp_if_zmqhub.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef CSP_IF_ZMQHUB_H_
|
||||
#define CSP_IF_ZMQHUB_H_
|
||||
|
||||
#include <csp/csp.h>
|
||||
|
||||
extern csp_iface_t csp_if_zmqhub;
|
||||
|
||||
/**
|
||||
* Setup ZMQ interface
|
||||
* @param addr only receive messages matching this address (255 means all)
|
||||
* @param host Pointer to string containing zmqproxy host
|
||||
* @return CSP_ERR
|
||||
*/
|
||||
int csp_zmqhub_init(uint8_t addr, const char * host);
|
||||
|
||||
/**
|
||||
* Setup ZMQ interface
|
||||
* @param addr only receive messages matching this address (255 means all)
|
||||
* @param publisher_endpoint Pointer to string containing zmqproxy publisher endpoint
|
||||
* @param subscriber_endpoint Pointer to string containing zmqproxy subscriber endpoint
|
||||
* @return CSP_ERR
|
||||
*/
|
||||
int csp_zmqhub_init_w_endpoints(uint8_t addr, const char * publisher_url,
|
||||
const char * subscriber_url);
|
||||
|
||||
#endif /* CSP_IF_ZMQHUB_H_ */
|
Reference in New Issue
Block a user