Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: triffid/netrap
base: 54c3f3526e
...
head fork: triffid/netrap
compare: b45a1ce8bf
  • 2 commits
  • 19 files changed
  • 0 commit comments
  • 1 contributor
View
29 controller/C++/Makefile
@@ -0,0 +1,29 @@
+PROJECT=netrap-controller
+
+CSRC=$(wildcard *.c)
+CXXSRC= $(wildcard *.cpp)
+
+OBJ=$(patsubst %.c,%.o,$(CSRC)) $(patsubst %.cpp,%.o,$(CXXSRC))
+
+CFLAGS=-std=gnu99 -O2 -fdata-sections -ffunction-sections -Wall
+CXXFLAGS=-O2 -fdata-sections -ffunction-sections -Wall
+LDFLAGS=-Wl,--as-needed -Wl,--gc-sections
+
+.PHONY: all clean
+
+all: $(PROJECT)
+
+$(PROJECT): $(PROJECT).elf
+ cp $< $@
+
+clean:
+ rm -rf $(OBJ) $(PROJECT).elf $(PROJECT) *~
+
+%.elf: $(OBJ)
+ g++ $(LDFLAGS) -o $@ $^
+
+%.o: %.c Makefile
+ gcc -c $(CFLAGS) -o $@ $<
+
+%.o: %.cPP Makefile
+ g++ -c $(CXXFLAGS) -o $@ $<
View
77 controller/C++/array.cpp
@@ -0,0 +1,77 @@
+#include "array.hpp"
+
+#include <stdlib.h>
+#include <string.h>
+
+Array::Array() {
+ len = 0;
+ data = NULL;
+}
+
+Array::~Array() {
+ if (data)
+ free(data);
+}
+
+unsigned int Array::length() {
+ return len;
+}
+
+void Array::push(void *element) {
+ len++;
+ if (data == NULL)
+ data = (void **) malloc(sizeof(void *) * len);
+ else
+ data = (void **) realloc(data, sizeof(void *) * len);
+
+ data[len - 1] = element;
+}
+
+void * Array::pop() {
+ if (len) {
+ len--;
+ void *r = data[len];
+ data = (void **) realloc(data, sizeof(void *) * len);
+ return r;
+ }
+ return NULL;
+}
+
+void *Array::shift() {
+ if (len) {
+ len--;
+ void *r = data[0];
+ data = (void **) memmove(data, &data[1], sizeof(void *) * len);
+ data = (void **) realloc(data, sizeof(void *) * len);
+ return r;
+ }
+ return NULL;
+}
+
+void Array::unshift(void *element) {
+ len++;
+ if (data == NULL)
+ data = (void **) malloc(sizeof(void *) * len);
+ else
+ data = (void **) realloc(data, sizeof(void *) * len);
+ data = (void **) memmove(&data[1], data, sizeof(void *) * (len - 1));
+ data[0] = element;
+}
+
+int Array::indexof(void *element) {
+ for (unsigned int i = 0; i < len; i++) {
+ if (data[i] == element)
+ return i;
+ }
+ return -1;
+}
+
+void Array::remove(void *element) {
+ int i = indexof(element);
+ if (i >= 0) {
+ len--;
+ if (len > ((unsigned int) i))
+ data = (void **) memmove(&data[i], &data[(i + 1)], (len - i) * sizeof(void *));
+ data = (void **) realloc(data, sizeof(void *) * len);
+ }
+}
View
19 controller/C++/array.hpp
@@ -0,0 +1,19 @@
+#ifndef _ARRAY_H
+#define _ARRAY_H
+
+class Array {
+ Array(void);
+ ~Array(void);
+ unsigned int length(void);
+ void push(void *element);
+ void * pop(void);
+ void unshift(void *element);
+ void * shift(void);
+ int indexof(void *element);
+ void remove(void *element);
+private:
+ unsigned int len;
+ void ** data;
+};
+
+#endif /* _ARRAY_H */
View
11 controller/C++/main.cpp
@@ -0,0 +1,11 @@
+#include <iostream>
+#include <cstdio>
+
+#include "array.hpp"
+#include "ringbuffer.hpp"
+
+int main(int argc, char **argv) {
+ Ringbuffer *r = new Ringbuffer(1024);
+ r->writefromfd(stdin, 1024);
+ cout << r->readtofd(stdout, 1024) << " chars written" << endl;
+}
View
50 controller/C++/printer.cpp
@@ -0,0 +1,50 @@
+#include "printer.hpp"
+
+#include <cstdio>
+
+namespace C {
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+}
+
+Printer::Printer() {
+ this->fd = -1;
+}
+
+Printer::Printer(int fd) {
+ open(fd);
+}
+
+Printer::Printer(char *port, int baud) {
+ open(port, baud);
+}
+
+Printer::~Printer() {
+ close();
+}
+
+int Printer::open(int fd) {
+ Printer::fd = fd;
+ gettimeofday(&opentime, NULL);
+ return 1;
+}
+
+int Printer::open(char *port, int baud) {
+ fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK);
+ if (fd != -1) {
+ return open(fd);
+ }
+ return fd;
+}
+
+int Printer::opened() {
+ return fd;
+}
+
+void Printer::close() {
+ if (fd != -1)
+ C::close(fd);
+ fd = -1;
+}
View
20 controller/C++/printer.hpp
@@ -0,0 +1,20 @@
+#ifndef _PRINTER_HPP
+
+#include <sys/time.h>
+
+class Printer {
+ Printer(void);
+ Printer(int fd);
+ Printer(char *port, int baud);
+ ~Printer(void);
+public:
+ int open(char *port, int baud);
+ int open(int fd);
+ int opened();
+ void close();
+private:
+ int fd;
+ timeval opentime;
+};
+
+#endif /* _PRINTER_HPP */
View
7 controller/C++/queuemanager.cpp
@@ -0,0 +1,7 @@
+#include "queuemanager.hpp"
+
+QueueManager::QueueManager() {
+}
+
+QueueManager::~QueueManager() {
+}
View
11 controller/C++/queuemanager.hpp
@@ -0,0 +1,11 @@
+#ifndef _QUEUEMANAGER_HPP
+#define _QUEUEMANAGER_HPP
+
+class QueueManager {
+ QueueManager();
+ ~QueueManager();
+public:
+private:
+};
+
+#endif /* _QUEUEMANAGER_HPP */
View
167 controller/C++/ringbuffer.cpp
@@ -0,0 +1,167 @@
+#include "ringbuffer.hpp"
+
+#include <stdlib.h>
+#include <string.h>
+#include <cstdio>
+
+Ringbuffer::Ringbuffer(unsigned int size) {
+ data = (char *) malloc(size);
+ length = size;
+ head = 0;
+ tail = 0;
+ nl = 0;
+}
+
+Ringbuffer::~Ringbuffer() {
+ free(data);
+}
+
+unsigned int Ringbuffer::numlines() {
+ return nl;
+}
+
+unsigned int Ringbuffer::scannl() {
+ nl = 0;
+ for (unsigned int i = tail; i != head; i++) {
+ if (i >= length)
+ i -= length;
+ if (data[i] == 10)
+ nl++;
+ }
+ return nl;
+}
+
+unsigned int Ringbuffer::canread() {
+ return (head - tail) % length;
+}
+
+unsigned int Ringbuffer::canwrite() {
+ return (tail - head + (length - 1)) % length;
+}
+
+unsigned int Ringbuffer::read(char *buf, unsigned int len) {
+ if (len > canread())
+ len = canread();
+
+ unsigned int stage1 = length - tail;
+ unsigned int stage2 = 0;
+
+ if (stage1 > len)
+ stage1 = len;
+ if (stage1 < len) {
+ stage2 = len - stage1;
+ stage1 = len;
+ }
+
+ memcpy(buf, &data[tail], stage1);
+
+ tail += stage1;
+ if (tail >= length) tail -= length;
+
+ if (stage2) {
+ memcpy(&buf[stage1], &data[tail], stage2);
+ tail += stage2;
+ if (tail >= length) tail -= length;
+ }
+
+ scannl();
+
+ return len;
+}
+
+unsigned int Ringbuffer::readtofd(FILE * fd, unsigned int len) {
+ if (len > canread())
+ len = canread();
+
+ unsigned int stage1 = length - tail;
+ if (stage1 > len)
+ stage1 = len;
+
+ stage1 = fwrite(&data[tail], 1, stage1, fd);
+
+ tail += stage1;
+ if (stage1 >= length) stage1 -= length;
+
+ scannl();
+
+ return stage1;
+}
+
+unsigned int Ringbuffer::peekline(char *buf, unsigned int len) {
+ if (nl == 0)
+ return 0;
+
+ len--; // make room for trailing 0
+
+ if (len > canread())
+ len = canread();
+
+ unsigned int t = tail;
+ for (unsigned int i = 0; i < len; i++) {
+ buf[i] = data[t];
+ t = (t + 1) % length;
+ if (buf[i] == 10) {
+ buf[++i] = 0;
+ return i;
+ }
+ }
+ return 0;
+}
+
+unsigned int Ringbuffer::readline(char *buf, unsigned int len) {
+ unsigned int r = peekline(buf, len);
+ if (r > 0) {
+ tail = (tail + r) % length;
+ nl--;
+ }
+ return r;
+}
+
+unsigned int Ringbuffer::write(char *buf, unsigned int len) {
+ if (len > canwrite())
+ len = canwrite();
+
+ unsigned int stage1 = length - head;
+ unsigned int stage2 = 0;
+
+ if (stage1 > len)
+ stage1 = len;
+ if (stage1 < len) {
+ stage2 = len - stage1;
+ }
+
+ memcpy(&data[head], buf, stage1);
+
+ head += stage1;
+ if (head >= length) head -= length;
+
+ if (stage2 > 0) {
+ memcpy(&data[head], &buf[stage1], stage2);
+
+ head += stage2;
+ if (head >= length) head -= length;
+ }
+
+ scannl();
+
+ return len;
+}
+
+unsigned int Ringbuffer::writefromfd(FILE *fd, unsigned int len) {
+ if (len > canwrite())
+ len = canwrite();
+
+ unsigned int stage1 = length - head;
+
+ if (stage1 > len)
+ stage1 = len;
+
+ stage1 = fread(&data[head], 1, stage1, fd);
+
+ head += stage1;
+ if (head >= length) head -= length;
+
+ scannl();
+
+ return stage1;
+}
View
59 controller/C++/ringbuffer.hpp
@@ -0,0 +1,59 @@
+#ifndef _RINGBUFFER_H
+#define _RINGBUFFER_H
+
+#include <iostream>
+using namespace std;
+
+class Ringbuffer {
+public:
+ Ringbuffer(unsigned int length);
+ ~Ringbuffer();
+
+ unsigned int numlines();
+
+ unsigned int canread();
+ unsigned int canwrite();
+
+ unsigned int read(char *buf, unsigned int len);
+ unsigned int readtofd(FILE *fd, unsigned int len);
+
+ unsigned int peekline(char *buf, unsigned int len);
+ unsigned int readline(char *buf, unsigned int len);
+
+ unsigned int write(char *buf, unsigned int len);
+ unsigned int writefromfd(FILE *fd, unsigned int len);
+private:
+ unsigned int scannl();
+ unsigned int length;
+ unsigned int head;
+ unsigned int tail;
+ char *data;
+ unsigned int nl;
+};
+/*
+typedef struct {
+ unsigned int head;
+ unsigned int tail;
+ char data[1024];
+ unsigned int nl;
+} ringbuffer;
+
+void ringbuffer_init(ringbuffer *rb);
+
+unsigned int ringbuffer_canread(ringbuffer *rb);
+unsigned int ringbuffer_canwrite(ringbuffer *rb);
+
+void ringbuffer_status(ringbuffer *rb);
+void ringbuffer_scannl(ringbuffer *rb);
+
+unsigned int ringbuffer_read(ringbuffer *rb, char *buffer, unsigned int maxchars);
+unsigned int ringbuffer_readtofd(ringbuffer *rb, int fd);
+
+unsigned int ringbuffer_peekline(ringbuffer *rb, char *linebuffer, unsigned int maxchars);
+unsigned int ringbuffer_readline(ringbuffer *rb, char *linebuffer, unsigned int maxchars);
+
+unsigned int ringbuffer_write(ringbuffer *rb, char *buffer, unsigned int maxchars);
+unsigned int ringbuffer_writefromfd(ringbuffer *rb, int fd, unsigned int nchars);
+unsigned int ringbuffer_writefromsock(ringbuffer *rb, int fd, unsigned int nchars);
+*/
+#endif /* _RINGBUFFER_H */
View
0  controller/C++/socket-file.cpp
No changes.
View
0  controller/C++/socket-file.hpp
No changes.
View
0  controller/C++/socket-pipe.cpp
No changes.
View
0  controller/C++/socket-pipe.hpp
No changes.
View
0  controller/C++/socket-tcp.cpp
No changes.
View
0  controller/C++/socket-tcp.hpp
No changes.
View
14 controller/C++/socket.cpp
@@ -0,0 +1,14 @@
+#include "socket.hpp"
+
+namespace C {
+#include <unistd.h>
+}
+
+Socket::Socket() {
+ fd = -1;
+}
+
+Socket::~Socket() {
+ if (fd != -1)
+ C::close(fd);
+}
View
12 controller/C++/socket.hpp
@@ -0,0 +1,12 @@
+#ifndef _SOCKET_HPP
+#define _SOCKET_HPP
+
+class Socket {
+ Socket();
+ ~Socket();
+public:
+private:
+ int fd;
+};
+
+#endif /* _SOCKET_HPP */
View
4 html/js/netrap.js
@@ -130,13 +130,13 @@ netrapUplink.prototype = {
return this.currentPrinter;
},
refreshTemperatureList: function() {
- this.sendCmd('M105');
+ this.query('M105');
},
temperatureList: function() {
return this.temperatures;
},
refreshPosition: function() {
- return this.query('M114');
+ this.query('M114');
},
position: function() {
return this.lastPos;

No commit comments for this range

Something went wrong with that request. Please try again.