5ebac62375423cb31a947cce277107bff6aea49a
7 #include "stm32f7xx_hal.h"
13 #include <netinet/in.h>
15 #include <sys/socket.h>
17 #include <sys/types.h>
21 #include "interpret.h"
22 #include "mTaskSymbols.h"
27 #define MSG_GET_TASK 't'
28 #define MSG_DEL_TASK 'd'
29 #define MSG_SDS_SPEC 's'
30 #define MSG_SDS_UPD 'u'
39 volatile char uartf
= 0;
49 #define SET_LED_RED GPIOB->BSRR = GPIO_PIN_14
50 #define RESET_LED_RED GPIOB->BSRR = GPIO_PIN_14 << 16
52 #define SET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7
53 #define RESET_LED_BLUE GPIOB->BSRR = GPIO_PIN_7 << 16
55 #define SET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0
56 #define RESET_LED_GREEN GPIOB->BSRR = GPIO_PIN_0 << 16
62 if (gettimeofday(&tv1
, NULL
) == -1)
64 return tv1
.tv_sec
*1000 + tv1
.tv_usec
/1000;
68 bool input_available(){
78 if (select(fd
+1, &fds
, NULL
, NULL
, &tv
) == -1)
80 return FD_ISSET(fd
, &fds
);
87 HAL_UART_Receive(&huart3
, &bt
, 1, 1000);
95 void write_byte(uint8_t b
)
98 HAL_UART_Transmit_DMA(&huart3
, &b
, 1);
114 void killHandler(int i
)
116 printf("%i caught, Bye...\n", i
);
122 void HAL_UART_TxCpltCallback(UART_HandleTypeDef
*UartHandle
)
131 uint8_t c
= read_byte();
132 debug("Receiving input: %c\n", c
);
135 debug("Receiving an sds\n");
139 debug("Receiving an sds\n");
140 //TODO do something with the return value
144 debug("Receiving a delete task request\n");
148 debug("Receiving a task\n");
154 debug("Unknown message: %X\n", c
);
158 void usage(FILE *o
, char *arg0
){
159 fprintf(o
, "Usage: %s [opts]\n\nOptions\n"
160 "-p PORT Custom port number, default: 8123\n" , arg0
);
167 int port
= 8123, opti
= 1;
168 //Register signal handler
169 if(signal(SIGINT
, killHandler
) == SIG_ERR
){
170 die("Couldn't register signal handler...\n");
172 if(signal(SIGTERM
, killHandler
) == SIG_ERR
){
173 die("Couldn't register signal handler...\n");
175 //Command line arguments
177 if(strcmp((*argv
)+opti
, "-h") == 0){
178 usage(stdout
, argv
[0]);
180 } else if(strcmp(argv
[opti
], "-p") == 0 && opti
+1<*argc
){
181 port
= atoi(argv
[++opti
]);
183 die("Port numbers are > 1\n");
185 usage(stderr
, argv
[0]);
191 //Open file descriptors
192 struct sockaddr_in sa
;
194 memset(&sa
, 0, sizeof(sa
));
195 sa
.sin_family
= AF_INET
;
196 sa
.sin_addr
.s_addr
= INADDR_ANY
;
197 sa
.sin_port
= htons(port
);
199 if((sock_fd
= socket(AF_INET
, SOCK_STREAM
, 0)) == -1)
201 if(bind(sock_fd
, (struct sockaddr
*)&sa
, sizeof(sa
)) == -1)
203 if(listen(sock_fd
, 10) == -1)
206 printf("Listening on %d\n", port
);
208 if((fd
= accept(sock_fd
, (struct sockaddr
*)NULL
, NULL
)) == -1)
221 struct task
*curtask
;
222 if(input_available())
225 cyclestart
= millis();
226 for(ct
= 0; ct
<MAXTASKS
; ct
++){
227 //See whether the task is even in use
228 if((curtask
= task_get(ct
)) == NULL
){
229 // debug("Task %d not implemented\n", ct);
232 //See whether the task interval has passed
233 if(cyclestart
-curtask
->lastrun
< curtask
->interval
){
234 // debug("Task %d not scheduled\n", ct);
238 printf("Current task to run: %d\n", ct
);
249 int main(int ac
, char *av
[])
261 //Check for new tasks
263 debug("Waiting for 500ms\n");
265 debug("done waiting\n");