1. COM1
#define COM1LINUX "/dev/ttyS0"
#define COM2LINUX "/dev/ttyS1"
#define COM3LINUX "/dev/ttyS2"
#define COM4LINUX "/dev/ttyS3"
#define COM5LINUX "/dev/ttyS4"
#define COM6LINUX "/dev/ttyS5"
#define COM1WR703N "/dev/ttyATH0"
#ifdef WR703N
COMReceive(COM1WR703N, "$1234567890");
#else
COMReceive(COM1LINUX, "$1234567890");
#endif
启动信息:
Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
ar933x-uart: ttyATH0 at MMIO 0x18020000 (irq = 11) is a AR933X UART
console [ttyATH0] enabled, bootconsole disabled
路由器启动时COM波特率为115200
rc = tcgetattr (fd[portnum], &t);//虚拟机成功返回0, 但在路由器上返回-1. 解决:WR703N=/dev/ttyATH0
echo "test" > /dev/ttyATH0//路由器上执行此命令, 串口监视端可看到 test
TP_IN为RX,TP_OUT为TX,Micro USB口的数据接口为空,TTL与Micro USB共用GND接口。从而实现免拆机无损TTL改造。
引出后黑色为GND,绿色为RX,白色为TX。完成焊接后请务必检查个个电缆链接且独立。
排列: 黑白绿(Err), 黑绿白(OK), 靠近RJ45接口为黑线.
2. 屏蔽串口的系统显示PC端用串口调试时, 能正常接收到数据, 但发送数据时出现 BusyBox 的提示, 而且导致路由器端数据接收不稳定. BusyBox v1.18.5 (2011-09-18 11:2 _______ ________ __
| |.---@OpenWrt:/#
Please press Enter to activate this console.
解决: vi /etc/inittab::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
ttyS0::askfirst:/bin/ash --login
#ttyATH0::askfirst:/bin/ash --login #注释此行
3. 增加了UDP调试
#define DEBUGP UDPprintf
DEBUGP("UARTHandler: %d, Len = %d, %s\n", usTimes, usLen, pcString);
4. 增加了TCP调试
#define DEBUGP TCPprintfDEBUGP("UARTHandler: %d, Len = %d, %s\n", usTimes, usLen, pcString);
5. TCP转COM, 同时UDP做Debug的数据显示
6. 获取本地时间
#include
struct tm *GetLocalTime(void)
{
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
//DEBUGP("Time = %d-%d-%d %d:%d:%d\n", timenow->tm_year+1900, timenow->tm_mon+1, timenow->tm_mday,
//timenow->tm_hour, timenow->tm_min, timenow->tm_sec);
//DEBUGP("recent time is : %s \n", asctime(timenow));
}
12-5-22: 修改 uhttpd, 增加自定义的SSI
opkg install /tmp/uhttpd_31_ar71xx.ipk
/etc/init.d/uhttpd stop
/etc/init.d/uhttpd start
修改 xuudp.c , 接收到的HTTP请求
看看以前做的个网页控制的小东东, 准备移植到路由器上
12-5-29: C实现的发送文本邮件, 发送附件尚未实现.
int main(int argc, char* argv[])
{
char to_id[100], subject[100];
char pcMailText[1000];
static int times=1;
sprintf(to_id, "%s", "onewire@126.com");
sprintf(subject, "%s %d", "Linux test mail", times++);
sprintf(pcMailText, "%s", "秋水在路由器上实验, Linux下C编程:眼神带着淡淡的倦意,轻轻的忧惺,宛若远山含笑迷蒙,但又如闪电惊雷般动人心魄");
SendMail(to_id, subject, pcMailText);
system("uname -r");
}
--- 测试OK的 base64加密,
static const char g_base64_chars [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
void _encode_block ( u_char in[3], u_char out[4] )
{
out[0] = g_base64_chars [ ( in[0] >> 2 ) ];
out[1] = g_base64_chars [ ( ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ) ];
out[2] = g_base64_chars [ ( ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ) ];
out[3] = g_base64_chars [ ( in[2] & 0x3f ) ];
}
void encode_base64(u_char* output, u_char* input)
{
int inputlen = strlen(input);
while ( inputlen >= 3 ) {
_encode_block ( input, output );
inputlen -= 3;
input += 3;
output += 4;
}
if ( inputlen > 0 ) {
u_char temp[3];
memset ( temp, 0, sizeof(temp) );
memcpy ( temp, input, inputlen );
_encode_block ( temp, output );
output[3] = '=';
if ( inputlen == 1 )
output[2] = '=';
output += 4;
}
output[0] = 0;
}
调用例程:
encode_base64(wkstr, FROMID);
strcat(wkstr, "\r\n");
send_socket(wkstr);//用户名的base64编码
//WR703N直接控制LED, 让这微弱的光芒指引我们收复***的方向吧. 2012-9-18
opkg update
opkg install gpioctl
opkg list-installed | grep gpio
gpioctl - 1.0-1
kmod-gpio-button-hotplug - 3.2.12-1
kmod-leds-gpio - 3.2.12-1
#LED on
echo "1" > /sys/devices/platform/leds-gpio/leds/tp-link:blue:system/brightness
#LED off
echo "0" > /sys/devices/platform/leds-gpio/leds/tp-link:blue:system/brightness
#LED blink
opkg update
opkg install gpioctl
opkg list-installed | grep gpio
gpioctl - 1.0-1
kmod-gpio-button-hotplug - 3.2.12-1
kmod-leds-gpio - 3.2.12-1
#LED on
echo "1" > /sys/devices/platform/leds-gpio/leds/tp-link:blue:system/brightness
#LED off
echo "0" > /sys/devices/platform/leds-gpio/leds/tp-link:blue:system/brightness
#LED blinking, 单位为ms
cd /sys/devices/platform/leds-gpio/leds/tp-link:blue:system/
echo timer > trigger
echo 1000 > delay_on
echo 1000 > delay_off
/*以下是刷机时的全程TTL信息*/
U-Boot 1.1.4 (Sep 26 2011 - 11:13:45)
AP121-2MB (ar9330) U-boot
DRAM: 32 MB
led turning on for 1s...
id read 0x100000ff
flash size 4194304, sector count = 64
Flash: 4 MB
Using default environment
In: serial
Out: serial
Err: serial
Net: ag7240_enet_initialize...
No valid address in Flash. Using fixed address
No valid address in Flash. Using fixed address
: cfg1 0x5 cfg2 0x7114
eth0: xx:xx:xx:xx:xx:xx /*此处为网卡MAC地址,已隐去*/
ag7240_phy_setup
eth0 up
: cfg1 0xf cfg2 0x7214
eth1: xx:xx:xx:xx:xx:xx
athrs26_reg_init_lan
ATHRS26: resetting s26
ATHRS26: s26 reset done
ag7240_phy_setup
eth1 up
eth0, eth1
Autobooting in 1 seconds /*此时输入tpl三个字母中断启动*/
hornet> setenv ipaddr 192.168.1.1 /*设置本机地址*/
hornet> setenv serverip 192.168.1.10 /*设置tftp服务器地址*/
hornet> tftpboot 0x80000000 wr703nv1.bin /*下载刷机固件*/
eth1 link down
dup 1 speed 100
Using eth0 device
TFTP from server 192.168.1.10; our IP address is 192.168.1.1
Filename 'wr703nv1.bin'.
Load address: 0x80000000
Loading: #################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
#################################################################
######################################################
done
Bytes transferred = 3932160 (3c0000 hex) /*成功下载固件,记住括号里文件的大小,我这里刷的是官方的*/
hornet> erase 0x9f020000 +0x3c0000 /*擦除Flash,以0x9f020000为起点,往后0x3c0000个内存单位的空间,注意+号前面有空格*/
First 0x2 last 0x3d sector size 0x10000 61
Erased 60 sectors
hornet> cp.b 0x80000000 0x9f020000 0x3c0000 /*从0x80000000写入固件到0x9f020000,大小为0x3c0000*/
Copy to Flash... write addr: 9f020000
done /*刷机成功!*/
/*以上是刷机时的全程TTL信息*/
/*帮助信息*/
hornet> help
? - alias for 'help'
bootm - boot application image from memory
cp - memory copy
erase - erase FLASH memory
help - print online help
md - memory display
mm - memory modify (auto-incrementing)
mtest - simple RAM test
mw - memory write (fill)
nm - memory modify (constant address)
printenv- print environment variables
progmac - Set ethernet MAC addresses
reset - Perform RESET of the CPU
setenv - set environment variables
tftpboot- boot image via network using TFTP protocol
version - print monitor version
hornet>
? - alias for 'help'
bootm - boot application image from memory
cp - memory copy
erase - erase FLASH memory
help - print online help
md - memory display
mm - memory modify (auto-incrementing)
mtest - simple RAM test
mw - memory write (fill)
nm - memory modify (constant address)
printenv- print environment variables
progmac - Set ethernet MAC addresses
reset - Perform RESET of the CPU
setenv - set environment variables
tftpboot- boot image via network using TFTP protocol
version - print monitor version
/*帮助信息*/