Started linux port
This commit is contained in:
parent
2e91369e2c
commit
9b23d8a620
|
@ -0,0 +1 @@
|
|||
-I../sss7core
|
|
@ -0,0 +1,40 @@
|
|||
VERSION = 0.1
|
||||
|
||||
HEADERS = ../sss7core/sss7.h libsss7.h
|
||||
OBJDIR = bin
|
||||
|
||||
CC = clang
|
||||
|
||||
CFLAGS = -I ../sss7core/ -Os -Wall -Wstrict-prototypes -fPIC
|
||||
LDFLAGS = -Wl,--gc-sections
|
||||
|
||||
all: start $(OBJDIR)/libsss7.so $(OBJDIR)/test
|
||||
@echo ":: Done !"
|
||||
|
||||
start:
|
||||
@echo " SSS7 linux port $(VERSION)"
|
||||
@echo "=========================="
|
||||
|
||||
$(OBJDIR)/test : $(OBJDIR)/test.o $(OBJDIR)/sss7core/sss7.o $(OBJDIR)/libsss7.so
|
||||
|
||||
$(OBJDIR)/%.o : %.c $(HEADERS) Makefile
|
||||
@mkdir -p $$(dirname $@)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/sss7core/%.o : ../sss7core/%.c $(HEADERS) Makefile
|
||||
@mkdir -p $$(dirname $@)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
$(OBJDIR)/%.so : $(OBJDIR)/%.o
|
||||
@mkdir -p $$(dirname $@)
|
||||
$(CC) $+ -shared $(LDFLAGS) -o $@
|
||||
|
||||
$(OBJDIR)/$(TARGET) : $(TARGET).o
|
||||
$(CC) $(LDFLAGS) $+ -o $@
|
||||
|
||||
|
||||
clean :
|
||||
@rm -rf $(OBJDIR)
|
||||
|
||||
test: all
|
||||
$(OBJDIR)/test
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,96 @@
|
|||
#include "libsss7.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <termios.h>
|
||||
|
||||
uint8_t uart_rx_byte;
|
||||
uint8_t uart_tx_byte, uart_has_tx_byte;
|
||||
|
||||
int serial_fd;
|
||||
|
||||
int libsss7_start(char *serialport) {
|
||||
sss7_init();
|
||||
|
||||
serial_fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY);
|
||||
if (serial_fd == -1) {
|
||||
perror("Error: Unable to open serialport");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Switch to blocking mode
|
||||
fcntl(serial_fd, F_SETFL, 0);
|
||||
|
||||
struct termios options;
|
||||
cfsetispeed(&options, B9600);
|
||||
cfsetospeed(&options, B9600);
|
||||
|
||||
// 8N1
|
||||
options.c_cflag = (CLOCAL | CREAD);
|
||||
options.c_cflag |= CS8;
|
||||
|
||||
// Raw mode, no features
|
||||
options.c_lflag = 0;
|
||||
|
||||
// No parity checks, no flow control
|
||||
options.c_iflag = 0;
|
||||
|
||||
// No output processing
|
||||
options.c_oflag = 0;
|
||||
|
||||
options.c_cc[VTIME] = 20;
|
||||
options.c_cc[VMIN] = 0;
|
||||
tcsetattr(serial_fd, TCSAFLUSH, &options);
|
||||
|
||||
int res = 0;
|
||||
while(1) {
|
||||
res = read(serial_fd, &uart_rx_byte, 1);
|
||||
if(res == 1) {
|
||||
sss7_process_rx();
|
||||
}
|
||||
|
||||
if(uart_has_tx_byte) {
|
||||
uart_has_tx_byte = 0;
|
||||
write(serial_fd, &uart_has_tx_byte, 1);
|
||||
sss7_process_tx();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int libsss7_can_send(void) {
|
||||
return sss7_can_send();
|
||||
}
|
||||
|
||||
void libsss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]) {
|
||||
|
||||
}
|
||||
|
||||
int libsss7_send_failed(void) {
|
||||
return sss7_send_failed();
|
||||
}
|
||||
|
||||
int libsss7_has_received(void) {
|
||||
return sss7_has_received();
|
||||
}
|
||||
|
||||
void libsss7_get_received(uint8_t msg[SSS7_PAYLOAD_SIZE]) {
|
||||
return sss7_get_received(msg);
|
||||
}
|
||||
|
||||
void libsss7_stop() {
|
||||
close(serial_fd);
|
||||
}
|
||||
|
||||
uint8_t uart_get_byte(void) {
|
||||
return uart_rx_byte;
|
||||
}
|
||||
|
||||
void uart_put_byte(uint8_t byte) {
|
||||
uart_has_tx_byte = 1;
|
||||
uart_tx_byte = byte;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#ifndef _LIBSSS7_H_
|
||||
#define _LIBSSS7_H_
|
||||
|
||||
#include "sss7.h"
|
||||
|
||||
|
||||
int libsss7_start(char *serialport);
|
||||
|
||||
int libsss7_can_send(void);
|
||||
|
||||
void libsss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]);
|
||||
|
||||
int libsss7_send_failed(void);
|
||||
|
||||
int libsss7_has_received(void);
|
||||
|
||||
void libsss7_get_received(uint8_t msg[SSS7_PAYLOAD_SIZE]);
|
||||
|
||||
void libsss7_stop();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libsss7.h"
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
libsss7_start("/tmp/ttyVA");
|
||||
|
||||
libsss7_stop();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue