qvyuanxin
2017-07-04 65a094bd57829118503802220b7125053c643c41


git-svn-id: http://192.168.1.226/svn/proxy@685 454eff88-639b-444f-9e54-f578c98de674
2个文件已添加
2个文件已修改
474 ■■■■■ 已修改文件
VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/serial.c 240 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/serial.h 139 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/java/cn/com/basic/face/util/RtspFaceNative.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp
@@ -17,7 +17,7 @@
#include <stdlib.h>
#include "DebugNetwork.h"
#include "serial.h"
//#include <mediastreamer2/include/mediastreamer2/msjava.h>
std::stringstream logss;
@@ -691,3 +691,93 @@
}
}
void Delay(unsigned int nDelay)
{
    unsigned int i,j,k;
    for ( i=0;i<nDelay;i++ )
        for ( j=0;j<6144;j++ )
            k++;
}
void callNum(int fd,char phone)
{
    switch ( phone)
    {
        case '1':
            serialWriteString(fd,"DA");//1
            break;
        case '2':
            serialWriteString(fd,"DB");//2
            break;
        case '3':
            serialWriteString(fd,"DC");//3
            break;
        case '4':
            serialWriteString(fd,"DD");//4
            break;
        case '5':
            serialWriteString(fd,"DE");//5
            break;
        case '6':
            serialWriteString(fd,"DF");//6
            break;
        case '7':
            serialWriteString(fd,"DG");//7
            break;
        case '8':
            serialWriteString(fd,"DH");//8
            break;
        case '9':
            serialWriteString(fd,"DI");//9
            break;
        case '0':
            serialWriteString(fd,"DJ");//0
            break;
    }
}
void call(const char * phone)
{
    int  fd = serialOpen("/dev/ttyS1",2400);
    serialWriteString(fd,"AA");
    Delay(10000);
   while (*phone)
   {
       Delay(10000);
       callNum(fd,*(phone++));
   }
}
char* jstringTostring(JNIEnv* env, jstring jstr)
{
char* rtn = NULL;
jclass clsstring = env->FindClass("java/lang/String");
jstring strencode = env->NewStringUTF("utf-8");
jmethodID mid = env->GetMethodID(clsstring, "getBytes", "(Ljava/lang/String;)[B");
jbyteArray barr= (jbyteArray)env->CallObjectMethod(jstr, mid, strencode);
jsize alen = env->GetArrayLength(barr);
jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE);
if (alen > 0)
{
rtn = (char*)malloc(alen + 1);
memcpy(rtn, ba, alen);
rtn[alen] = 0;
}
env->ReleaseByteArrayElements(barr, ba, 0);
return rtn;
}
void Java_cn_com_basic_face_util_RtspFaceNative_telCall(JNIEnv* env, jclass clazz,jstring phone)
 {
     call(jstringTostring(phone));
 }
 void Java_cn_com_basic_face_util_RtspFaceNative_Hang(JNIEnv* env, jclass clazz)
 {
       int  fd = serialOpen("/dev/ttyS1",2400);
           serialWriteString(fd,"BA");
 }
