コード例 #1
0
void consumeDataFromHost(DataT *ptrToDataFromHost) {
    if (ptrToDataFromHost != NULL) {
        // For now, we simply run the RPN calculator as a demonstration.
        // Example: Processing received input via RPN Calculator.
        int result = RPN_calculator(ptrToDataFromHost->payload);

        chsprintf(myData.payload, "%d", result);
        myData.length = log(result)/log(10) + 1; // Count number of characters of the result.
    }
}
コード例 #2
0
void commandRPNCalculator(BaseSequentialStream *chp, int argc, char *argv[]) {
    (void)argc;
    (void)argv;

    if (argc == 3) {
        char buffer[200];

        chsprintf(buffer, "%s %s %s\0", argv[0], argv[1], argv[2]);
        
        int result = RPN_calculator(buffer);

        chprintf(chp, "RPN result = %d", result);
        chprintf(chp, "\r\n");
    }
}
コード例 #3
0
ファイル: Protocol.c プロジェクト: tomkek/projects
void consumeDataFromHost(DataT *ptrToDataFromHost) {
    if (ptrToDataFromHost != NULL) {
#if USE_RPN_CALCULATOR && !USE_PROTOCOL_EXAMPLE
        // For now, we simply run the RPN calculator as a demonstration.
        // Example: Processing received input via RPN Calculator.
        int result = RPN_calculator(ptrToDataFromHost->payload);

        chsprintf(myData.payload, "%d", result);
        myData.length = log(result)/log(10) + 1; // Count number of characters of the result.
#endif

#if !USE_RPN_CALCULATOR && USE_PROTOCOL_EXAMPLE
        // Use the Google protobuf example here.
        struct ToSTM32F4Board toBoard;
        ToSTM32F4Board_read_delimited_from(ptrToDataFromHost->payload, &toBoard, 0);

        struct FromSTM32F4Board fromBoard;
        fromBoard._sum = toBoard._summand1 + toBoard._summand2;

        myData.length = FromSTM32F4Board_write_delimited_to(&fromBoard, myData.payload, 0);
#endif
    }
}