2021年2月

go的chan

无缓冲区channel

package main

import (
    "fmt"
    "time"
)

func main() {
    ch := make(chan int) // 创建无缓冲channel
    go func() {
        fmt.Println("time sleep 5 second...")
        time.Sleep(5 * time.Second)
        <-ch
    }()
    fmt.Println("即将阻塞...")
    ch <- 1 // 协程将会阻塞,等待数据被读取
    fmt.Println("ch 数据被消费,主协程退出")
}

结果,消费完才能继续

即将阻塞...
time sleep 5 second...
ch 数据被消费,主协程退出

- 阅读剩余部分 -

编译nginx

为啥要编译,希望编译些模块
Ubuntu 20.04 LTS集成的版本nginx version: nginx/1.18.0 (Ubuntu)

wget 'http://nginx.org/download/nginx-1.18.0.tar.gz'
tar -xzvf nginx-1.18.0.tar.gz

wget 'https://github.com/winshining/nginx-http-flv-module/archive/v1.2.8.tar.gz'
tar -xzvf v1.2.8.tar.gz

cd nginx-1.18.0
./configure --add-module=/home/user/nginx/nginx-http-flv-module-1.2.8

提示:error: the HTTP rewrite module requires the PCRE library
sudo apt-get install libpcre3-dev
配置成功,默认位置,可以通过--prefix=/usr/local/nginx配置

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

- 阅读剩余部分 -

Ubuntu安装FFmpeg、flv.js

sudo apt-get install ffmpeg
太慢小时级别,需要换个阿里源分钟级别
ffmpeg -version
ffmpeg version 4.2.4-1ubuntu0.1

关于视频推送的一个项目RtspWebSocket
https://gitee.com/yzfar/RtspWebSocket/tree/master

npm install flv.js
下载素材
https://blog.csdn.net/qq_41672008/article/details/103676839

参考资料:
https://www.cnblogs.com/lonelamb/p/11620906.html

酸汤面的串口

从官方的demo来看,串口分为ComDMA、ComIT、ComPolling三个例程,字面意思是DMA、中断、轮询。
其中还有个球猫老师早就知道空闲中断,就是闲得就中断...

建立一个叫Echo的工程,打开串口中断,确认115200-N-8-1,还得打开debuger的自动reset and run

uint8_t usart_rx_buffer[128];

HAL_UART_Receive_IT(&huart2, (uint8_t*)usart_rx_buffer, 1);  

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)  
{  
    if(huart ->Instance == USART2){  
        printf("%c",usart_rx_buffer[0]);  
        HAL_UART_Receive_IT(&huart2, (uint8_t*)usart_rx_buffer, 1);  
    }  
}

- 阅读剩余部分 -

frp很好玩,球猫说的,内网穿透

官网地址
https://github.com/fatedier/frp
下载地址
https://github.com/fatedier/frp/releases
服务端配置

wget https://github.com/fatedier/frp/releases/download/v0.34.0/frp_0.34.0_linux_amd64.tar.gz
tar -xvf frp_0.34.0_linux_amd64.tar.gz

可以建立一个frps_xxx.ini的配置文件

[common]
bind_port = 4001
dashboard_addr = 0.0.0.0
dashboard_port = 4002
dashboard_user = admin
dashboard_pwd = password
enable_prometheus = true
log_file = ./frps_xxx.log
use_encryption = true
use_compression = true
authentication_method = token
token = asdasd

然后用./frps -c ./frps_xxx.ini &来启动服务端
需要开放4001端口给外网,可以通过http://ip:4002访问网页

客户端仅需要frpc和frpc.ini就可以

[common]
server_addr = ip
server_port = 4001
token = asdasd
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 1234
use_encryption = true
use_compression = true

把本地的ssh端口映射到服务端的1234,执行./frpc -c ./frpc.ini &