fix controller for ftdi485
This commit is contained in:
@@ -47,7 +47,7 @@ int deviceMap[SFDEVICE_MAX_X][SFDEVICE_MAX_Y];
|
||||
|
||||
struct SFDEVICE devices[SFDEVICE_MAXDEV];
|
||||
|
||||
const char *symbols[] = {" ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
|
||||
const char *symbols[45] = {" ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
|
||||
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "Ä", "Ö", "Ü",
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ".", "-", "?", "!"};
|
||||
|
||||
@@ -186,9 +186,18 @@ json_object *devicemgr_printDetailsAll()
|
||||
return root;
|
||||
}
|
||||
|
||||
void setSingle(int id, u_int8_t flap)
|
||||
void setSingle(int id, char flap)
|
||||
{
|
||||
sfbus_display_full(devices[id].rs485_descriptor, devices[id].address, flap);
|
||||
// first convert char to flap id
|
||||
char test_char = toupper(flap);
|
||||
printf("find char %c\n", test_char);
|
||||
for (int ix = 0; ix < 45; ix++){
|
||||
if (*symbols[ix] == test_char){
|
||||
printf("match char %i %i %i\n",test_char, *symbols[ix], ix);
|
||||
sfbus_display_full(devices[id].rs485_descriptor, devices[id].address, ix);
|
||||
break;
|
||||
}
|
||||
}
|
||||
devices[nextFreeSlot].current_flap = flap;
|
||||
}
|
||||
|
||||
@@ -199,7 +208,10 @@ void printText(char *text, int x, int y)
|
||||
int this_id = deviceMap[x + i][y];
|
||||
if (this_id >= 0)
|
||||
{
|
||||
setSingle(devices[this_id].address, *(text + i));
|
||||
printf("print char %c to %i\n",*(text + i), devices[this_id].address);
|
||||
|
||||
setSingle(this_id, *(text + i));
|
||||
usleep(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
#include <json-c/json_object.h>
|
||||
#include <sys/types.h>
|
||||
#include <json-c/json.h>
|
||||
#include <ctype.h>
|
||||
|
||||
int devicemgr_readStatus(int device_id) ;
|
||||
json_object * devicemgr_printDetails(int device_id);
|
||||
json_object * devicemgr_printDetailsAll();
|
||||
int devicemgr_register(int rs485_descriptor, u_int16_t address, int x,int y);
|
||||
void devicemgr_init();
|
||||
void devicemgr_init();
|
||||
int devicemgr_print(char* text);
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "rs485.h"
|
||||
#include "ftdi485.h"
|
||||
|
||||
/*
|
||||
* Open RS485 Interface (FT232RL)
|
||||
@@ -43,27 +43,6 @@ int rs485_init(char *device, int baud) {
|
||||
close(rs485_fd);
|
||||
return -1;
|
||||
}
|
||||
rs485_trdir(rs485_fd, 1);
|
||||
|
||||
return rs485_fd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set RS485 Direction (FT232RL - RTS PIN)
|
||||
*/
|
||||
int rs485_trdir(int rs485_fd, int level) {
|
||||
int status;
|
||||
|
||||
if (ioctl(rs485_fd, TIOCMGET, &status) == -1) {
|
||||
perror("setRTS(): TIOCMGET");
|
||||
return 0;
|
||||
}
|
||||
if (level)
|
||||
status |= TIOCM_DTR;
|
||||
else
|
||||
status &= ~TIOCM_DTR;
|
||||
if (ioctl(rs485_fd, TIOCMSET, &status) == -1) {
|
||||
perror("setRTS(): TIOCMSET");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -11,5 +11,4 @@
|
||||
#define RS485TX 0
|
||||
#define RS485RX 1
|
||||
|
||||
int rs485_init(char *device, int baud);
|
||||
int rs485_trdir(int rs485_fd, int level);
|
||||
int rs485_init(char *device, int baud);
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <termios.h> // Contains POSIX terminal control definitions
|
||||
#include <unistd.h> // write(), read(), close()
|
||||
|
||||
#include "rs485.h"
|
||||
#include "ftdi485.h"
|
||||
#include "sfbus.h"
|
||||
#include "devicemgr.h"
|
||||
|
||||
@@ -67,14 +67,18 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
// test
|
||||
devicemgr_init();
|
||||
devicemgr_register(fd,0,0,0);
|
||||
devicemgr_register(fd,1,1,0);
|
||||
devicemgr_register(fd,1,0,0);
|
||||
devicemgr_register(fd,2,1,0);
|
||||
devicemgr_register(fd,3,2,0);
|
||||
devicemgr_register(fd,4,3,0);
|
||||
devicemgr_printDetailsAll();
|
||||
//exit(1);
|
||||
|
||||
if (strcmp(command, "ping") == 0) {
|
||||
sfbus_ping(fd, addr_int);
|
||||
exit(0);
|
||||
} else if (strcmp(command, "printf") == 0) {
|
||||
printText(data,0,0);
|
||||
} else if (strcmp(command, "r_eeprom") == 0) {
|
||||
char *buffer = malloc(64);
|
||||
sfbus_read_eeprom(fd, addr_int, buffer);
|
||||
@@ -104,6 +108,24 @@ int main(int argc, char *argv[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
} else if (strcmp(command, "w_cal") == 0) {
|
||||
int n_addr = strtol(data, NULL, 10);
|
||||
// read current eeprom status
|
||||
char *buffer_w = malloc(64);
|
||||
char *buffer_r = malloc(64);
|
||||
if (sfbus_read_eeprom(fd, addr_int, buffer_w) < 0) {
|
||||
fprintf(stderr, "Error reading eeprom\n");
|
||||
exit(1);
|
||||
}
|
||||
// modify current addr
|
||||
u_int16_t n_addr_16 = n_addr;
|
||||
memcpy(buffer_w+2, &n_addr_16, 2);
|
||||
if (sfbus_write_eeprom(fd, addr_int, buffer_w, buffer_r) < 0) {
|
||||
fprintf(stderr, "Error writing eeprom\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
} else if (strcmp(command, "status") == 0) {
|
||||
double voltage = 0;
|
||||
|
||||
@@ -107,14 +107,14 @@ void sfbus_send_frame(int fd, u_int16_t address, u_int8_t length,
|
||||
}
|
||||
*frame = '$'; // startbyte
|
||||
|
||||
rs485_trdir(fd, 0);
|
||||
//rs485_trdir(fd, 0);
|
||||
|
||||
int result = write(fd, frame_ptr, frame_size_complete);
|
||||
print_bufferHexTx(frame_ptr + 5, frame_size_complete - 6, address);
|
||||
free(frame_ptr);
|
||||
// tcdrain(fd);
|
||||
usleep(470 * (frame_size_complete + 1));
|
||||
rs485_trdir(fd, 1);
|
||||
//usleep(470 * (frame_size_complete + 1));
|
||||
//rs485_trdir(fd, 1);
|
||||
}
|
||||
|
||||
int sfbus_ping(int fd, u_int16_t address) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "rs485.h"
|
||||
#include "ftdi485.h"
|
||||
|
||||
ssize_t sfbus_recv_frame(int fd, u_int16_t address, char *buffer);
|
||||
ssize_t sfbus_recv_frame_wait(int fd, u_int16_t address, char *buffer);
|
||||
|
||||
Reference in New Issue
Block a user