VisitFace/RtspNativeCodec/app/src/main/cpp/serial.c
New file
@@ -0,0 +1,240 @@
/*
 * Copyright 2012 - 2014 Thomas Buck <xythobuz@xythobuz.de>
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <dirent.h>
#include <errno.h>
#include <time.h>
#include <poll.h>
#include "serial.h"
#ifndef XON
#define XON 0x11
#endif
#ifndef XOFF
#define XOFF 0x13
#endif
#ifndef TIMEOUT
#define TIMEOUT 2
#endif
int serialOpen(const char *port, unsigned int baud) {
    struct termios options;
    int fd = open(port, O_RDWR | O_NOCTTY | O_NDELAY);
    if (fd == -1) {
        fprintf(stderr, "Couldn't open port \"%s\": %s\n", port, strerror(errno));
        return -1;
    }
    tcgetattr(fd, &options);
    options.c_lflag = 0;
    options.c_oflag = 0;
    options.c_iflag = 0;
    // Set Baudrate
    switch (baud) {
        case 9600:
            cfsetispeed(&options, B9600);
            cfsetospeed(&options, B9600);
            break;
        case 19200:
            cfsetispeed(&options, B19200);
            cfsetospeed(&options, B19200);
            break;
        case 38400:
            cfsetispeed(&options, B38400);
            cfsetospeed(&options, B38400);
            break;
        //case 76800:
        //    cfsetispeed(&options, B76800);
        //    cfsetospeed(&options, B76800);
        //    break;
        case 115200:
            cfsetispeed(&options, B115200);
            cfsetospeed(&options, B115200);
            break;
        default:
            fprintf(stderr, "Warning: Baudrate not supported!\n");
            serialClose(fd);
            return -1;
    }
    // Input Modes
    options.c_iflag |= IGNCR; // Ignore CR
#ifdef XONXOFF
    options.c_iflag |= IXON; // XON-XOFF Flow Control
#endif
    // Output Modes
    options.c_oflag |= OPOST; // Post-process output
    // Control Modes
    options.c_cflag |= CS8; // 8 data bits
    options.c_cflag |= CREAD; // Enable Receiver
    options.c_cflag |= CLOCAL; // Ignore modem status lines
    // Local Modes
    options.c_lflag |= IEXTEN; // Extended input character processing
    // Special characters
    options.c_cc[VMIN] = 0; // Always return...
    options.c_cc[VTIME] = 0; // ..immediately from read()
#ifdef XONXOFF
    options.c_cc[VSTOP] = XOFF;
    options.c_cc[VSTART] = XON;
#endif
    tcsetattr(fd, TCSANOW, &options);
    tcflush(fd, TCIOFLUSH);
    return fd;
}
void serialClose(int fd) {
    tcflush(fd, TCIOFLUSH);
    close(fd);
}
int serialHasChar(int fd) {
    struct pollfd fds;
    fds.fd = fd;
    fds.events = (POLLIN | POLLPRI); // Data may be read
    if (poll(&fds, 1, 0) > 0) {
        return 1;
    } else {
        return 0;
    }
}
void serialWaitUntilSent(int fd) {
    while (tcdrain(fd) == -1) {
        fprintf(stderr, "Could not drain data: %s\n", strerror(errno));
    }
}
unsigned int serialWriteRaw(int fd, const char *d, int len) {
    unsigned int processed = 0;
    time_t start = time(NULL);
    while ((processed < len) && (difftime(time(NULL), start) < TIMEOUT)) {
        int t = write(fd, (d + processed), (len - processed));
        if (t == -1) {
            fprintf(stderr, "Error while writing: %s\n", strerror(errno));
            return processed;
        } else {
            processed += t;
        }
    }
    return processed;
}
unsigned int serialReadRaw(int fd, char *d, int len) {
    unsigned int processed = 0;
    time_t start = time(NULL);
    while ((processed < len) && (difftime(time(NULL), start) < TIMEOUT)) {
        int t = read(fd, (d + processed), (len - processed));
        if (t == -1) {
            fprintf(stderr, "Error while reading: %s\n", strerror(errno));
            return processed;
        } else {
            processed += t;
        }
    }
    return processed;
}
void serialWriteChar(int fd, char c) {
    while (serialWriteRaw(fd, &c, 1) != 1);
}
void serialReadChar(int fd, char *c) {
    while (serialReadRaw(fd, c, 1) != 1);
#ifdef XONXOFF
    if (*c == XON) {
        if (tcflow(fd, TCOON) == -1) {
            fprintf(stderr, "Could not restart flow: %s\n", strerror(errno));
        }
        serialReadChar(fd, c);
    } else if (*c == XOFF) {
        if (tcflow(fd, TCOOFF) == -1) {
            fprintf(stderr, "Could not stop flow: %s\n", strerror(errno));
        }
        serialReadChar(fd, c);
    }
#endif
}
void serialWriteString(int fd, const char *s) {
    while (*s)
        serialWriteChar(fd, *(s++));
}
char** getSerialPorts(void) {
    DIR *dir;
    struct dirent *ent;
    int size = 0;
    dir = opendir("/dev/");
    while ((ent = readdir(dir)) != NULL) {
#ifdef SEARCH
        if (strstr(ent->d_name, SEARCH) != NULL)
#endif
        size++;
    }
    closedir(dir);
    char **files = (char **)malloc((size + 1) * sizeof(char *));
    int i = 0;
    dir = opendir("/dev/");
    while (((ent = readdir(dir)) != NULL) && (i < size)) {
#ifdef SEARCH
        if (strstr(ent->d_name, SEARCH) != NULL) {
#endif
            int tmp = strlen(ent->d_name) + 6;
            files[i] = (char *)malloc(tmp * sizeof(char));
            strcpy(files[i], "/dev/");
            strcpy(files[i] + 5, ent->d_name);
            files[i][tmp - 1] = '\0';
#ifdef TRY_TO_OPEN_PORTS
            int fdtmp = serialOpen(files[i], 9600);
            if (fdtmp != -1) {
                serialClose(fdtmp);
#endif
                i++;
#ifdef TRY_TO_OPEN_PORTS
            } else {
                free(files[i]);
            }
#endif
#ifdef SEARCH
        }
#endif
    }
    closedir(dir);
    files[i] = NULL;
    return files;
}
VisitFace/RtspNativeCodec/app/src/main/cpp/serial.h
New file
@@ -0,0 +1,139 @@
/*
 * Copyright 2012 - 2014 Thomas Buck <xythobuz@xythobuz.de>
 */
