然而,靠「Zoom」弘法,
不少機構只是把原來的課程/開示設計原封不動地改為網上直播,
講者的挑戰則更大,除了要學習「網紅式」鏡頭表達技巧外,
更重要是,聽眾常覺得網上的開示「必然會」重播,便會想「
| /*********** File : yuv_ardiff.c Description : To compare the Y space of two yuv files for motion detection Accumulative Relative Diff Usage : yuv_ardiff file1.yuv file2.yuv Modification History 2017-08-01 Initial version 2017-08-06 Change counter to accumulative 2017-08-08 Use Relative ratio */ #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> int main (int argc, char **argv) { struct stat st; int file1_size, file2_size; int y_size; int i; FILE *fp1; FILE *fp2; unsigned char byte1, byte2; int diff, sum, rdiff;; int count[256]; if (argc != 3) { printf ("Usage: %s file1.yuv file2.yuv\n", argv[0]); return 0; } if (stat(argv[1], &st) == -1) { printf ("Error: Cannot get the file size of %s\n", argv[1]); return 0; } file1_size = st.st_size; /* printf ("%d\n", file1_size); */ if (stat(argv[2], &st) == -1) { printf ("Error: Cannot get the file size of %s\n", argv[2]); return 0; } file2_size = st.st_size; /* printf ("%d\n", file2_size); */ if (file1_size != file2_size) { printf ("Error: File size of %s (%d) is not equal to %s (%d)\n", argv[1], file1_size, argv[2], file2_size); return 0; } /* The first 2/3 are Y, next 1/6 is U and last 1/6 is V */ if ((file1_size % (3*16*16)) != 0) { /* actual is 1.5 * 32 * 16 */ printf ("Error: File size (%d) should be multiple of 1.5*32*16\n", file1_size); return 0; } fp1 = fopen (argv[1], "r"); if (fp1 == NULL) { printf ("Error: Cannot open file (%s)\n", argv[1]); return 0; } fp2 = fopen (argv[2], "r"); if (fp2 == NULL) { printf ("Error: Cannot open file (%s)\n", argv[2]); return 0; } y_size = file1_size * 2 / 3; /* printf ("y_size = %d\n", y_size); */ for (i=0; i<256; i++) count[i] = 0; for (i=0; i< y_size; i++) { if (fread (&byte1, 1, 1, fp1) != 1) { printf ("Error: Cannot read byte from (%s)\n", argv[1]); return 0; } if (fread (&byte2, 1, 1, fp2) != 1) { printf ("Error: Cannot read byte from (%s)\n", argv[2]); return 0; } diff = abs (byte1 - byte2); sum = byte1 + byte2; if (sum > 0) rdiff = (diff * 256) / sum; else rdiff = 0; if (rdiff > 255) { printf ("Error: rdiff (%d) is greater than 255\n", rdiff); return 0; } (count[rdiff])++; } // for loop fclose (fp1); fclose (fp2); for (i=254; i>=0; i--) count[i] += count[i+1]; for (i=0; i<256; i++) printf ("%d ", count[i]); printf ("\n"); return 0; } // main ===================================================== #!/bin/bash # File: pi_camera_motion.sh cd /home/whc/motion rm -f last.yuv if [ -e current.yuv ]; then mv current.yuv last.yuv fi DATE=`date +"%Y%m%d_%H%M%S"` raspiyuv -n -h 2464 -w 3280 -o current.yuv if [ -e last.yuv ]; then yd=`/home/whc/bin/yuv_adiff last.yuv current.yuv` echo ${DATE} ${yd} >> /home/whc/yuv_ardiff.log diff_count=`echo ${yd} | awk '{print \$101}'` if [ "${diff_count}" -gt "10000" ]; then convert -size "3296x2464" -depth 8 -sampling-factor "4:2:0" yuv:current.yuv pi_photo_${DATE}.jpg /home/whc/gdrive-linux-rpi upload --parent xxxxxxxxxxxxxxxxxxxxxxxxxx pi_photo_${DATE}.jpg fi fi |
| openssl s_client -connect localhost:8000 -cert client.pem -key key.pem -CApath . -CAfile ca.pem -showcerts -debug -msg -state -crlf -ign_eof <<EOF POST /app HTTP/1.1 hostname: localhost Content-Type: application/x-www-form-urlencoded Content-Length: XXX <?xml version='1.0'?><Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/' xmlns:op='http://schemas.xyz.com/svc' xmlns:ems='http://schemas.xyz.com/ems'><Header>Header_Text</Header><Body><op:AddPbs><ems:ChannelAcctId><ems:ChannelId>06</ems:ChannelId><ems:AcctId>1234567</ems:AcctId></ems:ChannelAcctId></op:AddPbs></Body></Envelope> EOF |
| import java.io.FileInputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpsServer;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpsExchange;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsParameters;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.SSLContext;
import java.security.KeyStore;
import java.net.URI;
import java.net.InetSocketAddress;
public class java_https_server implements HttpHandler {
private static final int HTTP_OK_STATUS = 200;
// ----------class property --------------
private String context = "/";
private int port = 8000;
private String keystorePasswordString = "password";
private String keystoreFile = "/full_path/keystore.jks";
private String truststorePasswordString = "password";
private String truststoreFile = "/full_path/truststore.jks";
// --------- Constructor -------------------
public java_https_server () {
}
// --------------------------------------------
public HttpsServer CreateHttpServer(int port, String context) {
HttpsServer httpServer;
try {
httpServer = HttpsServer.create(new InetSocketAddress(port), 0);
SSLContext sslContext = SSLContext.getInstance("TLS");
// server keystore
char[] keystorePassword = keystorePasswordString.toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
ks.load (new FileInputStream(keystoreFile), keystorePassword);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init (ks, keystorePassword);
// server truststore
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
char[] truststorePassword = truststorePasswordString.toCharArray();
ks.load (new FileInputStream(truststoreFile), truststorePassword);
tmf.init (ks);
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
// create an anonymous inner class HttpsConfigurator to require client certificate
HttpsConfigurator configurator = new HttpsConfigurator(sslContext) {
public void configure (HttpsParameters params) {
SSLParameters sslParams = getSSLContext().getDefaultSSLParameters();
sslParams.setNeedClientAuth(true);
params.setSSLParameters(sslParams);
}
};
httpServer.setHttpsConfigurator(configurator);
//Create a new context for the given context and handler
httpServer.createContext(context, this);
//Create a default executor
httpServer.setExecutor(null);
}
catch (Exception e) {
e.printStackTrace();
return null;
}
return httpServer;
} // method CreateHttpServer
// --------------------------------------------
public void handle(HttpExchange t) throws IOException {
URI uri = t.getRequestURI();
String response;
System.out.println ("LocalAddress: " + t.getLocalAddress().toString());
System.out.println ("RemoteAddress: " + t.getRemoteAddress().toString());
System.out.println ("URL is: " + uri.toString());
System.out.println ("Method: " + t.getRequestMethod());
System.out.println ("Client Certficate: " +
((HttpsExchange)t).getSSLSession().getPeerCertificateChain()[0].getSubjectDN());
if (t.getRequestMethod().equals ("POST")) {
InputStream is = t.getRequestBody();
byte[] data = new byte[100000];
int length = is.read(data);
if (length == 100000)
System.out.println ("Warning: the input buffer is FULL!");
System.out.println ("Request Length: " + length);
data = java.util.Arrays.copyOf(data, length); // trim the array to the correct size
System.out.println ("Request Body:[" + new String(data) + "]");
is.close();
response = "Give your response here";
}
else {
response = "Error";
}
//Set the response header status and length
t.sendResponseHeaders(HTTP_OK_STATUS, response.getBytes().length);
//Write the response string
OutputStream os = t.getResponseBody();
os.write(response.getBytes());
os.close();
}
// --------------------------------------------
public static void main(String[] args) throws Exception {
java_https_server server = new java_https_server();
System.out.println("Use Ctrl-C (foreground) or \"kill -15 (background)\" to stop me");
final HttpsServer httpServer = server.CreateHttpServer(server.port, server.context);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Stopping Server..");
httpServer.stop(0);
System.out.println("Server stopped");
} // run()
});
httpServer.start(); // Start the server
System.out.println("Server is started and listening on port "+ server.port);
} // method main
} // class java_https_server
|
$ java -cp . java_https_server
Use Ctrl-C (foreground) or "kill -15 (background)" to stop me
Server is started and listening on port 8000
LocalAddress: /127.0.0.1:8000
RemoteAddress: localhost/127.0.0.1:52204
URL is: /app
Method: POST
Client Certficate: CN=ccm010, OU=xxx, O=xxx, L=xxx, ST=xxx, C=HK
Request Length: 385
Request Body:[<?xml version='1.0'?><Envelope xmlns='http://schemas.xmlsoap.org/soap/envelope/' xmlns:op='http://schemas.xyz.com/svc' xmlns:ems='http://schemas.xyz.com/ems'><Header>Header_Text</Header><Body><op:AddPbs><ems:ChannelAcctId><ems:ChannelId>06</ems:ChannelId><ems:AcctId>1234567</ems:AcctId></ems:ChannelAcctId></op:AddPbs></Body></Envelope>]
Stopping Server..
Server stopped
|
|
Invoke libxml function
|
Input/Output
|
Outstanding Object
|
|
xmlParseFile
|
Input: xml filename
Output: xmlDocPtr
|
xmlDocPtr
|
|
xmlPathNewContext
|
Input: xmlDocPtr
Output: xmlXPathContextPtr
|
xmlDocPtr
xmlXPathContextPtr
|
|
xmlXPathRegisterNs (only applicable for xml with
namespace)
|
Input: xmlXPathContextPtr
namespace_prefix
namespace_URL
|
|
|
xmlXPathEvalExpression
|
Input: XPath_Expression,
xmlXPathContextPtr
Output: xmlXPathObjectPtr
|
xmlDocPtr
xmlXPathContextPtr
xmlXPathObjectPtr
|
|
xmlXPathFreeContext
|
|
xmlDocPtr
xmlXPathObjectPtr
|
|
Check if xmlXPathNodeSetIsEmpty
|
Input: xmlXPathObjectPtr->nodesetval
|
|
|
Retrieve the node:
xmlXPathObjectPtr ->nodesetval->nodeTab[0]
|
|
|
|
Retrieve the text of the node
xmlNodeGetContent
|
Input: xmlNode *
Output: xmlChar *
|
xmlDocPtr
xmlXPathObjectPtr
xmlChar * node_text
|
|
xmlFree (node_text)
xmlXPathFreeObject(xmlXPathObjectPtr)
|
|
xmlDocPtr
|
|
Final Clean up
xmlFreeDoc(xmlDocPtr);
xmlCleanupParser();
|
|
Nil
|