From 456f97ea9dcbf319b55238ff57eb30cd63e76702 Mon Sep 17 00:00:00 2001 From: "Igor Zalatov (from Citadel PC)" Date: Mon, 25 Sep 2023 21:20:19 +0300 Subject: [PATCH] Update some packages --- packages/demo-openipc/demo-openipc.mk | 4 +- packages/gps-openipc/Config.in | 7 + packages/gps-openipc/gps-openipc.mk | 22 ++ packages/gps-openipc/src/gps-openipc.c | 260 ++++++++++++++++++ .../configs/t31_lite_vixand2_defconfig | 2 +- .../rebuild_gk7205v200_ultimate_baresip | 13 +- 6 files changed, 304 insertions(+), 4 deletions(-) create mode 100644 packages/gps-openipc/Config.in create mode 100644 packages/gps-openipc/gps-openipc.mk create mode 100644 packages/gps-openipc/src/gps-openipc.c diff --git a/packages/demo-openipc/demo-openipc.mk b/packages/demo-openipc/demo-openipc.mk index 111c0ea..9c1ce84 100644 --- a/packages/demo-openipc/demo-openipc.mk +++ b/packages/demo-openipc/demo-openipc.mk @@ -8,7 +8,7 @@ DEMO_OPENIPC_LICENSE = MIT DEMO_OPENIPC_LICENSE_FILES = LICENSE define DEMO_OPENIPC_EXTRACT_CMDS - cp ../general/package/demo-openipc/src/* $(@D)/ + cp -avr $(DEMO_OPENIPC_PKGDIR)/src/* $(@D)/ endef define DEMO_OPENIPC_BUILD_CMDS @@ -17,7 +17,7 @@ endef define DEMO_OPENIPC_INSTALL_TARGET_CMDS $(INSTALL) -m 755 -d $(TARGET_DIR)/etc/init.d - cp ../general/package/demo-openipc/files/S97demo $(TARGET_DIR)/etc/init.d + cp $(DEMO_OPENIPC_PKGDIR)/files/S97demo $(TARGET_DIR)/etc/init.d install -m 0755 -D $(@D)/demo-openipc $(TARGET_DIR)/usr/sbin/demo-openipc endef diff --git a/packages/gps-openipc/Config.in b/packages/gps-openipc/Config.in new file mode 100644 index 0000000..0ad29cf --- /dev/null +++ b/packages/gps-openipc/Config.in @@ -0,0 +1,7 @@ +config BR2_PACKAGE_GPS_OPENIPC + bool "gps-openipc" + default n + help + Minimalistic package for getting coordinates and time from GPS receiver. + + https://openipc.org diff --git a/packages/gps-openipc/gps-openipc.mk b/packages/gps-openipc/gps-openipc.mk new file mode 100644 index 0000000..ac72922 --- /dev/null +++ b/packages/gps-openipc/gps-openipc.mk @@ -0,0 +1,22 @@ +################################################################################ +# +# gps-openipc | updated 2023.09.25 +# +################################################################################ + +GPS_OPENIPC_LICENSE = MIT +GPS_OPENIPC_LICENSE_FILES = LICENSE + +define GPS_OPENIPC_EXTRACT_CMDS + cp -avr $(GPS_OPENIPC_PKGDIR)/src/* $(@D)/ +endef + +define GPS_OPENIPC_BUILD_CMDS + (cd $(@D); $(TARGET_CC) -s gps-openipc.c -o gps-openipc) +endef + +define GPS_OPENIPC_INSTALL_TARGET_CMDS + install -m 0755 -D $(@D)/gps-openipc $(TARGET_DIR)/usr/sbin/gps-openipc +endef + +$(eval $(generic-package)) diff --git a/packages/gps-openipc/src/gps-openipc.c b/packages/gps-openipc/src/gps-openipc.c new file mode 100644 index 0000000..9f89525 --- /dev/null +++ b/packages/gps-openipc/src/gps-openipc.c @@ -0,0 +1,260 @@ +//----------------------------------------------------------------------------------------- +// +// Special thanks to Craig Peacock from the OpenIPC.org project. +// +//----------------------------------------------------------------------------------------- + +#include +#include +#include +#include +#include +#include +#include +#include + +int hex2int(char *c); +int checksum_valid(char *string); +int parse_comma_delimited_str(char *string, char **fields, int max_fields); +int debug_print_fields(int numfields, char **fields); +int OpenGPSPort(const char *devname); +int SetTime(char *date, char *time); + +int main(int argc, char **argv) +{ + int fd; + char buffer[255]; + int nbytes; + int i; + char *field[20]; + + if ((fd = OpenGPSPort("/dev/ttyUSB3")) < 0) + { + printf("Cannot open GPS port\r\n."); + return 0; + } + + do { + if ((nbytes = read(fd, &buffer, sizeof(buffer))) < 0) { + perror("Read"); + return 1; + } else { + if (nbytes == 0) { + printf("No communication from GPS module\r\n"); + sleep(1); + } else { + buffer[nbytes - 1] = '\0'; + //printf("[%s]\r\n",buffer); + if (checksum_valid(buffer)) { + if ((strncmp(buffer, "$GP", 3) == 0) | + (strncmp(buffer, "$GN", 3) == 0)) { + + if (strncmp(&buffer[3], "GGA", 3) == 0) { + i = parse_comma_delimited_str(buffer, field, 20); + //debug_print_fields(i,field); + printf("UTC Time :%s\r\n",field[1]); + printf("Latitude :%s\r\n",field[2]); + printf("Longitude :%s\r\n",field[4]); + printf("Altitude :%s\r\n",field[9]); + printf("Satellites:%s\r\n",field[7]); + } + if (strncmp(&buffer[3], "RMC", 3) == 0) { + i = parse_comma_delimited_str(buffer, field, 20); + //debug_print_fields(i,field); + printf("Speed :%s\r\n",field[7]); + //printf("UTC Time :%s\r\n",field[1]); + //printf("Date :%s\r\n",field[9]); + + SetTime(field[9],field[1]); + } + } + } + } + } + } while(1); + + if (close(fd) < 0) { + perror("Close"); + return 1; + } + + return (0); +} + +int debug_print_fields(int numfields, char **fields) +{ + printf("Parsed %d fields\r\n",numfields); + + for (int i = 0; i <= numfields; i++) { + printf("Field %02d: [%s]\r\n",i,fields[i]); + } +} + +int hexchar2int(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + return -1; +} + +int hex2int(char *c) +{ + int value; + + value = hexchar2int(c[0]); + value = value << 4; + value += hexchar2int(c[1]); + + return value; +} + +int checksum_valid(char *string) +{ + char *checksum_str; + int checksum; + unsigned char calculated_checksum = 0; + + // Checksum is postcede by * + checksum_str = strchr(string, '*'); + if (checksum_str != NULL){ + // Remove checksum from string + *checksum_str = '\0'; + // Calculate checksum, starting after $ (i = 1) + for (int i = 1; i < strlen(string); i++) { + calculated_checksum = calculated_checksum ^ string[i]; + } + checksum = hex2int((char *)checksum_str+1); + //printf("Checksum Str [%s], Checksum %02X, Calculated Checksum %02X\r\n",(char *)checksum_str+1, checksum, calculated_checksum); + if (checksum == calculated_checksum) { + //printf("Checksum OK"); + return 1; + } + } else { + //printf("Error: Checksum missing or NULL NMEA message\r\n"); + return 0; + } + return 0; +} + +int parse_comma_delimited_str(char *string, char **fields, int max_fields) +{ + int i = 0; + fields[i++] = string; + + while ((i < max_fields) && NULL != (string = strchr(string, ','))) { + *string = '\0'; + fields[i++] = ++string; + } + + return --i; +} + +int SetTime(char *date, char *time) +{ + struct timespec ts; + struct tm gpstime; + time_t secs; + char tempbuf[2]; + int ret; + + printf("GPS UTC_Date %s, UTC_Time %s\r\n",date, time); + // GPS date has format of ddmmyy + // GPS time has format of hhmmss.ss + + if ((strlen(date) != 6) | (strlen(time) != 9)) { + printf("No date or time fix. Exiting\r\n"); + return 1; + } + + // Parse day: + strncpy(tempbuf, (char *)date, 2); + tempbuf[2] = '\0'; + gpstime.tm_mday = atoi(tempbuf); + + // Parse month: + strncpy(tempbuf, (char *)date+2, 2); + tempbuf[2] = '\0'; + gpstime.tm_mon = atoi(tempbuf) - 1; + + // Parse year: + strncpy(tempbuf, (char *)date+4, 2); + tempbuf[2] = '\0'; + gpstime.tm_year = atoi(tempbuf) + 100; + + // Parse hour: + strncpy(tempbuf, (char *)time, 2); + tempbuf[2] = '\0'; + gpstime.tm_hour = atoi(tempbuf); + + // Parse minutes: + strncpy(tempbuf, (char *)time+2, 2); + tempbuf[2] = '\0'; + gpstime.tm_min = atoi(tempbuf); + + // Parse seconds: + strncpy(tempbuf, (char *)time+4, 2); + tempbuf[2] = '\0'; + gpstime.tm_sec = atoi(tempbuf); + + printf("Converted UTC_Date %02d%02d%02d, UTC_Time %02d%02d%02d.00\r\n",gpstime.tm_mday,(gpstime.tm_mon)+1,(gpstime.tm_year)%100, gpstime.tm_hour, gpstime.tm_min, gpstime.tm_sec); + + ts.tv_sec = mktime(&gpstime); + // Apply GMT offset to correct for timezone + ts.tv_sec += gpstime.tm_gmtoff; + + printf("Number of seconds since Epoch %ld\r\n",ts.tv_sec); + + ts.tv_nsec = 0; + ret = clock_settime(CLOCK_REALTIME, &ts); + if (ret) + perror("Set Clock"); + + //clock_gettime(CLOCK_REALTIME, &ts); + //printf("Number of seconds since Epoch %ld\r\n",ts.tv_sec); + //gpstime = gmtime(&ts.tv_sec); + //printf("System UTC_Date %02d%02d%02d, ",gpstime->tm_mday,(gpstime->tm_mon)+1,(gpstime->tm_year)%100); + //printf("UTC_Time %02d%02d%02d.00\r\n", gpstime->tm_hour, gpstime->tm_min, gpstime->tm_sec); + printf("\r\n"); +} + +int OpenGPSPort(const char *devname) +{ + int fd; + struct termios options; + + if ((fd = open(devname, O_RDWR | O_NOCTTY | O_NDELAY)) < 0) { + perror("Open"); + return 1; + } + + // Set to blocking + fcntl(fd, F_SETFL, 0); + + // Get port attributes + tcgetattr(fd, &options); + + // Set input and output baud rates + cfsetispeed(&options, B9600); + cfsetospeed(&options, B9600); + + // Set input modes + options.c_iflag |= ICRNL; + + // Set 8 bits, no parity, 1 stop bit + options.c_cflag &= ~PARENB; + options.c_cflag &= ~CSTOPB; + options.c_cflag &= ~CSIZE; + options.c_cflag |= CS8; + + options.c_lflag &= ~ECHO; + options.c_lflag |= ICANON; + + // Set port attributes + tcsetattr(fd, TCSAFLUSH, &options); + + return(fd); +} diff --git a/projects/t31_lite_vixand2/br-ext-chip-ingenic/configs/t31_lite_vixand2_defconfig b/projects/t31_lite_vixand2/br-ext-chip-ingenic/configs/t31_lite_vixand2_defconfig index 7b9fac1..a4246d8 100644 --- a/projects/t31_lite_vixand2/br-ext-chip-ingenic/configs/t31_lite_vixand2_defconfig +++ b/projects/t31_lite_vixand2/br-ext-chip-ingenic/configs/t31_lite_vixand2_defconfig @@ -108,7 +108,7 @@ BR2_PACKAGE_WIREGUARD_LINUX_COMPAT=y BR2_PACKAGE_WIREGUARD_TOOLS=y # EXPERIMENTAL -# BR2_PACKAGE_ONVIF_SIMPLE_SERVER is not set +BR2_PACKAGE_ONVIF_SIMPLE_SERVER=y # BR2_PACKAGE_FFMPEG_OPENIPC=y diff --git a/workplace/scripts/rebuild_gk7205v200_ultimate_baresip b/workplace/scripts/rebuild_gk7205v200_ultimate_baresip index a404091..31555bd 100755 --- a/workplace/scripts/rebuild_gk7205v200_ultimate_baresip +++ b/workplace/scripts/rebuild_gk7205v200_ultimate_baresip @@ -44,5 +44,16 @@ baresip() { } +gps() { + # + rm -rf \ + output/per-package/gps-openipc \ + output/build/gps-openipc* + # + BOARD=gk7205v200_ultimate_baresip make br-gps-openipc-{dirclean,rebuild} +} -baresip + +#baresip + +gps \ No newline at end of file