几种地图经纬度坐标系转换
wgs84:GPS使用的坐标系
gcj02:中国国家测绘局制订的地理信息系统的坐标系统,是在WGS84经纬度的基础上执行加密算法而成。因为GPS得到的经纬度直接在 GCJ-02 坐标系下会定位到错误的地点,有种到了火星的感觉,因此在坊间也将 GCJ-02 戏称为火星坐标系。高德地图、腾讯地图均使用的此坐标系。
bd09:百度地图使用的,在gcj02基础上又做了一次转换。
地图 | 大陆/港/澳 | 台湾省 | 海外 |
---|---|---|---|
高德 |
blackfeather 2022/9/8 ℃ 0评论
wgs84:GPS使用的坐标系
gcj02:中国国家测绘局制订的地理信息系统的坐标系统,是在WGS84经纬度的基础上执行加密算法而成。因为GPS得到的经纬度直接在 GCJ-02 坐标系下会定位到错误的地点,有种到了火星的感觉,因此在坊间也将 GCJ-02 戏称为火星坐标系。高德地图、腾讯地图均使用的此坐标系。
bd09:百度地图使用的,在gcj02基础上又做了一次转换。
地图 | 大陆/港/澳 | 台湾省 | 海外 |
---|---|---|---|
高德 |
blackfeather 2022/9/8 ℃ 0评论
任务队列可以认为是执行同一个方法来处理数据的队列,指定回调函数。
线程池就是先开辟好多个线程,然后将要执行的方法+参数丢到线程池中,支持返回值获取。
blackfeather 2021/8/24 ℃ 0评论
很多应用需要监控系统资源的使用率等信息,之前零散写过很多。
近日需要读取硬盘的IO使用率,就是任务管理器中的硬盘相关信息。
读写速度很好搞定,但是这个百分比的使用率(活动时间)恶心了,最后搜索到的技术点都指向了Pdh(performance data helper)库。
blackfeather 2021/6/25 ℃ 0评论
背景需求
每个工作背景都不同,需要总结一下:
1.C++编写,跨平台(windows上用的vs2013,所以是C++11标准)
2.支持http和ws的server,支持多线程,支持uri映射(类似addhandler("/hello",onrequestcallback);),支持请求中相关字段的获取(get/post参数读取、header、cookie等读取)
3.不用性能超强,并发数也不大(几十并发)
blackfeather 2020/10/30 ℃ 5评论
基于C++11的线程池(threadpool)简洁且可以带任意多的参数
源代码来自Github上作者progschj,地址为:A simple C++11 Thread Pool implementation,具体博客可以参见Jakob’s Devlog,地址为:A Thread Pool with C++11
blackfeather 2020/10/2 ℃ 0评论
timer定时器,多线程,回调为阻塞模式。支持参数绑定,非常好使。
用法:
////////////////////////////////////////////////////////////////////////// //以下是测试代码 namespace timertester { class timertestclass { public: timertestclass(){}; ~timertestclass(){}; void testfn() { printf("timer callback is class func.\n"); FTimerEvent mTimer(3000, &timertestclass::threadfn, this); for (int i = 0; i < 5; i++) { printf("press any key to ...\n"); getchar(); mTimer.SetTimerEvent(); } printf("stop timer \n"); mTimer.StopTimer(); } void threadf(int i) { printf("test f i:%d\n", i); } void threadfn() { printf("test fn d\n"); } void threadfn2() { printf("test fn2222 \n"); } }; static void testfn1(timertestclass *cls) { cls->threadfn(); } static void testpf() { printf("test printf \n"); printf("callback ret. \n"); } static void prt(int& i) { printf("print %d\n", i); } static void timertest() { int t = 0; FTimerEvent timerstdref(1000, prt, std::ref(t)); for (int i = 0; i < 10; i++) { t = i; Sleep(1000); } timerstdref.StopTimer(); { printf("timer 0 manual to set\n"); //如果定时为0,则每次为手动触发 FTimerEvent timerman(0, [](){ printf("timerman in.\n"); Sleep(5000); printf("timerman out.\n"); }); timerman.SetTimerEvent(); timerman.SetTimerEvent(); timerman.StopTimer(); } printf("stop timer in callback\n"); FTimerEvent timer4; timer4.InitTimer(1000, [](FTimerEvent *pTimer){ printf("exit timer\n"); pTimer->StopTimer(); }, &timer4); Sleep(3000); timer4.StopTimer(); printf("set timer in callback\n"); FTimerEvent timer5; timer5.InitTimer(2000, [](FTimerEvent *pTimer){ static bool set = false; printf("timer in\n"); if (!set) { printf("set timer\n"); pTimer->SetTimerEvent(); set = true; } printf("timer out\n"); }, &timer5); Sleep(10000); timer5.StopTimer(); timertestclass test1; test1.testfn(); int x = 0; FTimerEvent timerref(1000, [&x]() { printf("x: %d \n", x); }); for (int i = 0; i < 10; i++) { x = i; Sleep(1000); } timerref.StopTimer(); FTimerEvent timerx(1000, [&test1]() { test1.threadfn2(); }); Sleep(10000); timerx.StopTimer(); FTimerEvent timer0(1000, testpf); Sleep(10000); timer0.StopTimer(); FTimerEvent timer1(1000, testfn1, &test1); Sleep(10000); timer1.StopTimer(); FTimerEvent timer2(1000, [](){ printf("lambada no param \n"); }); Sleep(10000); timer2.StopTimer(); int param = 0; FTimerEvent timer3(1000, [](int *p){ printf("lambada with param: %d \n", *p); }, ¶m); Sleep(10000); timer3.StopTimer(); } }
blackfeather 2020/9/7 ℃ 0评论
基于openssl库写的aes_gcm解密方法
兼容gcm 128、192、256位,兼容变长iv算法,与python和java的gcmdecrypt方法结果保持一致。
最恶心的地方在iv长度,要手动设置,否则某些情况下会与python或者java的结果不一致(代码的24行)。
std::string AesGCMDecrypt(const std::string &strKey, const std::string &strIV, const std::string &strBuffer, int nPadding/* = 1*/) { std::string strRet; if (strBuffer.empty()) return strRet; const EVP_CIPHER *cipher; if (strKey.length() == 16) cipher = EVP_aes_128_gcm(); else if (strKey.length() == 24) cipher = EVP_aes_192_gcm(); else if (strKey.length() == 32) cipher = EVP_aes_256_gcm(); else return strRet; unsigned char *pszDecode = new unsigned char[strBuffer.length() + 32]; ZeroMemory(pszDecode, strBuffer.length() + 32); unsigned char *pszOut = pszDecode; int nDecodeLen, nTotalLen = 0; EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new(); EVP_DecryptInit_ex(ctx, cipher, NULL, NULL, NULL); if (strIV.length() != 12) EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, strIV.length(), NULL); EVP_DecryptInit_ex(ctx, NULL, NULL, (const unsigned char *)strKey.c_str(), (const unsigned char *)strIV.c_str()); EVP_CIPHER_CTX_set_padding(ctx, nPadding); EVP_DecryptUpdate(ctx, pszOut, &nDecodeLen, (const unsigned char *)strBuffer.c_str(), strBuffer.length()); nTotalLen = nDecodeLen; pszOut += nDecodeLen; EVP_DecryptFinal(ctx, pszOut, &nDecodeLen); nTotalLen += nDecodeLen; strRet.assign((const char *)pszDecode, nTotalLen); delete[] pszDecode; EVP_CIPHER_CTX_free(ctx); return strRet; }
blackfeather 2020/9/1 ℃ 1评论
在C/C++编码中,open对close,new对delete,malloc对free等等是严格要求的,否则会有各种泄露的奇葩情况。
但是实际编码中,各种异常捕捉和错误判断又让编码变得繁琐臃肿。
后来在使用golang中,defer方法使用非常方便,C++虽然没有自带的,但是可以写嘛!
借助C++类的析构方法和lambada表达式,还有std::function容器,很容易写出来一个自己的defer(以下代码是复制来的,感觉非常的干练,自己写的不好看不贴了,后来也用了这个.h)
blackfeather 2020/9/1 ℃ 0评论
plist是苹果最常用的配置文件存储类型之一,plist实际为xml,xml操作远没有json方便,并且苹果很多应用存储的plist跟NSArray等对象是绑定的,又会设计到了uid重定位等问题,于是写了一个plist转json的类,一次convert,方便受用。
内部基本上都封装完毕,基于libplist和jsoncpp库,支持xml和bplist两种格式,data类型为了考虑十六进制buffer使用了base64编码
使用方法:
blackfeather 2020/9/1 ℃ 0评论
有缘人拿去。。。RFC 3394,AESUnwrap。。。某些情况下使用的。
uint8_t AES_unwrap(uint8_t *kek, uint16_t key_len, uint8_t *cipher_text, uint16_t cipher_len, uint8_t *output) { uint8_t a[8], b[16]; uint8_t *r; uint8_t *c; uint16_t i, j, n; AES_KEY ctx; if (! kek || cipher_len < 16 || ! cipher_text || ! output) { /* We don't do anything with the return value */ return 1; } /* Initialize variables */ n = (cipher_len/8)-1; /* the algorithm works on 64-bits at a time */ memcpy(a, cipher_text, 8); r = output; c = cipher_text; memcpy(r, c+8, cipher_len - 8); /* Compute intermediate values */ for (j=5; j >= 0; --j) { r = output + (n - 1) * 8; /* DEBUG_DUMP("r1", (r-8), 8); */ /* DEBUG_DUMP("r2", r, 8); */ for (i = n; i >= 1; --i) { uint16_t t = (n*j) + i; /* DEBUG_DUMP("a", a, 8); */ memcpy(b, a, 8); b[7] ^= t; /* DEBUG_DUMP("a plus t", b, 8); */ memcpy(b+8, r, 8); AES_set_decrypt_key(kek, 128, &ctx); AES_decrypt(b, b, &ctx); /* NOTE: we are using the same src and dst buffer. It's ok. */ /* DEBUG_DUMP("aes decrypt", b, 16) */ memcpy(a,b,8); memcpy(r, b+8, 8); r -= 8; } } /* DEBUG_DUMP("a", a, 8); */ /* DEBUG_DUMP("output", output, cipher_len - 8); */ return 0; }
blackfeather 2019/6/25 ℃ 0评论