Line 10... |
Line 10... |
#include <fcntl.h>
|
#include <fcntl.h>
|
#include <unistd.h>
|
#include <unistd.h>
|
#include <termios.h>
|
#include <termios.h>
|
|
|
|
|
#define SERIAL_PORT "/dev/ttyS0"
|
|
|
|
#define SYN ((unsigned char) 's')
|
#define SYN ((unsigned char) 's')
|
#define ACK ((unsigned char) 'a')
|
#define ACK ((unsigned char) 'a')
|
|
|
#define LINE_SIZE 520
|
#define LINE_SIZE 520
|
|
|
Line 50... |
Line 48... |
}
|
}
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
|
|
void serialOpen(void) {
|
void serialOpen(char *serialPort) {
|
sfd = open(SERIAL_PORT, O_RDWR | O_NOCTTY | O_NDELAY);
|
sfd = open(serialPort, O_RDWR | O_NOCTTY | O_NDELAY);
|
if (sfd == -1) {
|
if (sfd == -1) {
|
error("cannot open serial port '%s'", SERIAL_PORT);
|
error("cannot open serial port '%s'", serialPort);
|
}
|
}
|
tcgetattr(sfd, &origOptions);
|
tcgetattr(sfd, &origOptions);
|
currOptions = origOptions;
|
currOptions = origOptions;
|
cfsetispeed(&currOptions, B38400);
|
cfsetispeed(&currOptions, B38400);
|
cfsetospeed(&currOptions, B38400);
|
cfsetospeed(&currOptions, B38400);
|
Line 69... |
Line 67... |
currOptions.c_cflag &= ~CRTSCTS;
|
currOptions.c_cflag &= ~CRTSCTS;
|
currOptions.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG | IEXTEN);
|
currOptions.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG | IEXTEN);
|
currOptions.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK);
|
currOptions.c_iflag &= ~(IGNBRK | BRKINT | IGNPAR | PARMRK);
|
currOptions.c_iflag &= ~(INPCK | ISTRIP | INLCR | IGNCR | ICRNL);
|
currOptions.c_iflag &= ~(INPCK | ISTRIP | INLCR | IGNCR | ICRNL);
|
currOptions.c_iflag &= ~(IXON | IXOFF | IXANY);
|
currOptions.c_iflag &= ~(IXON | IXOFF | IXANY);
|
currOptions.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONOCR | ONLRET | OFILL);
|
currOptions.c_oflag &= ~(OPOST | ONLCR | OCRNL | ONOCR | ONLRET);
|
tcsetattr(sfd, TCSANOW, &currOptions);
|
tcsetattr(sfd, TCSANOW, &currOptions);
|
}
|
}
|
|
|
|
|
void serialClose(void) {
|
void serialClose(void) {
|
Line 120... |
Line 118... |
unsigned char b;
|
unsigned char b;
|
unsigned char cmd;
|
unsigned char cmd;
|
char line[LINE_SIZE];
|
char line[LINE_SIZE];
|
int n, i;
|
int n, i;
|
|
|
if (argc != 2) {
|
if (argc != 3) {
|
printf("Usage: %s <file to be loaded>\n", argv[0]);
|
printf("Usage: %s <serial port> <file to be loaded>\n", argv[0]);
|
exit(1);
|
exit(1);
|
}
|
}
|
loadName = argv[1];
|
loadName = argv[2];
|
loadFile = fopen(loadName, "rt");
|
loadFile = fopen(loadName, "rt");
|
if (loadFile == NULL) {
|
if (loadFile == NULL) {
|
error("cannot open file to be loaded '%s'", loadName);
|
error("cannot open file to be loaded '%s'", loadName);
|
}
|
}
|
/* open serial interface */
|
/* open serial interface */
|
serialOpen();
|
serialOpen(argv[1]);
|
/* wait for client to connect */
|
/* wait for client to connect */
|
printf("Waiting for client...\n");
|
printf("Waiting for client...\n");
|
while (1) {
|
while (1) {
|
if (serialRcv(&b) && b == SYN) {
|
if (serialRcv(&b) && b == SYN) {
|
break;
|
break;
|