/** Write ack/nack to btm link. */ static void btm_send_ack(long lPort, char acktp, int seqnum) { char buf[4]; itostr_rjust(buf, 2, seqnum % 100, '0'); buf[2] = '\0'; xSerialPutChar(lPort, acktp, ( 5 / portTICK_PERIOD_MS )); lSerialPutString(lPort, buf, 2); xSerialPutChar(lPort, '\n', ( 5 / portTICK_PERIOD_MS )); }
/* Described at the top of this file. */ static void prvUSARTEchoTask( void *pvParameters ) { signed char cChar; /* String declared static to ensure it does not end up on the stack, no matter what the optimisation level. */ static const char *pcLongishString = "ABBA was a Swedish pop music group formed in Stockholm in 1972, consisting of Anni-Frid Frida Lyngstad, " "Björn Ulvaeus, Benny Andersson and Agnetha Fältskog. Throughout the band's existence, Fältskog and Ulvaeus " "were a married couple, as were Lyngstad and Andersson - although both couples later divorced. They became one " "of the most commercially successful acts in the history of popular music, and they topped the charts worldwide " "from 1972 to 1983. ABBA gained international popularity employing catchy song hooks, simple lyrics, sound " "effects (reverb, phasing) and a Wall of Sound achieved by overdubbing the female singers' voices in multiple " "harmonies. As their popularity grew, they were sought after to tour Europe, Australia, and North America, drawing " "crowds of ardent fans, notably in Australia. Touring became a contentious issue, being particularly cumbersome for " "Fältskog, but they continued to release studio albums to widespread commercial success. At the height of their " "popularity, however, both relationships began suffering strain that led ultimately to the collapse of first the " "Ulvaeus-Fältskog marriage (in 1979) and then of the Andersson-Lyngstad marriage in 1981. In the late 1970s and early " "1980s these relationship changes began manifesting in the group's music, as they produced more thoughtful, " "introspective lyrics with different compositions."; /* Just to avoid compiler warnings. */ ( void ) pvParameters; /* Initialise COM0, which is USART1 according to the STM32 libraries. */ lCOMPortInit( mainCOM0, mainBAUD_RATE ); /* Try sending out a string all in one go, as a very basic test of the lSerialPutString() function. */ lSerialPutString( mainCOM0, pcLongishString, strlen( pcLongishString ) ); for( ;; ) { /* Block to wait for a character to be received on COM0. */ xSerialGetChar( mainCOM0, &cChar, portMAX_DELAY ); /* Write the received character back to COM0. */ xSerialPutChar( mainCOM0, cChar, 0 ); } }
/* Described at the top of this file. */ void BluetoothModemTask( void *pvParameters ) { char cChar; /* Just to avoid compiler warnings. */ ( void ) pvParameters; /* Initialise COM0, which is USART1 according to the STM32 libraries. */ lCOMPortInit( comBTM, mainBAUD_RATE ); /* Reset BTM */ #if 0 GPIO_ResetBits(BTM_Reset_Port, BTM_Reset_Pin); vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS ); GPIO_SetBits(BTM_Reset_Port, BTM_Reset_Pin); #endif // do { } while (1); // const char *atEscape = "^^^"; const char *atEscapeChar = "^"; const char *atEOL = "\r"; const char *atTest = "AT\r"; // after-reset condition: give the BT module some time to init itself. vTaskDelay( ( TickType_t ) 1000 / portTICK_PERIOD_MS ); do { #if 1 // Before the escape sequence there must be silence for 1s vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); vTaskDelay( ( TickType_t ) 120 / portTICK_PERIOD_MS ); lSerialPutString( comBTM, atEscapeChar, strlen(atEscapeChar) ); // After the escape sequence there must be silence for 1s vTaskDelay( ( TickType_t ) 1200 / portTICK_PERIOD_MS ); #endif LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_100, LED_INTENS_0); // Send end of line lSerialPutString( comBTM, atEOL, strlen(atEOL) ); // wait a little bit vTaskDelay( ( TickType_t ) 100 / portTICK_PERIOD_MS ); // empty input buffer usartDrainInput(comBTM); /* this drains possible 'ERROR 05' status */ // vTaskDelay( ( TickType_t ) 10 / portTICK_PERIOD_MS ); // Send plain AT lSerialPutString( comBTM, atTest, strlen(atTest) ); // vTaskDelay( ( TickType_t ) 20 / portTICK_PERIOD_MS ); // expect "OK\r\n" } while (btmExpectOK()); LEDs_Set(LED0, LED_INTENS_0, LED_INTENS_0, LED_INTENS_100); GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 /*| GPIO_Pin_1*/; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init( GPIOA, &GPIO_InitStruct ); do { } while (1); // disable local echo const char *atDisableEcho = "ATE0\r"; lSerialPutString( comBTM, atDisableEcho, strlen(atDisableEcho) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atSetDeviceName = "AT*agln=\"PIP-Watch\",0\r\n"; lSerialPutString( comBTM, atSetDeviceName, strlen(atSetDeviceName) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atSetPin = "AT*agfp=\"1234\",0\r"; lSerialPutString( comBTM, atSetPin, strlen(atSetPin) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } const char *atToDataMode = "AT*addm\r"; lSerialPutString( comBTM, atToDataMode, strlen(atToDataMode) ); if (btmExpectOK()) { // failed assert_failed(__FILE__, __LINE__); } /* Try sending out a string all in one go, as a very basic test of the lSerialPutString() function. */ // lSerialPutString( comBTM, pcLongishString, strlen( pcLongishString ) ); int k = 0; char *buf = NULL; for( ;; ) { /* Block to wait for a character to be received on COM0. */ xSerialGetChar( comBTM, &cChar, portMAX_DELAY ); /* Write the received character back to COM0. */ xSerialPutChar( comBTM, cChar, 0 ); if (!buf) { buf = pvPortMalloc(sizeof(char) * 32); #if 0 /* start ADC conversion by software */ // ADC_ClearFlag(ADC1, ADC_FLAG_EOC); ADC_ClearFlag(ADC1, ADC_FLAG_STRT); ADC_Cmd(ADC1, ENABLE); #if 0 ADC_SoftwareStartConvCmd(ADC1, ENABLE); /* wait till the conversion starts */ while (ADC_GetSoftwareStartConvStatus(ADC1) != RESET) { } #endif /* wait till the conversion ends */ while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != SET) { } #endif k = 0; // k = itostr(buf, 32, RTC_GetCounter()); // k = itostr(buf, 32, ADC_GetConversionValue(ADC1)); // k = itostr(buf, 32, vbat_measured); // k = itostr(buf, 32, vbat_percent); // ADC_ClearFlag(ADC1, ADC_FLAG_EOC); } buf[k++] = cChar; if (cChar == '\r' || k >= 30) { buf[k] = '\0'; for (int i = 0; i < k-4; ++i) { if (buf[i] == '*') { /* set time: *<hours><minutes> */ int hours = (buf[i+1]-'0')*10 + (buf[i+2]-'0'); int minutes = (buf[i+3]-'0')*10 + (buf[i+4]-'0'); hours %= 24; minutes %= 60; current_rtime.sec = 0; current_rtime.hour = hours; current_rtime.min = minutes; break; } } if (xQueueSend(toDisplayStrQueue, &buf, 0) == pdTRUE) { // ok; will alloc new buffer buf = NULL; } else { // fail; ignore, keep buffer } // motor demo GPIO_SetBits(GPIOB, 1 << 13); vTaskDelay( ( TickType_t ) 300 / portTICK_PERIOD_MS ); GPIO_ResetBits(GPIOB, 1 << 13); k = 0; xSerialPutChar( comBTM, '\n', 0 ); } } }