#ifndef _SERIAL_H_
#define _SERIAL_H_
/*
 * Configuration
 */
/*!
 * \brief Enable XON/XOFF flow control.
 *
 * If you uncomment this definition, the serial port code will
 * stop sending when a XOFF was received, and start again upon
 * receiving XON. However, you need to use the blocking
 * read/write functions!
 */
//#define XONXOFF
#define XON 0x11  //!< XON flow control character
#define XOFF 0x13 //!< XOFF flow control character
/*!
 * \brief Search term to filter the list of available ports.
 *
 * If you define SEARCH, instead of simply returning a list of
 * files in /dev/, getSerialPorts() will only return items that
 * contain the string defined to SEARCH.
 */
#define SEARCH "tty"
/*!
 * \brief Only list real serial ports.
 *
 * If you uncomment this definition, getSerialPorts() will try to
 * open every port, only returning the name if it is a real serial
 * port. This could cause a big delay, if eg. your system tries to
 * open non-existing bluetooth devices, waiting for their timeout.
 * Also, if your console tty is probed, it might change it's settings.
 */
//#define TRY_TO_OPEN_PORTS
/*!
 * \brief The timeout in seconds for raw reading/writing.
 *
 * If this amount of time passes without being able to write/read
 * a character, the raw I/O functions will return 0.
 */
#define TIMEOUT 2
/*
 * Setup
 */
/*!
 * \brief open a serial port
 * \param port name of port
 * \param baud baudrate
 * \returns file handle or -1 on error
 */
int serialOpen(const char *port, unsigned int baud);
/*!
 * \brief close an open serial port
 * \param fd file handle of port to close
 */
void serialClose(int fd);
/*!
 * \brief query available serial ports
 * \returns string array with serial port names.
 * Last element is NULL. Don't forget to free()
 * after using it!
 */
char **getSerialPorts(void);
/*
 * Raw, non-blocking I/O
 */
/*!
 * \brief read from an open serial port
 * \param fd file handle of port to read from
 * \param data buffer big enough to fit all read data
 * \param length maximum number of bytes to read
 * \returns number of bytes really read
 */
unsigned int serialReadRaw(int fd, char *data, int length);
/*!
 * \brief write to an open serial port
 * \param fd file handle of port to write to
 * \param data buffer containing data to write
 * \param length number of bytes to write
 * \returns number of bytes really written
 */
unsigned int serialWriteRaw(int fd, const char *data, int length);
/*!
 * \brief wait until data is sent
 * \param fd file handle of port to wait for
 */
void serialWaitUntilSent(int fd);
/*
 * Blocking I/O
 */
/*!
 * \brief check if a character has arrived and can be read
 * \param fd file handle of port to check
 * \returns 1 if a character is available, 0 if not
 */
int serialHasChar(int fd);
/*!
 * \brief read a single character
 * \param fd file handle of port to read from
 * \param c where read character will be stored
 */
void serialReadChar(int fd, char *c);
/*!
 * \brief write a single character
 * \param fd file handle to write to
 * \param c character to write
 */
void serialWriteChar(int fd, char c);
/*!
 * \brief write a string
 * \param fd file handle to write to
 * \param s C string to be written
 */
void serialWriteString(int fd, const char *s);
#endif
VisitFace/RtspNativeCodec/app/src/main/java/cn/com/basic/face/util/RtspFaceNative.java
@@ -61,7 +61,8 @@
    public static native void startCapturePlayer(String uri);
    public static native void stopCapturePlayer();
    public static native ArrayList<NativeImg> getCaptureImages();
    public  static native  call(String phone);
    public  static native hang();
    public static int COMPANY_ID = 1001;
    public static void faceCallBack(int cameraIdx, int count)