Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "wmp_config.h"
00038 #include "config/compiler.h"
00039
00040 #include "include/ml_com.h"
00041 #include "include/ll_com.h"
00042
00043 char zFrame[2500];
00044
00045 #ifdef WMP_USE_FRAME_COMPRESSION
00046 #include <zlib.h>
00047
00048 long long max = 0;
00049
00050 int cmp_send(char * f, int size){
00051 uLongf len = 2500;
00052 WMP_DBG(FRAME_COMPRESS,"sending %d bytes\n", size);
00053
00054 unsigned long long ts1 = getRawActualTimeus();
00055 int ret = compress(zFrame,&len,f,size);
00056 unsigned long long ts2 = getRawActualTimeus();
00057 long long ts = ts2 - ts1;
00058 if (ts > max) max = ts;
00059 WMP_DBG(FRAME_COMPRESS,"cmp_time = %lld max:%lld \n",ts,max);
00060
00061 if (ret != Z_OK){
00062 WMP_DBG(FRAME_COMPRESS,"cmp err\n");
00063 return -1;
00064 }
00065 WMP_DBG(FRAME_COMPRESS,"sending %d bytes (compressed) \n", len);
00066 return llpsend(zFrame,len,ZWMP_TYPE_FIELD);
00067 }
00068
00069 rxInfo cmp_receive(char * f, int timeout){
00070 rxInfo rxi = llreceive(zFrame,timeout);
00071 if (rxi.proto == 0x6970){
00072 WMP_DBG(FRAME_COMPRESS,"recvd %d bytes proto: %x\n", rxi.size, rxi.proto);
00073 uLongf len = 2500;
00074 unsigned long long ts1 = getRawActualTimeus();
00075 int ret = uncompress(f,&len,zFrame,rxi.size);
00076 unsigned long long ts2 = getRawActualTimeus();
00077 long long ts = ts2 -ts1;
00078
00079 WMP_DBG(FRAME_COMPRESS,"decmp_time = %lld\n",ts);
00080
00081 if (ret != Z_OK){
00082 WMP_DBG(FRAME_COMPRESS,"uncmp err\n");
00083 rxi.error = 1;
00084 return rxi;
00085 }
00086 rxi.size = len;
00087 WMP_DBG(FRAME_COMPRESS,"returning %d bytes\n",len);
00088 }else{
00089 memcpy(f,zFrame,rxi.size);
00090 }
00091 return rxi;
00092 }
00093 #else
00094
00095 int cmp_send(char * f, int size){
00096 return llsend(f,size);
00097 }
00098
00099 rxInfo cmp_receive(char * f, int timeout){
00100 return llreceive(f,timeout);
00101 }
00102
00103 #endif
00104
00105
00106
00107