示例#1
0
void TWebPgToFileFetch::OnError(const int&, const TStr& MsgStr){
  // save error-message as http-body
  if (!OutHttpBodyFNm.Empty()){
    TFOut SOut(OutHttpBodyFNm); TFileId SOutFId=SOut.GetFileId();
    fprintf(SOutFId, "Error: %s\n", MsgStr.CStr());
  }
  // save error-message as http
  if (!OutHttpFNm.Empty()){
    TFOut SOut(OutHttpFNm); TFileId SOutFId=SOut.GetFileId();
    fprintf(SOutFId, "Error: %s\n", MsgStr.CStr());
  }
  // save error-message as xml
  if (!OutXmlFNm.Empty()){
    // create output file
    TFOut SOut(OutXmlFNm); TFileId SOutFId=SOut.GetFileId();
    // open top tag
    fprintf(SOutFId, "<WebPage>\n");
    // save error message
    TStr XmlMsgStr=TXmlLx::GetXmlStrFromPlainStr(MsgStr);
    fprintf(SOutFId, "  <Message>%s</Message>\n", XmlMsgStr.CStr());
    // close top tag
    fprintf(SOutFId, "</WebPage>\n");
  }
  // output to screen
  if (OutScrP){
    printf("%s\n", MsgStr.CStr());
  }
}
示例#2
0
void SamplingToSRAM(unsigned char blocks)
{
	unsigned char rec_chr,i;

	rec_chr=0;
	dac_index=0;
	if (DAC0_mode)
	{
		SFRPAGE   = DAC0_PAGE;
		DAC0CN    = 0x9C;		// left justified, update on Timer2 overflow
	}
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x00;
	ADC_Init(1);
	SFRPAGE   = ADC0_PAGE;
	AD0INT=0;
	SFRPAGE   = ADC1_PAGE;
	AD1INT=0;
	fifo_wp=fifo_rp=0;
	samples_to_save=fifo_size;
	fifo_blocks=0;
	fifo_max_blocks=blocks;
	fifo_mode=0;
	dac_index=0;
	LED=0;

    SFRPAGE   = TMR4_PAGE;
    TMR4CN    = 0x04;
    TMR4CF    = 0x08;

	SFRPAGE=CONFIG_PAGE;
	P4_5=0;	// enable SRAM
	EA=1;
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x04;
	while (EA); // wait for end of sampling

	do
	{
		rec_chr=SIn();
		for(i=0; i<fifo_size; i++)
		{
			SOut(fifo[fifo_rp++]);
			SOut(fifo[fifo_rp++]);
		}
	} while ( (rec_chr!=27) && (fifo_rp<fifo_wp) );

	SFRPAGE=CONFIG_PAGE;
	P4_5=1;	// disable SRAM
	EA=0;
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x00;
	LED=1;
	SFRPAGE   = DAC0_PAGE;
	DAC0CN    = 0x84;
}
示例#3
0
void ContSampling(void)
{
	unsigned char rec_chr,i;

//	Delay_ms(500);

	rec_chr=0;
	dac_index=0;
	if (DAC0_mode)
	{
		SFRPAGE   = DAC0_PAGE;
		DAC0CN    = 0x9C;		// left justified, update on Timer2 overflow
	}
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x00;
	ADC_Init(1);
	SFRPAGE   = ADC0_PAGE;
	AD0INT=0;
	SFRPAGE   = ADC1_PAGE;
	AD1INT=0;
	fifo_wp=fifo_rp=0;
	samples_to_save=fifo_size;
	fifo_blocks=0;
	fifo_max_blocks=0;
	fifo_mode=1;
	EvenOddSample=0;
	SetPGA0(ADC0ConfigEven);
	SetPGA1(ADC1ConfigEven);

	SFRPAGE=CONFIG_PAGE;
	P4_5=0;	// enable SRAM
	LED=0;
	EA=1;
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x04;
	do
	{
		while (!fifo_blocks);
		for(i=0; i<fifo_size; i++)
		{
			SOut(fifo[fifo_rp++]);
			SOut(fifo[fifo_rp++]);
		}
		fifo_blocks--;
	} while (SIn0()!=27);
	SFRPAGE=CONFIG_PAGE;
	P4_5=1;	// disable SRAM
	EA=0;
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x00;
	SFRPAGE   = DAC0_PAGE;
	DAC0CN    = 0x84;
	LED=1;
}
示例#4
0
int main(int argc, char* argv[]){
  Try;
  TStr HtmlFPath="F:/Data/print";
  PCiaWFBBs CiaWFBBs=TCiaWFBBs::LoadBin("../CiaWFBToBow/CiaWFB.Bin");

  {TFOut SOut("CiaWFB.Tab"); FILE* fOut=SOut.GetFileId();
  for (int CountryN=0; CountryN<CiaWFBBs->GetCountries(); CountryN++){
    PCiaWFBCountry CiaWFBCountry=CiaWFBBs->GetCountry(CountryN);
    TStr CountryNm=CiaWFBCountry->GetCountryNm();
    printf("Country: %s\n", CountryNm.CStr());
    for (int FldN=0; FldN<CiaWFBCountry->GetFlds(); FldN++){
      TStr FldNm; TStr FldVal;
      CiaWFBCountry->GetFldNmVal(FldN, FldNm, FldVal);
      TStr SecFldNm=CiaWFBCountry->GetSecNm(FldNm);
      //printf("%d. '%s' - '%s': '%s'\n",
      // FldN, SecFldNm.CStr(), FldNm.CStr(), FldVal.CStr());
      fprintf(fOut, "%s\t%s\t%s\t%s\n",
       CountryNm.CStr(), SecFldNm.CStr(), FldNm.CStr(), FldVal.CStr());
    }
    //printf("\n");
  }}


  PCiaWFBCountry CiaWFBCountry=CiaWFBBs->GetCountry("Slovenia");
  CiaWFBCountry->GetFldValNum("Population");
  CiaWFBCountry->GetFldValNum("GDP - per capita");

  return 0;
  Catch;
  return 1;
}
示例#5
0
文件: bowfl.cpp 项目: Accio/snap
void TBowFl::SaveLnDocTxt(const PBowDocBs& BowDocBs, const TStr& FNm, const bool& UseDocStrP){
  TFOut SOut(FNm);
  int Docs=BowDocBs->GetDocs();
  for (int DId=0; DId<Docs; DId++){
    printf("%d/%d\r", DId+1, Docs);
    // output document-name
    TStr DocNm=TStr::GetFNmStr(BowDocBs->GetDocNm(DId));
    SOut.PutStr(DocNm);
    // output categories
    for (int CIdN=0; CIdN<BowDocBs->GetDocCIds(DId); CIdN++){
      int CId=BowDocBs->GetDocCId(DId, CIdN);
      TStr CatNm=TStr::GetFNmStr(BowDocBs->GetCatNm(CId));
      SOut.PutCh(' '); SOut.PutCh('!'); SOut.PutStr(CatNm);
    }
    // output words
    if (UseDocStrP){
      TStr DocStr=BowDocBs->GetDocStr(DId);
//      DocStr.DelChAll('\n'); DocStr.DelChAll('\r');
      SOut.PutCh(' '); SOut.PutStr(DocStr);
    } else {
        int DocWIds=BowDocBs->GetDocWIds(DId);
        int WId; double WordFq;
        for (int DocWIdN=0; DocWIdN<DocWIds; DocWIdN++){
          BowDocBs->GetDocWIdFq(DId, DocWIdN, WId, WordFq);
          TStr WordStr=BowDocBs->GetWordStr(WId);
          for (int WordFqN=0; WordFqN<WordFq; WordFqN++){
            SOut.PutCh(' '); SOut.PutStr(WordStr);
          }
        }
    }
    SOut.PutLn();
  }
  printf("\n");
}
示例#6
0
文件: skygrid.cpp 项目: Accio/snap
/////////////////////////////////////////////////
// SkyGrid-Document
void TSkyGridBinDoc::SaveBinDocV(
 const TStr& InXmlFPath, const TStr& OutBinFNm, const int& MxDocs){
  printf("Processing SkyGrid-News-Xml files from '%s'...\n", InXmlFPath.CStr());
  TFOut SOut(OutBinFNm);
  TFFile FFile(InXmlFPath, true); TStr FNm;
  int Docs=0; int DateDocs=0; uint64 PrevTm=0;
  while (FFile.Next(FNm)){
    if ((MxDocs!=-1)&&(Docs>=MxDocs)){break;}
    //printf("  Processing '%s' ...", FNm.CStr());
    PXmlDoc XmlDoc=TXmlDoc::LoadTxt(FNm);
    PXmlTok ContentTok=XmlDoc->GetTagTok("item|content");
    TStr SwIdStr=ContentTok->GetTagTok("swid")->GetArgVal("value");
    TStr UrlStr=ContentTok->GetTagTok("url")->GetTokStr(false);
    TStr TitleStr=ContentTok->GetTagTok("title")->GetTokStr(false);
    TStr FetchedValStr=ContentTok->GetTagTok("fetched")->GetArgVal("value");
    TXmlTokV EntityTokV; ContentTok->GetTagTokV("annotations|entity", EntityTokV);
    TStr BodyStr=ContentTok->GetTagTok("body")->GetTokStr(false);
    // extract date
    TStr DateStr=SwIdStr.GetSubStr(0, 7);
    TStr YearStr=DateStr.GetSubStr(0, 3);
    TStr MonthStr=DateStr.GetSubStr(4, 5);
    TStr DayStr=DateStr.GetSubStr(6, 7);
    TTm DateTm(YearStr.GetInt(), MonthStr.GetInt(), DayStr.GetInt());
    uint64 Tm=TTm::GetMSecsFromTm(DateTm);
    // extract entities
    TStrIntH EntNmToFqH;
    for (int EntityTokN=0; EntityTokN<EntityTokV.Len(); EntityTokN++){
      PXmlTok EntityTok=EntityTokV[EntityTokN];
      if (!EntityTok->IsTag("entity")){continue;}
      TStr CanonicalNm=EntityTok->GetArgVal("canonical", "");
      TStr TextStr=EntityTok->GetArgVal("text", "");
      TStr TypeNm=EntityTok->GetArgVal("type", "");
      TStr EntNm=CanonicalNm.Empty() ? TextStr : CanonicalNm;
      EntNmToFqH.AddDat(EntNm)++;
    }
    TIntStrPrV FqEntNmPrV; EntNmToFqH.GetDatKeyPrV(FqEntNmPrV); FqEntNmPrV.Sort(false);
    // extract headline
    TChA HeadlineChA=BodyStr.GetSubStr(0, 250);
    while ((HeadlineChA.Len()>0)&&(HeadlineChA.LastCh()!=' ')){
      HeadlineChA.Trunc(HeadlineChA.Len()-1);}
    HeadlineChA+="...";
    // create document
    TSkyGridBinDoc Doc(SwIdStr, Tm, TitleStr, HeadlineChA, FqEntNmPrV);
    // save document
    Doc.Save(SOut);
    // screen log
    if (PrevTm!=Tm){
      if (PrevTm!=0){printf("\n");}
      PrevTm=Tm; DateDocs=0;
    }
    Docs++; DateDocs++;
    printf("  %s [Day:%d / All:%d]\r", DateStr.CStr(), DateDocs, Docs);
  }
  printf("\nDone.\n");
}
示例#7
0
void SendID()
{
	unsigned char *s;

	s="MA-DAQ (c) 11/11/2011 www.inf.u-szeged.hu/noise";
	do
	{
		if (SIn()==27) break;
		SOut(*s);
		if (*s) s++;
	} while (*s);
}
示例#8
0
文件: bowflx.cpp 项目: Accio/snap
void TBowFl::SaveSparseMatlabTxt(const PBowDocBs& BowDocBs,
    const PBowDocWgtBs& BowDocWgtBs, const TStr& FNm,
    const TStr& CatFNm, const TIntV& _DIdV) {

  TIntV DIdV;
  if (_DIdV.Empty()) {
      BowDocBs->GetAllDIdV(DIdV);
  } else {
      DIdV = _DIdV;
  }
  // generate map of row-ids to words
  TFOut WdMapSOut(TStr::PutFExt(FNm, ".row-to-word-map.dat"));
  for (int WId = 0; WId < BowDocWgtBs->GetWords(); WId++) {
    TStr WdStr = BowDocBs->GetWordStr(WId);
    WdMapSOut.PutStrLn(TStr::Fmt("%d %s", WId+1,  WdStr.CStr()));
  }
  WdMapSOut.Flush();
  // generate map of col-ids to document names
  TFOut DocMapSOut(TStr::PutFExt(FNm, ".col-to-docName-map.dat"));
  for (int DocN = 0; DocN < DIdV.Len(); DocN++) {
    const int DId = DIdV[DocN];
    TStr DocNm = BowDocBs->GetDocNm(DId);
    DocMapSOut.PutStrLn(TStr::Fmt("%d %d %s", DocN, DId,  DocNm.CStr()));
  }
  DocMapSOut.Flush();
  // save documents' sparse vectors
  TFOut SOut(FNm);
  for (int DocN = 0; DocN < DIdV.Len(); DocN++){
    const int DId = DIdV[DocN];
    PBowSpV DocSpV = BowDocWgtBs->GetSpV(DId);
    const int DocWIds = DocSpV->GetWIds();
    for (int DocWIdN=0; DocWIdN<DocWIds; DocWIdN++){
      const int WId = DocSpV->GetWId(DocWIdN);
      const double WordWgt = DocSpV->GetWgt(DocWIdN);
      SOut.PutStrLn(TStr::Fmt("%d %d %.16f", WId+1, DocN+1, WordWgt));
    }
  }
  SOut.Flush();
  // save documents' category sparse vectors
  if (!CatFNm.Empty()) {
    TFOut CatSOut(CatFNm);
    for (int DocN = 0; DocN < DIdV.Len(); DocN++){
      const int DId = DIdV[DocN];
      const int DocCIds = BowDocBs->GetDocCIds(DId);
      for (int DocCIdN=0; DocCIdN<DocCIds; DocCIdN++){
        const int CId = BowDocBs->GetDocCId(DId, DocCIdN);
        const double CatWgt = 1.0;
        CatSOut.PutStrLn(TStr::Fmt("%d %d %.16f", CId+1, DocN+1, CatWgt));
      }
    }
    CatSOut.Flush();
  }
}
示例#9
0
void SendID()
{
	unsigned char *s;

	s="EduDAQ (c) 02/05/2009 www.noise.physx.u-szeged.hu";
	do
	{
		if (SIn()==27) break;
		SOut(*s);
		if (*s) s++;
	} while (*s);
}
void TNmObjBs::SaveTxtNmObj(const TStr& FqFNm, const TStr& SwFNm,
 const TStr& AbcFNm, const TStr& DocFNm) const {
  // get sorted frequency/named-object vector
  TIntStrVPrV FqWordStrVPrV(NmObjWordStrVToDocIdVH.Len(), 0);
  TStrVIntPrV WordStrVFqPrV(NmObjWordStrVToDocIdVH.Len(), 0);
  for (int NmObjId=0; NmObjId<NmObjWordStrVToDocIdVH.Len(); NmObjId++){
    int Fq=NmObjWordStrVToDocIdVH[NmObjId].Len();
    const TStrV& WordStrV=NmObjWordStrVToDocIdVH.GetKey(NmObjId);
    FqWordStrVPrV.Add(TIntStrVPr(Fq, WordStrV));
    WordStrVFqPrV.Add(TStrVIntPr(WordStrV, Fq));
  }
  FqWordStrVPrV.Sort(false);
  WordStrVFqPrV.Sort();
  // save by frequency
  if (!FqFNm.Empty()){
    printf("Saving by frequency to '%s' ...", FqFNm.CStr());
    TFOut SOut(FqFNm); FILE* fOut=SOut.GetFileId();
    for (int PrN=0; PrN<FqWordStrVPrV.Len(); PrN++){
      int Fq=FqWordStrVPrV[PrN].Val1;
      TStrV& WordStrV=FqWordStrVPrV[PrN].Val2;
      TStr WordStrVStr=GetWordStrVStr(WordStrV);
      fprintf(fOut, "%d - %s\n", Fq, WordStrVStr.CStr());
    }
    printf(" Done.\n");
  }
  // save for stopword
  if (!SwFNm.Empty()){
    printf("Saving by frequency for stop-words proposal to '%s' ...", SwFNm.CStr());
    TFOut SOut(SwFNm); FILE* fOut=SOut.GetFileId();
    for (int PrN=0; PrN<FqWordStrVPrV.Len(); PrN++){
      TStrV& WordStrV=FqWordStrVPrV[PrN].Val2;
      TStr WordStrVStr=GetWordStrVStr(WordStrV, ' ');
      fprintf(fOut, "%s\n", WordStrVStr.CStr());
    }
    printf(" Done.\n");
  }
  // save by alphabet
  if (!AbcFNm.Empty()){
    printf("Saving by alphabet to '%s' ...", AbcFNm.CStr());
    TFOut SOut(AbcFNm); FILE* fOut=SOut.GetFileId();
    for (int PrN=0; PrN<WordStrVFqPrV.Len(); PrN++){
      TStrV& WordStrV=WordStrVFqPrV[PrN].Val1;
      int Fq=WordStrVFqPrV[PrN].Val2;
      TStr WordStrVStr=GetWordStrVStr(WordStrV);
      fprintf(fOut, "%s - %d [", WordStrVStr.CStr(), Fq);
      int NmObjId=GetNmObjId(WordStrV);
      TIntV DocIdV;
      GetNmObjDocIdV(NmObjId, DocIdV);
      for (int DocIdN=0; DocIdN<DocIdV.Len(); DocIdN++){
        TStr DocNm=GetDocNm(DocIdV[DocIdN]);
        fprintf(fOut, "'%s' ", DocNm.CStr());
      }
      fprintf(fOut, "]\n");
    }
    printf(" Done.\n");
  }
  // save by documents
  if (!DocFNm.Empty()){
    printf("Saving by documents to '%s' ...", DocFNm.CStr());
    TFOut SOut(DocFNm); FILE* fOut=SOut.GetFileId();
    for (int DocId=0; DocId<GetDocs(); DocId++){
      TStr DocNm=GetDocNm(DocId);
      fprintf(fOut, "'%s'(%d):", DocNm.CStr(), DocId);
      TStr DateStr=GetDocDateStr(DocId);
      if (!DateStr.Empty()){
        fprintf(fOut, "[%s]", DateStr.CStr());}
      int DocNmObjs=GetDocNmObjs(DocId);
      for (int DocNmObjN=0; DocNmObjN<DocNmObjs; DocNmObjN++){
        int NmObjId; int TermFq; GetDocNmObjId(DocId, DocNmObjN, NmObjId, TermFq);
        TStr NmObjStr=GetNmObjStr(NmObjId);
        fprintf(fOut, " [%s:%d]", NmObjStr.CStr(), TermFq);
      }
      fprintf(fOut, "\n");
    }
    printf(" Done.\n");
  }
}
示例#11
0
void main()
{
	unsigned char c;

	Init_Device();

	CheckSRAMs();

	LED=0;
	adc_select=3;
	ADC0ConfigEven=ADC0ConfigOdd=0;		// adc0 gain and channel selection for every even sample and every odd sample
	ADC1ConfigEven=ADC1ConfigOdd=0;
	DAC0_mode=0;
	handshake=1;
	dac_increment=1;
	dac_amplitude=255;
	dac_offset=0;
	fifo_size=128;	// default number of samples in a block

	RTS=0;

	while (1)
	{
		while (SInOut()!='@');
		c=SInOut();
		if (c=='I')
		{
			SendID();
		}
		else if (c=='x')	// switch reference voltage and resistors
		{
			c=SInOut();
			SW0 = !(c&1);	// 1: 10k resistor connected to input, 0: input floating
			SW1 = !(c&2);
			SW2 = !(c&4);
			SW3 = !(c&8);
			PULL = !(c&16);	// 1: pull up to Vref, 0: pull down to GND
		}
		else if (c=='t')	// set trigger polarity
		{
			c=SInOut();
			TRIGINV = c&1;
		}
		else if (c=='b')	// set fifo block size (number of samples in a block
		{
			fifo_size=SInOut();
		}
		else if (c=='c')	// configure continuous sampling mode
		{
			ADC0ConfigEven=SInOut();
			ADC1ConfigEven=SInOut();
			ADC0ConfigOdd=SInOut();
			ADC1ConfigOdd=SInOut();
		}
		else if (c=='S') // start sampling, ESC exits
		{
			ContSampling();
		}
		else if (c=='s') // start sampling, ESC exits
		{
			unsigned long n;

			n = SInOut();
			n = (n << 8)+SInOut();
			n = (n << 8)+SInOut();
			SetSamplingFreq(n);
			n = SInOut();
			n = (n << 8)+SInOut();
			HiSpeedSampling(n);
//			SamplingToSRAM(SInOut());
		}
		else if (c=='A') // select ADCs
		{
			adc_select = SInOut() & 3;
		}
		else if (c=='1') // set range, current, channel
		{
			c=SInOut();
			SetPGA0(c);
		}
		else if (c=='2') // set range, current, channel
		{
			c=SInOut();
			SetPGA1(c);
		}
		else if (c=='M') // measure channels
		{
			c=SInOut();
			if (c<1) c=1;
			Convert(c); // make a single conversion and send data to PC
			SOut(adc1data >> 8);	// channel 0 or 1
			SOut(adc1data);
			SOut(adc0data >> 8);	// channel 2 or 3
			SOut(adc0data);
		}
		else if (c=='f') // set freq
示例#12
0
void putchar(char c)
{
	SOut(c);
}
示例#13
0
void HiSpeedSampling(unsigned int samples) 	// uses DMA
{
	unsigned char rec_chr;
	unsigned int i;

	LED=0;

	rec_chr=0;
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x00;

    SFRPAGE   = ADC0_PAGE;
    ADC0CF    = 0x10;
	ADC0CN = 0x4C;	// timer2
	AD0INT=0;
    SFRPAGE   = ADC1_PAGE;
    ADC1CF    = 0x10;
	ADC1CN = 0x4C;	// timer2
	AD1INT=0;


	SFRPAGE=CONFIG_PAGE;
	P4_5=0;	// enable SRAM

	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x04;

	SFRPAGE = DMA0_PAGE;        // Switch to DMA0 Page
	DMA0CN = 0x00;    		  	// Disable DMA interface
	DMA0DAL = 0;            	// Starting Point for XRAM addressing
	DMA0DAH = 0;            	// Starting Point for XRAM addressing
	DMA0CTL = samples;          // Get NUM_SAMPLES samples
	DMA0CTH = samples>>8;       // Get NUM_SAMPLES samples
	DMA0IPT = 0x00;             // Start writing at location 0
	// Push instructions onto stack in order they will be executed
	DMA0IDT = adc_select<<4; 	// DMA0_GET_ADC0;            // DMA to move ADC0 data.
	DMA0IDT = DMA0_END_OF_OP;

	DMA0BND = 0x00;             // Begin instruction executions at address 0
	DMA0CN = 0xA0;              // Mode 1 Operations, Begin Executing DMA Ops
                                // (which will start ADC0)
	SFRPAGE = DMA0_PAGE;      	// Switch to DMA0 Page
	while ((!(DMA0CN & 0x40)) && (SIn0()!=27));  // Wait for DMA to obtain and move ADC samples
	LED=1;
	i=0;
	do
	{
		if (adc_select==3)
		{
			SOut(XRAM(4*i));
			SOut(XRAM(4*i+1));
			SOut(XRAM(4*i+2));
			SOut(XRAM(4*i+3));
		}
		else
		{
			SOut(XRAM(2*i));
			SOut(XRAM(2*i+1));
		}
		i++;
	} while (i<samples);

	SFRPAGE=CONFIG_PAGE;
	P4_5=1;	// disable SRAM
	EA=0;
	SFRPAGE   = TMR2_PAGE;
	TMR2CN    = 0x00;
	LED=1;
}
示例#14
0
/// Save main file
void TPgBlob::SaveMain() {
    TFOut SOut(FNm + ".main");
    TInt children_cnt(Files.Len());
    children_cnt.Save(SOut);
    Fsm.Save(SOut);
}
示例#15
0
void main()
{
	unsigned char c;

	Init_Device();

	CheckSRAMs();

	adc_select=3;
	ADCConfigEven=ADCConfigOdd=0;		// adc0 gain and channel selection for every even sample and every odd sample
	DAC0_mode=0;
	handshake=1;
	dac_increment=1;
	dac_amplitude=255;
	dac_offset=0;
	fifo_size=128;	// default number of samples in a block

//fifo_size=4;	// default number of samples in a block
//SetSamplingFreq(100);

	for(c=0; c<3; c++)	// flash the power LED three times to indicate booting
	{
		LED=0;	Delay_ms(200);
		LED=1;	Delay_ms(200);
	}
	LED=0;


	RTS=0;




	while (1)
	{
		while (SInOut()!='@');
		c=SInOut();
		if (c=='I')
		{
			SendID();
		}
		else if (c=='x')	// switch reference voltage and resistors
		{
		}
		else if (c=='t')	// set trigger polarity
		{
		}
		else if (c=='b')	// set fifo block size (number of samples in a block
		{
			fifo_size=SInOut();
		}
		else if (c=='c')	// configure continuous sampling mode
		{
			c=SInOut();
			ADCConfigEven = ((c & 1) << 4) | ((c & 2) << 2);
			c=SInOut();
			ADCConfigEven =  ((c & 1) << 5) | ((c & 2) << 5);
			c=SInOut();
			ADCConfigOdd = ((c & 1) << 4) | ((c & 2) << 2);
			c=SInOut();
			ADCConfigOdd =  ((c & 1) << 5) | ((c & 2) << 5);
		}
		else if (c=='S') // start sampling, ESC exits
		{
			ContSampling();
		}
		else if (c=='s') // start sampling, ESC exits
		{
			unsigned long n;

			n = SInOut();
			n = (n << 8)+SInOut();
			n = (n << 8)+SInOut();
			SetSamplingFreq(n);
			n = SInOut();
			n = (n << 8)+SInOut();
			HiSpeedSampling(n);
		}
		else if (c=='A') // select ADCs
		{
			adc_select = SInOut() & 3;
		}
		else if (c=='1') // set channel
		{
			c=SInOut();
			MUX1A0 = c & 1;
			MUX1A1 = c & 2;
		}
		else if (c=='2') // setchannel
		{
			c=SInOut();
			MUX2A0 = c & 1;
			MUX2A1 = c & 2;
		}
		else if (c=='M') // measure channels
		{
			c=SInOut();
			if (c<1) c=1;
			Convert(c); // make a single conversion and send data to PC
			SOut(adc1data >> 8);	// channel 0 or 1
			SOut(adc1data);
			SOut(adc0data >> 8);	// channel 2 or 3
			SOut(adc0data);
		}
		else if (c=='f') // set freq
示例#16
0
文件: exp.cpp 项目: Accio/snap
TStr TExpVal::GetStr() const {
  PSOut SOut=TMOut::New(); TMOut& MOut=*(TMOut*)SOut();
  SaveTxt(SOut);
  TStr ExpValStr=TStr::LoadTxt(MOut.GetSIn());
  return ExpValStr;
}
示例#17
0
int main(int argc, char* argv[]){
  Try;
  // create environment
  Env=TEnv(argc, argv, TNotify::StdNotify);

  // command line parameters
  Env.PrepArgs("Bag-Of-Words K-Means");
  TStr InBowFNm=Env.GetIfArgPrefixStr("-i:", "", "Input-Bow-File");
  TStr OutPartFNm=Env.GetIfArgPrefixStr("-op:", "KMeans.BowPart", "Output-BowPartition-File");
  TStr OutTxtFNm=Env.GetIfArgPrefixStr("-ot:", "KMeans.Txt", "Output-Txt-File");
  TStr OutXmlFNm=Env.GetIfArgPrefixStr("-ox:", "KMeans.Xml", "Output-Xml-File");
  int Docs=Env.GetIfArgPrefixInt("-docs:", -1, "Documents");
  int Clusts=Env.GetIfArgPrefixInt("-clusts:", 10, "Clusters");
  int RndSeed=Env.GetIfArgPrefixInt("-rseed:", 1, "RNG-Seed");
  int ClustTrials=Env.GetIfArgPrefixInt("-ctrials:", 1, "Clustering-Trials");
  double ConvergEps=Env.GetIfArgPrefixFlt("-ceps:", 10, "Convergence-Epsilon");
  double CutWordWgtSumPrc=Env.GetIfArgPrefixFlt("-cutww:", 0.5, "Cut-Word-Weight-Sum-Percentage");
  int MnWordFq=Env.GetIfArgPrefixInt("-mnwfq:", 5, "Minimal-Word-Frequency");
  bool SaveDocNmP=Env.GetIfArgPrefixBool("-sdnm:", false, "Save-Document-Names");
  if (Env.IsEndOfRun()){return 0;}

  // load data
  if (InBowFNm.Empty()){
    TExcept::Throw("No Input-Bow-File specified!");}
  PBowDocBs BowDocBs=TBowDocBs::LoadBin(InBowFNm);

  // get doc-ids
  TIntV AllDIdV; BowDocBs->GetAllDIdV(AllDIdV);
  if (Docs!=-1){AllDIdV.Trunc(Docs);}

  // get document partition
  PBowSim BowSim=TBowSim::New(bstCos); // similarity object
  TBowWordWgtType WordWgtType=bwwtNrmTFIDF; // define weighting
  TSecTm StartTm=TSecTm::GetCurTm(); // get start-time
  PBowDocPart BowDocPart=TBowClust::GetKMeansPart(
   TNotify::StdNotify, // log output
   BowDocBs, // document data
   BowSim, // similarity function
   TRnd(RndSeed), // random generator
   Clusts, // number of clusters
   ClustTrials, // trials per k-means
   ConvergEps, // convergence epsilon for k-means
   1, // min. documents per cluster
   WordWgtType, // word weighting
   CutWordWgtSumPrc, // cut-word-weights percentage
   MnWordFq, // minimal word frequency
   AllDIdV); // training documents
  TSecTm EndTm=TSecTm::GetCurTm(); // get end-time
  printf("Duration: %d secs\n", TSecTm::GetDSecs(StartTm, EndTm));

  // output partition
  if (!OutPartFNm.Empty()){
    TFOut SOut(OutPartFNm); BowDocPart->Save(SOut);}
  if (!OutTxtFNm.Empty()){
    BowDocPart->SaveTxt(OutTxtFNm, BowDocBs, true, 15, 0.5, SaveDocNmP);}
  if (!OutXmlFNm.Empty()){
    BowDocPart->SaveXml(OutXmlFNm, BowDocBs);}

  return 0;
  Catch;
  return 1;
}
示例#18
0
文件: google.cpp 项目: Accio/snap
void TRSet::SaveRSetsBin(const TStr& FNm, TRSetV& RSetV){
  TFOut SOut(FNm);
  for (int RSetN=0; RSetN<RSetV.Len(); RSetN++){
    RSetV[RSetN]->Save(SOut);
  }
}