void TRf24Radio::Init() { Notify->OnNotify(TNotifyType::ntInfo, "Initializing RF24 radio device ..."); TRadioProtocol::InitRadio(*Radio, *Network, MyAddr, RF24_PA_MAX); Notify->OnNotifyFmt(TNotifyType::ntInfo, "My address: %d", MyAddr); Notify->OnNotifyFmt(TNotifyType::ntInfo, "Values per payload: %d", VALS_PER_PAYLOAD); if (MyAddr != 00) { Notify->OnNotifyFmt(TNotifyType::ntInfo, "Contacting parent node: %d", Network->parent()); Send(Network->parent(), 'k', TMem()); } ReadThread.Start(); }
bool TRf24Radio::Pong(const uint16& NodeId) { Notify->OnNotifyFmt(TNotifyType::ntInfo, "Ponging node %u ...", NodeId); return Send(NodeId, REQUEST_PONG, TMem()); }
void *TMongSrv::HandleRequest(enum mg_event event, struct mg_connection *conn, const struct mg_request_info *request_info) { // Since this is a static request handler, find out for which // server instance this is for. The URL should tell that. TChA UrlStr = "http://"; const char *Host = mg_get_header(conn, "Host"); UrlStr += Host != NULL ? Host : "localhost"; UrlStr += request_info->uri; if (request_info->query_string != NULL) { UrlStr += "?"; UrlStr += request_info->query_string; } void *processed = (void *) "yes"; TStr UrlS = UrlStr; PUrl Url = TUrl::New(UrlS); if (!Url->IsOk(usHttp)) { TNotify::OnNotify(TNotify::StdNotify, ntErr, TStr("Invalid URI: ") + UrlStr); return NULL; } PMongSrv& Server = TMongSrv::Get(Url); if (request_info->log_message != NULL) { TNotify::OnNotify(Server->GetNotify(), ntErr, TStr(request_info->log_message)); return NULL; } THttpRqMethod Method = hrmUndef; if (strncmp(request_info->request_method, "POST", 4) == 0) { Method = hrmPost; } else if (strncmp(request_info->request_method, "GET", 3) == 0) { Method = hrmGet; } else if (strncmp(request_info->request_method, "HEAD", 4) == 0) { Method = hrmHead; } else { return NULL; } TStr ContentType = mg_get_header(conn, THttp::ContTypeFldNm.CStr()); const char *ContentLenStr = mg_get_header(conn, "Content-Length"); PHttpRq Rq; if (Method == hrmPost) { int ContentLength = atoi(ContentLenStr); char *Body = new char[ContentLength]; mg_read(conn, Body, ContentLength); Rq = THttpRq::New(Method, Url, ContentType, TMem(Body, ContentLength)); delete[] Body; } else { Rq = THttpRq::New(Method, Url, ContentType, TMem()); } int ClientId = Server->NewClient(conn, request_info); try { Server->OnHttpRq(ClientId, Rq); Server->DropClient(ClientId); return processed; } catch (PExcept& Exception) { TNotify::OnNotify(Server->GetNotify(), ntErr, Exception->GetStr()); Server->DropClient(ClientId); return NULL; } }