Update simlight test
This commit is contained in:
parent
b90dfdfc31
commit
0f29394aa7
|
|
@ -2,19 +2,13 @@
|
|||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <libserialport.h>
|
||||
#include "../src/monocoque/simulatorapi/simapi/simapi/simdata.h"
|
||||
#include "../src/arduino/shiftlights/shiftlights.h"
|
||||
|
||||
/* Helper function for error handling. */
|
||||
int check(enum sp_return result);
|
||||
|
||||
int main()
|
||||
{
|
||||
SimData sd;
|
||||
sd.maxrpm = 6500;
|
||||
sd.rpms = 0;
|
||||
sd.altitude = 10;
|
||||
sd.gear = 1;
|
||||
sd.velocity = 74;
|
||||
|
||||
char* port_name = "/dev/ttyACM0";
|
||||
|
||||
|
|
@ -28,24 +22,30 @@ int main()
|
|||
printf("Opening port.\n");
|
||||
check(sp_open(port, SP_MODE_READ_WRITE));
|
||||
|
||||
printf("Setting port to 9600 8N1, no flow control.\n");
|
||||
check(sp_set_baudrate(port, 9600));
|
||||
printf("Setting port to 115200 8N1, no flow control.\n");
|
||||
check(sp_set_baudrate(port, 115200));
|
||||
check(sp_set_bits(port, 8));
|
||||
check(sp_set_parity(port, SP_PARITY_NONE));
|
||||
check(sp_set_stopbits(port, 1));
|
||||
check(sp_set_flowcontrol(port, SP_FLOWCONTROL_NONE));
|
||||
|
||||
while ( sd.rpms <= sd.maxrpm )
|
||||
ShiftLightsData sd;
|
||||
|
||||
|
||||
int result;
|
||||
unsigned int timeout = 2000;
|
||||
size_t size = sizeof(ShiftLightsData);
|
||||
for( sd.litleds = 0; sd.litleds < 7; sd.litleds++)
|
||||
{
|
||||
|
||||
|
||||
unsigned int timeout = 2000;
|
||||
|
||||
|
||||
/* On success, sp_blocking_write() and sp_blocking_read()
|
||||
* return the number of bytes sent/received before the
|
||||
* timeout expired. We'll store that result here. */
|
||||
int result;
|
||||
int size = sizeof(SimData);
|
||||
|
||||
|
||||
|
||||
/* Send data. */
|
||||
result = check(sp_blocking_write(port, &sd, size, timeout));
|
||||
|
|
@ -53,25 +53,18 @@ int main()
|
|||
/* Check whether we sent all of the data. */
|
||||
if (result == size)
|
||||
{
|
||||
printf("Sent %d bytes successfully, %i rpm.\n", size, sd.rpms);
|
||||
printf("Sent %d bytes successfully, %i lit leds.\n", size, sd.litleds);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Timed out, %d/%d bytes sent.\n", result, size);
|
||||
}
|
||||
|
||||
sd.rpms += 1000;
|
||||
if ( sd.rpms == sd.maxrpm + 1000 )
|
||||
{
|
||||
sd.rpms = 0;
|
||||
}
|
||||
if ( sd.rpms > sd.maxrpm )
|
||||
{
|
||||
sd.rpms = sd.maxrpm;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
sleep(2);
|
||||
}
|
||||
sd.litleds = 0;
|
||||
result = check(sp_blocking_write(port, &sd, size, timeout));
|
||||
|
||||
check(sp_close(port));
|
||||
sp_free_port(port);
|
||||
|
|
|
|||
Loading…
Reference in New Issue