void GetComponentID() { char buf[BUFSIZE]; SDMService service; SDMData data; service.source = DataManager; service.source.setSensorID(1); //DataManager sensor_id is always 1 service.destination.setPort(my_port); service.command_id = 264; //Could be queried for by using a SDMReqReg with item_name = ReturnSensorID service.length = 4; PUT_INT(service.data,PID); service.Send(); mm.BlockGetMessage(buf); data.Unmarshal(buf); my_PID = GET_LONG(data.msg); my_sensorID = GET_LONG(&data.msg[4]); //Could be gotten from the Messagemanipulator printf("My PID is %ld\n",my_PID); printf("My sensor_id is %ld\n",my_sensorID); }
int main(int argc,char** argv) { SDMService service; SDMConsume con; MessageManager mm; char buf[BUFSIZE]; char name[128]; char ip[17]; long port; SDMComponent_ID id; int pid = 0; SDMData dat; SDMInit(argc,argv); my_port = getPort(); if (my_port < 0) { printf("Error getting port.\n"); return -1; } mm.Async_Init(my_port); RegisterxTEDS(); usleep(100); service.source.setSensorID(1); service.command_id = 264; service.destination.setPort(my_port); service.length = 4; pid = atoi(argv[3]); memcpy(service.data,&pid,4); service.Send(); if (mm.BlockGetMessage(buf) != SDM_Data) { printf("Error, unknown message received.\n"); return -1; } dat.Unmarshal(buf); pid = GET_LONG(dat.msg); printf("My SensorID is %d\n",pid); service.command_id = 262; memcpy(service.data,&pid,4); service.Send(); if (mm.BlockGetMessage(buf) != SDM_Data) { printf("Error, unknown message received.\n"); return -1; } dat.Unmarshal(buf); memset(name,0,128); strncpy(name,dat.msg,127); printf("My name is %s\n",name); service.command_id = 268; service.Send(); if (mm.BlockGetMessage(buf) != SDM_Data) { printf("Error, unknown message received.\n"); return -1; } dat.Unmarshal(buf); port = GET_LONG(dat.msg); strcpy(ip,&dat.msg[4]); printf("My port is %ld and my ip is %s\n",port,ip); service.command_id = 267; service.Send(); service.command_id = 270; id.setSensorID(pid); id.setPort(port); id.setAddress(inet_addr(ip)); id.Unmarshal(service.data,0); service.Send(); if (mm.BlockGetMessage(buf) != SDM_Data) { printf("Error, unknown message received.\n"); return -1; } dat.Unmarshal(buf); printf("My componentKey is %s\n",dat.msg); CancelxTEDS(); }
int main (int argc, char ** argv) { MessageManager mm; char buf[BUFSIZE]; SDMSearchReply ReplyMsg; unsigned char type; char InfoSource[40]; char MessageID[40]; SDMInit(argc, argv); signal(SIGINT,SigHandler); myPort = getPort(); if (myPort == SDM_PM_NOT_AVAILABLE) { myPort = 4059; } mm.Async_Init(myPort); printf("-------------------SDMSearch Tester-------------------\n"); bool MenuFinished = false; while (!MenuFinished) MenuFinished = Menu(); printf("Sending request...\n"); Request.destination.setPort(myPort); Request.Send(); int count = 1; bool Finished = false; if (Request.reply > SDM_SEARCH_CURRENT) { printf("Press CTRL+C to quit.\n"); sleep(1); } while (!Finished || Request.reply > SDM_SEARCH_CURRENT) { type = mm.BlockGetMessage(buf); switch (type) { case SDM_SearchReply: { long length = ReplyMsg.Unmarshal(buf); if (length == SDM_NO_FURTHER_DATA_PROVIDER) Finished = true; else { ReplyMsg.source.IDToString(InfoSource, sizeof(InfoSource)); printf("(%d) SearchReply received (%s):\n",count++, InfoSource); printf("\t---Captured Text Portion:---\n"); bool nullFound = false; for (unsigned int i = 0; i < sizeof(ReplyMsg.captured_matches); i++) { if (isprint(ReplyMsg.captured_matches[i])) { printf("%c", ReplyMsg.captured_matches[i]); nullFound = false; } else if (ReplyMsg.captured_matches[i] == '\0') { printf("0"); if (nullFound) { printf("\n"); break; } nullFound = true; } } } break; } default: printf("Unexpected message (%d).\n",type); } } printf("End of SDMSearch messages.\n"); printf("-------------------SDMSearch Tester Finished-------------------\n"); return 0; }