void write_number(uint8_t num) { uint16_t data = 0; switch (num) { case 0: data = PIN_A2 | PIN_B2 | PIN_C2 | PIN_D2 | PIN_E2 | PIN_F2; break; case 1: data = PIN_B2 | PIN_C2; break; case 2: data = PIN_A2 | PIN_B2 | PIN_G2 | PIN_E2 | PIN_D2; break; case 3: data = PIN_A2 | PIN_B2 | PIN_G2 | PIN_C2 | PIN_D2; break; case 4: data = PIN_F2 | PIN_G2 | PIN_B2 | PIN_C2; break; case 5: data = PIN_A2 | PIN_F2 | PIN_G2 | PIN_C2 | PIN_D2; break; case 6: data = PIN_A2 | PIN_F2 | PIN_G2 | PIN_C2 | PIN_D2 | PIN_E2; break; case 7: data = PIN_A2 | PIN_B2 | PIN_C2; break; case 8: data = PIN_A2 | PIN_B2 | PIN_C2 | PIN_D2 | PIN_E2 | PIN_F2 | PIN_G2; break; case 9: data = PIN_A2 | PIN_B2 | PIN_C2 | PIN_D2 | PIN_F2 | PIN_G2; break; case 10: data = PIN_A2 | PIN_B2 | PIN_C2 | PIN_E2 | PIN_F2 | PIN_G2; break; case 11: data = PIN_C2 | PIN_D2 | PIN_E2 | PIN_F2 | PIN_G2; break; case 12: data = PIN_A2 | PIN_E2 | PIN_F2 | PIN_D2; break; case 13: data = PIN_B2 | PIN_G2 | PIN_C2 | PIN_D2 | PIN_E2; break; case 14: data = PIN_A2 | PIN_D2 | PIN_E2 | PIN_F2 | PIN_G2; break; case 15: data = PIN_A2 | PIN_E2 | PIN_F2 | PIN_G2; break; } write_binary_data(data); }
int Trick::VariableServerThread::write_data() { int ret; unsigned int i ; char buf1[ MAX_MSG_LEN ]; int len ; // do not send anything when there are no variables! if ( vars.size() == 0 or packets_copied == 0 ) { return(0); } /* Acquire sole access to vars[ii]->buffer_in. */ if ( var_data_staged and pthread_mutex_trylock(©_mutex) == 0 ) { unsigned int ii; void * temp_p; // Swap buffer_in and buffer_out for each vars[ii]. for ( ii = 0 ; ii < vars.size() ; ii++ ) { temp_p = vars[ii]->buffer_in; vars[ii]->buffer_in = vars[ii]->buffer_out; vars[ii]->buffer_out = temp_p; } var_data_staged = false; /* Relinquish sole access to vars[ii]->buffer_in. */ pthread_mutex_unlock(©_mutex) ; if (binary_data) { int Index = 0; int PacketNumber = 0; do { ret = write_binary_data( Index, buf1, PacketNumber ); if ( ret >= 0 ) { Index = ret ; } else { return(-1) ; } PacketNumber++; } while( Index < (int)vars.size() ); } else { /* ascii mode */ char val[MAX_MSG_LEN]; sprintf(buf1, "0\t") ; for (i = 0; i < vars.size(); i++) { ret = vs_format_ascii( vars[i] , val); if (ret < 0) { message_publish(MSG_WARNING, "%p Variable Server string buffer[%d] too small for symbol %s, TRUNCATED IT.\n", &connection, MAX_MSG_LEN, vars[i]->ref->reference ); } /* make sure this message will fit in a packet by itself */ if( strlen( val ) + 2 > MAX_MSG_LEN ) { message_publish(MSG_WARNING, "%p Variable Server buffer[%d] too small for symbol %s, TRUNCATED IT.\n", &connection, MAX_MSG_LEN, vars[i]->ref->reference ); val[MAX_MSG_LEN - 1] = '\0'; } len = strlen(buf1) ; /* make sure there is space for the next tab or next newline and null */ if( len + strlen( val ) + 2 > MAX_MSG_LEN ) { if (debug >= 2) { message_publish(MSG_DEBUG, "%p tag=<%s> var_server sending %d ascii bytes:", &connection, connection.client_tag, (int)strlen(buf1)) ; message_publish(MSG_NORMAL, "%s\n", buf1); } ret = tc_write(&connection, (char *) buf1, len); if ( ret != len ) { return(-1) ; } buf1[0] = '\0'; } strcat(buf1, val); strcat(buf1, "\t"); } len = strlen(buf1) ; if ( len > 0 ) { buf1[ strlen(buf1) - 1 ] = '\n'; if (debug >= 2) { message_publish(MSG_DEBUG, "%p tag=<%s> var_server sending %d ascii bytes:", &connection, connection.client_tag, (int)strlen(buf1)) ; message_publish(MSG_NORMAL, "%s\n", buf1); } ret = tc_write(&connection, (char *) buf1, (int)strlen(buf1)); if ( ret != (int)strlen(buf1) ) { return(-1) ; } } } } return (0); }