123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // Created by Administrator on 2019/1/14.
- //
- #include "site_message_handle.h"
- #include "system_basic_info/SystemAnalysis.h"
- #include "common_tool.h"
- #include "ant.h"
- #include "ya_event.h"
- /** 解析 分站发送过来的数据中(分站的信息数据)*/
- void site_message_handle::parse_data_locate_reader(char * DataBuffer, int nLen, int dwConnID,int& nCurPos
- , int& reader_id )
- {
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_15);
- #pragma pack(1)
- // 7字节 从第一个字节开始,分别表示秒、分、时、天、周、月、年
- struct _LocateInfo
- {
- unsigned int site_id; //分站ID
- unsigned short time_stamp; //时间戳(0-65535)
- unsigned char sec;
- unsigned char min;
- unsigned char hour;
- unsigned char day;
- unsigned char week;
- unsigned char mon;
- unsigned char year;
- unsigned char site_relation; //分站类型
- unsigned char site_state; //分站状态char
- unsigned char site_power; //分站电源类型
- };
- #pragma pack()
- _LocateInfo *_pLocateInfo = (_LocateInfo *)(DataBuffer + nCurPos);
- if (tool_other::IsBigEnd()) //大端
- {
- _pLocateInfo->site_id = ntohl(_pLocateInfo->site_id);
- _pLocateInfo->time_stamp = ntohs(_pLocateInfo->time_stamp);
- }
- nCurPos += sizeof(_LocateInfo);
- reader_id = _pLocateInfo->site_id;
- std::shared_ptr<site> pSite = sit_list::instance()->get(_pLocateInfo->site_id);
- bool isErrorReader = false;
- if(pSite){
- //add_socket_to_list(dwConnID, reader_id, DEVICE_TYPE::DT_CARD_READER);
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_16);
- }else{
- pSite = std::make_shared<site>();
- pSite->m_id = reader_id;
- LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_17);
- }
- // 接收数据时间
- pSite->m_rec_time = time(NULL);
- m_time_last_rec = pSite->m_rec_time; // 更新最后信号时间
- // 分站时间戳
- pSite->m_tick_count = _pLocateInfo->time_stamp;
- // 分站时间
- // 7字节 从第一个字节开始,分别表示秒、分、时、天、周、月、年
- struct tm reader_time;
- reader_time.tm_sec = _pLocateInfo->sec;
- reader_time.tm_min = _pLocateInfo->min;
- reader_time.tm_hour = _pLocateInfo->hour;
- reader_time.tm_mday = _pLocateInfo->day;
- reader_time.tm_wday = _pLocateInfo->week;
- reader_time.tm_mon = _pLocateInfo->mon - 1;
- reader_time.tm_year = _pLocateInfo->year + 100; // + 2000 - 1900
- pSite->m_time = mktime(&reader_time);
- //改为大小分站信息,最高位第7位表示大小分站,1表示大分站,0表示小分站
- //高6位表示分站(大或小)在大分站的左侧或右侧,1代表在大分站的左侧,0表示在大分站的右侧
- //高5位预留位,用于区分是读卡分站还是大小分站
- uint8_t reader_type = _pLocateInfo->site_relation >>7; //大小分站的区别
- uint8_t reader_dir = (_pLocateInfo->site_relation >>6)&0x01;
- uint8_t reader_type_locate = (_pLocateInfo->site_relation >>5)&0x01; //大小分站与读卡分站的区别
- uint8_t relay_counts = _pLocateInfo->site_relation&0x0F;
- pSite->m_reader_dir = reader_dir;
- pSite->m_relay_counts = relay_counts;
- reader_power_battery_alarm(_pLocateInfo->site_id,_pLocateInfo->site_power);
- log_info("id:%d, n:%d, %.2d-%.2d-%.2d %.2d:%.2d:%.2d, sta: %d,reader_power: %d"
- ",reader_type: %d,is_big_reader: %d,is_left: %d, counts: %d",
- _pLocateInfo->site_id, _pLocateInfo->time_stamp, _pLocateInfo->year, _pLocateInfo->mon, _pLocateInfo->day\
- , _pLocateInfo->hour, _pLocateInfo->min,_pLocateInfo->sec\
- , _pLocateInfo->site_state,_pLocateInfo->site_power,reader_type_locate,reader_type,reader_dir,relay_counts);/*tep:%d,*/
- }
- /** 解析单个卡数据 */
- int site_message_handle::parse_data_locate_card(char * DataBuffer, int reader_id
- , unsigned short wChr,int& nCurPos, unsigned long long ct_time/* = 0*/,int pos/* = 0*/)
- {
- return 0;
- }
- void site_message_handle::reader_power_battery_alarm(unsigned int site_id, int powerType)
- {
- std::shared_ptr<site> pSite = sit_list::instance()->get(site_id);
- if (pSite == nullptr )
- {
- return ;
- }
- std::shared_ptr<ya_event> ev_ptr = event_list::get_event_reader(site_id,ET_READER_POWER_BY_BATTERY);
- int oldEvState = -1;
- int usePowerType = powerType;
- if (!pSite->m_needpower_alarm)
- {
- //如果分站不需要电池供电告警,而告警事件列表中存在告警信息,需要发送结束告警事件
- if (ev_ptr && ev_ptr->m_status == ES_START)
- {
- oldEvState = ES_START;
- usePowerType = 1;
- }
- else
- {
- return;
- }
- }
- switch (usePowerType)
- {
- case 1 : //交流电 取消警告
- {
- if(nullptr == ev_ptr || oldEvState == ES_END)
- {
- return ; //不出在警告并且警告已是取消状态
- }
- event_list::copy_event(pSite,ev_ptr);
- ev_ptr->m_status = ES_END;
- ev_ptr->m_cur_time = std::chrono::system_clock::now();
- ev_ptr->m_cur_value = usePowerType;
- ev_ptr->m_is_display = true;
- event_list::save_event(ev_ptr);
- log_info("[event warning: restore reader power supply] reader_id: %d.",site_id);
- }
- break;
- case 0: //直流电警告
- {
- if(nullptr != ev_ptr && oldEvState == ES_START)
- {
- return ; //已有警告在发送不需要再次添加
- }
- if (nullptr == ev_ptr)
- {
- ev_ptr = event_list::create_event_reader(site_id,ET_READER_POWER_BY_BATTERY);
- event_list::copy_event(pSite,ev_ptr);
- event_list::instance()->add(ev_ptr->get_list_id(),ev_ptr);
- }
- ev_ptr->status = ES_START;
- ev_ptr->m_limit_value = 0;
- ev_ptr->m_cur_value = usePowerType;
- event_list::save_event(ev_ptr);
- log_info("[event warning: reader power supply by battery] reader_id: %d.",site_id);
- }
- break;
- }
- }
|