⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serfile.c

📁 linux下的一个串口调试程序的源代码
💻 C
字号:
/* * Program:     serfile * Funtcion:    transmit a file via a serial port * Usage:       serfile filename * Date:        2002-02-19 * Version:		0.0.5 * Author:      Paul Dean */#include <stdio.h>              //* printf */#include <fcntl.h>              //* open */#include <string.h>             //* bzero */#include <stdlib.h>             //* exit */#include <sys/times.h>          //* times */#include <unistd.h>             //* read, write, close */#include <sys/stat.h>           //* lstat */#include "types.h"#include "serial.h"#include "args.h"static PACKAGE_INFO pkgInfo = {    "serfile",                  //* program */    "serutils",                 //* package */    "0.0.4",                    //* version */    "Paul Dean",                //* author */    0                           //* reserved */},             *pPkgInfo = &pkgInfo;static PORT_INFO portInfo = {    0,                          //* debug */    0,                          //* echo */    115200,                     //* baudrate */    0,                          //* port */    8,                          //* databit */    1,                          //* flow control: hardware */    'N',                        //* no parity check */    "1",                        //* stopbit */    NULL,                       //* device */    0                           //* reserved */},             *pPortInfo = &portInfo;static ARGUMENTS args = { &pkgInfo, &portInfo };P_ARGUMENTS     pArgs = &args;static INT32    SendAllFiles (char **pathname);int main (int argc, char *argv[]){    INT32           retval = 0;    parse_arguments (argc, argv, 1, pPkgInfo, pPortInfo);    //* open comport */    retval = OpenComPort (pPortInfo);    if (retval) {        fprintf (stderr, "Make sure /dev/ttyS%d "                 "not in use or you have enough privilege.\n\n",                 pPortInfo->port);        exit (retval);    }    SendAllFiles (&argv[optind]);    CloseComPort ();    exit (0);}static INT32 SendAllFiles (char **pathname){    long            oldtick, newtick;    INT32           systick;    float           kbps = 0, time = 0;    long            byteSend = 0;    struct stat     stat;    int             num = 0;    oldtick = times (NULL);     //* get system tick number */    //* send files in char **pathname via serial port */    while (*pathname != NULL) {        printf ("\nsenging file %s, echo mode: %s\n",                *pathname, pPortInfo->echo == 0 ? "off" : "on");        if (-1 == SendFile (*pathname, pPortInfo->echo)) {            fflush (stdout);            fflush (stderr);            fprintf (stderr, "\ncannot send file %s\n", *pathname);            return (-1);        }        lstat (*pathname, &stat);        num++;        byteSend += stat.st_size;        pathname++;    }    newtick = times (NULL);    systick = sysconf (_SC_CLK_TCK);    //* get system clock tick per second */    time = (float) (newtick - oldtick) / systick;    kbps = (float) byteSend / time / 1000;    printf ("\n%d files, %ld bytes sent in %.2fs, %.2fKbps\n",            num, byteSend, time, kbps);    return (0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -