/********************************************************************* * グラフ表示内の文字を書く. ********************************************************************* */ void draw_PortName(int adr,int poll_mode) { int i,y1; char string[128]; int color = 0x80ff00; #if _AVR_PORT_ char *port="-"; if(adr == 0x39) port = "A"; if(adr == 0x36) port = "B"; if(adr == 0x30) port = "D"; #else char port[16]="-"; int port_a = portAddress( "PORTA" ); if((adr - port_a)>=0) { if((adr - port_a)< 5) { port[0] = 'A' + (adr - port_a); } } #endif if( poll_mode == POLL_ANALOG) { // 0xa0 int yc = 128+ANALOG_BASE-8; int y0 = ANALOG_BASE-8; int y1 = 256+ANALOG_BASE-8; gr_puts(4,y0,"100",color,0,0); gr_puts(4,yc,"50" ,color,0,0); gr_puts(4,y1,"0" ,color,0,0); }else for(i=0;i<8;i++) { sprintf(string,"P%s%d",port,i); y1 = calc_ypos(i); gr_puts(4,y1-20,string,color,0,0); } }
void UsbCheckPollCmd(void) { #if _AVR_PORT_ pollcmd_implemented = 1; // とりあえず実装されていると仮定. { int gtccr = portAddress("gtccr"); // LSBのみ1か0のポート. int data; int rc = UsbSetPoll(gtccr,0); if(rc==0) { // 失敗. pollcmd_implemented = 0; // 実装されていないと判定. return ; } data = UsbPoll(); if((data == (-1)) || (data & 0xfe)) { pollcmd_implemented = 0; // 実装されていないと判定. } } #else if((UsbGetDevCaps()) == 1) { // bootloaderである. pollcmd_implemented = 0; // 実装されていない. }else{ pollcmd_implemented = 1; // 実装されている. } #endif }
/********************************************************************* * ポート内容をポーリングする. ********************************************************************* */ void cmdPoll(char *buf) { char sample[256]; int v,n,count,i; n = get_arg(buf); //引数の数. if(n != 0) { if(n < 2) { // 1個のポートを読み取る. count = 1000; }else{ count = arg_hex[1]; } v = portAddress(arg_ptr[0]); //ポート名称からアドレスを算出. if(v) { // アドレスが存在する. UsbSetPoll(v,POLL_PORT); for(i=0;i<count;i++) { int val = UsbPoll(sample); cmdPortPrintOneCr(count - i, arg_ptr[0],v,val); if(kbhit()) break; } }else{ // A,B,D全ポート読み. unsigned char portbuf[16]; #if _AVR_PORT_ int adr = 0x30; // PORTD int size = 10; // 0x30〜0x39 #else int adr = portAddress( "PORTA" ); // default PORTC int size = 10; // 0x30〜0x39 #endif for(i=0;i<count;i++) { int rc = UsbRead(adr,arena,portbuf,size); if( rc != size) { printf("poll error %d.\n",rc); return; } cmdPortPrintAllCr(count - i, portbuf); if(kbhit()) break; } } UsbSetPoll(0,0); } printf("\n\n"); }
void cmdQuestion(char *buf) { int v; if( get_arg(buf) < 1) { cmdHelp(""); }else{ v = portAddress(arg_ptr[0]); if(v) printf("%s=0x%x\n",arg_ptr[0],v); } }
void UsbCheckPollCmd() { pollcmd_implemented = 1; // とりあえず実装されていると仮定. { int gtccr = portAddress("gtccr"); // LSBのみ1か0のポート. int data; int rc = UsbSetPoll(gtccr,0); if(rc==0) { // 失敗. pollcmd_implemented = 0; // 実装されていないと判定. return ; } data = UsbPoll(); if((data == (-1)) || (data & 0xfe)) { pollcmd_implemented = 0; // 実装されていないと判定. } } }
/********************************************************************* * arg_ptr[] の文字列をHEX数値とみなして値に変換し arg_hex[]に入れる ********************************************************************* */ void scan_args(int arg_cnt) { int i,v; for(i=0;i<arg_cnt;i++) { v = portAddress(arg_ptr[i]); //シンボル名による解決. if(v) { arg_hex[i] = v; arg_val[i] = v; }else{ v=(-1); sscanf(arg_ptr[i],"%x",&v); arg_hex[i] = v; radix2scanf(arg_ptr[i],&arg_hex[i]); v=(-1); sscanf(arg_ptr[i],"%d",&v); arg_val[i] = v; } } }
//----------------------------------------------------------------------------- bool MakeResponse(CommunicationID requestID, Response** ppResponse) { // protect the maps from being changed by other threads using the mutex ScopeLock lock(s_mutex); PsAssert(ppResponse != NULL); // first see if we already have this ID as a streaming response ResponseMap::iterator iterResponse = g_streamingResponseMap.find(requestID); if (iterResponse != g_streamingResponseMap.end()) { *ppResponse = iterResponse->second; return true; } // otherwise we need to create a new response based on the original request // so get the request RequestMap::iterator iterRequest = g_requestMap.find(requestID); if (iterRequest == g_requestMap.end()) { // the original request couldn't be found, so return failure return false; } // need to create a new response if (PsNew(*ppResponse) == false) { return false; } HTTPRequestHeader* pRequest = iterRequest->second; PsAssert(pRequest != NULL); if (pRequest->GetReceivedOverSocket() == true) { (*ppResponse)->client_socket = pRequest->GetClientSocket(); } else { #if defined (_WIN32) (*ppResponse)->client_socket = NetSocket::CreateFromDuplicate(pRequest->GetProtoInfo()); #else // create a new socket and connect to the streamSocket on the server (*ppResponse)->client_socket = NetSocket::Create(); if ((*ppResponse)->client_socket != NULL) { osPortAddress portAddress((unsigned short)pRequest->GetPort()); (*ppResponse)->client_socket->Connect(portAddress); } #endif } if ((*ppResponse)->client_socket == NULL) { int Err = NetSocket::LastError(); Log(logERROR, "Could not create socket: NetSocket failed with error: %ld\n", Err); return false; } // see if this should be added as a streaming response gtASCIIString strUrl(pRequest->GetUrl()); int32 iStream = strUrl.find(STR_STREAM_TOKEN); if (iStream >= 0) { const char* pBuf = strUrl.asCharArray(); const char* pRate = &pBuf[ iStream + strlen(STR_STREAM_TOKEN)]; unsigned int uRate = 0; // try to get the rate from the command; if (sscanf_s(pRate, "%u", &uRate) < 1) { // default to max rate uRate = COMM_MAX_STREAM_RATE; } // set the response as streaming with the specified rate (*ppResponse)->m_bStreamingEnabled = true; (*ppResponse)->m_dwMaxStreamsPerSecond = uRate; g_streamingResponseMap[ requestID ] = *ppResponse; } else { // streaming requests need to be kept around so that // additional responses can be directed to the right place, // HOWEVER, non-streaming requests only get a single response // and we just created the response for it, so it is safe // to remove the request from the requestMap. This will // help keep communication quick as the number of incoming // requests grows. RemoveRequest(requestID); } return true; }
void local_init(void) { protected_ports[0]=portAddress("pind"); protected_ports[1]=portAddress("portd"); protected_ports[2]=portAddress("ddrd"); }